forked from HSLdevcom/digitransit-ui
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
111 lines (91 loc) · 3.68 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# syntax = docker/dockerfile:1.4
FROM node:20-alpine as builder
WORKDIR /opt/digitransit-ui
ENV \
# We mimick common CI/CD systems so that tools don't assume a "normal" dev env.
CI=true \
# Picked up by various Node.js tools.
NODE_ENV=production
# install dependencies for npm packages
RUN \
# required for sharp, which builds libvips using node-gyp
apk add --no-cache python3 make g++ vips-dev bash
COPY .yarnrc.yml package.json yarn.lock lerna.json ./
COPY .yarn ./.yarn
# todo: only copy */packages/*/package.json, not all of the code
# AFAIK there is no blob syntax that copies */package.json while keeping paths.
# https://github.com/moby/moby/issues/15858
COPY digitransit-util ./digitransit-util
COPY digitransit-search-util ./digitransit-search-util
COPY digitransit-component ./digitransit-component
COPY digitransit-store ./digitransit-store
RUN \
# Tell Playwright not to download browser binaries, as it is only used for testing (not building).
# https://github.com/microsoft/playwright/blob/v1.16.2/installation-tests/installation-tests.sh#L200-L216
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
&& yarn install --immutable --inline-builds \
&& yarn cache clean --all \
&& rm -rf /tmp/phantomjs
# Setting $CONFIG causes digitransit-ui to only build assets for *one* instance (see app/configurations).
# This speeds up the build (because favicons-webpack-plugin is increasingly *very* slow with the nr of
# configs processed), but the resulting image won't be able to serve other instances.
ARG CONFIG=''
ENV CONFIG=${CONFIG}
COPY config ./config
RUN \
yarn run build-workspaces
COPY . .
RUN \
yarn run build \
&& rm -rf node_modules/.cache \
&& rm -rf /tmp/Relay*
# Deleting files retrospectively, after having copied/generated them in a previous step, *does not* reduce
# the size of the resulting (builder) Docker image. But we prevent them from being copied into the final image.
RUN \
rm -rf static docs .cache
FROM node:20-alpine
LABEL org.opencontainers.image.title="digitransit-ui"
LABEL org.opencontainers.image.description="open nationwide journey planning platform"
LABEL org.opencontainers.image.authors="[email protected]"
LABEL org.opencontainers.image.documentation="https://digitransit.fi"
LABEL org.opencontainers.image.source="https://github.com/HSLdevcom/digitransit-ui/tree/v3"
LABEL org.opencontainers.image.revision="3"
LABEL org.opencontainers.image.licenses="(AGPL-3.0 OR EUPL-1.2)"
WORKDIR /opt/digitransit-ui
ARG CONFIG=''
ENV CONFIG=${CONFIG}
EXPOSE 8080
# todo: install production dependencies only, re-use .yarn/cache from above
# `yarn install --production` is not supported by Yarn v2.4.3, and the suggested `yarn workspaces focus` command
# does not exist.
COPY --from=builder /opt/digitransit-ui/ .
ARG WEBPACK_DEVTOOL=''
ENV \
# App specific settings to override when the image is run \
SENTRY_DSN='' \
SENTRY_SECRET_DSN='' \
PORT=8080 \
API_URL='' \
MAP_URL='' \
OTP_URL='' \
GEOCODING_BASE_URL='' \
APP_PATH='' \
CONFIG=$CONFIG \
NODE_ENV='' \
# setting a non-empty default value for NODE_OPTS
# if you don't do this then yarn/node seem to think that you want to
# execute a file called "" (empty string) and doesn't start the server
# https://github.com/HSLdevcom/digitransit-ui/issues/4155
#
# the --title option just sets the harmless property process.title
# https://nodejs.org/api/cli.html#cli_title_title
NODE_OPTS='--title=digitransit-ui' \
RELAY_FETCH_TIMEOUT='' \
WEBPACK_DEVTOOL=$WEBPACK_DEVTOOL \
ASSET_URL='' \
STATIC_MESSAGE_URL=''
RUN apk add --no-cache curl
HEALTHCHECK \
--interval=5s --timeout=3s --retries=3 --start-period=5s \
CMD curl -fsSLI "http://localhost:$PORT/" || exit 1
CMD yarn run start