-
Notifications
You must be signed in to change notification settings - Fork 152
/
Dockerfile
225 lines (192 loc) · 8.81 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# syntax=docker/dockerfile:1.3
# +------------------+
# | |
# | builder-base |
# | |
# +---------+--------+
# ^
# |
# |
# +---------+--------+
# | |
# | yarn-base +<------------------------------------------------+
# | | |
# +---------+--------+ |
# ^ |
# | |
# | |
# +---------+--------+ +----------+-------+
# | | | |
# | yarn-deps | | yarn-deps-prod |
# | | | |
# +---------+--------+ +----------+-------+
# ^ ^
# | |
# | |
# +---------+--------+ |
# | | |
# | builder-src |<------------------------------+ |
# | | | |
# +---+-----------+--+ | |
# ^ ^ | |
# | | | |
# | | | |
# +---------------+--+ +---+--------------+ |
# | | | | |
# | builder-client | | builder-server | |
# | | | | |
# +---------------+--+ +---+--------------+ |
# ^ ^ ^ |
# | | | |
# | | | |
# +---+-----------+--+ | |
# | |-------------------------------+ |
# | builder +<------------------------------------------+ |
# | | | |
# +--------+---------+ | |
# ^ | |
# | | |
# | | |
# +--------+---------+ +---+-----+--------+
# | | | |
# | electron-runner | | production |
# | | | |
# +------------------+ +------------------+
# ---------------------------------------------------------
# Base build dependencies
# ---------------------------------------------------------
FROM node:18.15.0-alpine3.17 as builder-base
WORKDIR /app
# Install system dependencies
RUN apk --no-cache --quiet add \
bash \
build-base \
curl \
git
# ---------------------------------------------------------
# Yarn base
# ---------------------------------------------------------
FROM builder-base as yarn-base
# Copy files required for installation of application dependencies
COPY package.json yarn.lock ./
COPY patches ./patches
# ---------------------------------------------------------
# Yarn dependencies
# ---------------------------------------------------------
FROM yarn-base as yarn-deps
RUN --mount=type=cache,id=yarndev,target=/usr/local/share/.cache \
--mount=type=cache,id=cypress,sharing=locked,target=/root/.cache/Cypress \
yarn install --frozen-lockfile --quiet
# ---------------------------------------------------------
# Yarn dependencies
# ---------------------------------------------------------
FROM yarn-base as yarn-deps-prod
RUN --mount=type=cache,id=yarnprod,target=/usr/local/share/.cache \
--mount=type=cache,id=cypress,sharing=locked,target=/root/.cache/Cypress \
yarn install --production --frozen-lockfile --quiet
# ---------------------------------------------------------
# Builder with source code
# ---------------------------------------------------------
FROM yarn-deps as builder-src
# Copy application code
COPY __mocks__ ./__mocks__
COPY cypress ./cypress
COPY data ./data
COPY patches ./patches
COPY src ./src
COPY webpack ./webpack
COPY .git ./.git
COPY .env.oss \
.env.test \
.eslintrc.js \
.nvmrc \
.prettierignore \
.swcrc.js \
babel.config.js \
cypress.config.ts \
dangerfile.ts \
jest.config.js \
package.json \
relay.config.js \
relativeci.config.js \
tsconfig.json \
yarn.lock \
./
# ---------------------------------------------------------
# Compile client
# ---------------------------------------------------------
FROM builder-src as builder-client
RUN yarn build:client:prod
# ---------------------------------------------------------
# Compile server
# ---------------------------------------------------------
FROM builder-src as builder-server
# Build application
RUN yarn build:server:prod
# ---------------------------------------------------------
# All development assets
# ---------------------------------------------------------
FROM builder-src as builder
# Scripts
COPY ./scripts ./scripts
# Client assets
COPY --from=builder-client /app/manifest.json .
COPY --from=builder-client /app/public ./public
COPY --from=builder-client /app/src ./src
# Server assets
COPY --from=builder-server /app/server.dist.js .
COPY --from=builder-server /app/server.dist.js.map .
# ---------------------------------------------------------
# Image with xvfb to run Electron with a virtual display
# ---------------------------------------------------------
FROM node:18.15.0-bullseye-slim as electron-runner
WORKDIR /app
# Install electron deps
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app /app
# ---------------------------------------------------------
# Release image
# ---------------------------------------------------------
#
# Release stage. This stage creates the final docker iamge that will be
# released. It contains only production dependencies and artifacts.
#
FROM node:18.15.0-alpine3.17 as production
RUN apk --no-cache --quiet add \
bash \
dumb-init \
&& adduser -D -g '' deploy
WORKDIR /app
RUN chown deploy:deploy $(pwd)
USER deploy
# Production node modules.
COPY --chown=deploy:deploy --from=yarn-deps-prod /app/node_modules ./node_modules
# Base code
COPY --chown=deploy:deploy --from=builder /app/data ./data
COPY --chown=deploy:deploy --from=builder /app/package.json .
COPY --chown=deploy:deploy --from=builder /app/scripts ./scripts
COPY --chown=deploy:deploy --from=builder /app/webpack ./webpack
COPY --chown=deploy:deploy --from=builder /app/yarn.lock .
# Client assets
COPY --chown=deploy:deploy --from=builder /app/manifest.json .
COPY --chown=deploy:deploy --from=builder /app/public ./public
COPY --chown=deploy:deploy --from=builder /app/src ./src
# Server assets
COPY --chown=deploy:deploy --from=builder /app/server.dist.js .
COPY --chown=deploy:deploy --from=builder /app/server.dist.js.map .
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# TODO: Reduce production memory, this is not a concern
CMD ["node", "--max_old_space_size=2048", "--heapsnapshot-signal=SIGUSR2", "--no-experimental-fetch", "./server.dist.js"]