forked from artsy/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
243 lines (207 loc) · 9.3 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# syntax=docker/dockerfile:experimental
# +------------------+
# | |
# | builder-base |
# | |
# +---------+--------+
# ^
# |
# |
# +---------+--------+
# | |
# | yarn-base +<------------------------------------------------+
# | | |
# +---------+--------+ |
# ^ |
# | |
# | |
# +---------+--------+ +----------+-------+
# | | | |
# | yarn-deps | | yarn-deps-prod |
# | | | |
# +---------+--------+ +----------+-------+
# ^ ^
# | |
# | |
# +---------+--------+ |
# | | |
# | builder-src |<------------------------------+ |
# | | | |
# +---+-----------+--+ | |
# ^ ^ | |
# | | | |
# | | | |
# +---------------+--+ +---+--------------+ +-------------------------+ |
# | | | | | | |
# | builder-assets | | builder-server | | builder-assets-legacy | |
# | | | | | | |
# +---------------+--+ +---+--------------+ +------------------------ + |
# ^ ^ ^ |
# | | | |
# | | | |
# +---+-----------+--+ | |
# | |-------------------------------+ |
# | builder +<------------------------------------------+ |
# | | | |
# +--------+---------+ | |
# ^ | |
# | | |
# | | |
# +--------+---------+ +---+-----+--------+
# | | | |
# | electron-runner | | production |
# | | | |
# +------------------+ +------------------+
# ---------------------------------------------------------
# Base build dependencies
# ---------------------------------------------------------
FROM node:14.17.5-alpine3.11 as builder-base
WORKDIR /app
# Install system dependencies
RUN apk --no-cache --quiet add \
bash \
build-base \
curl \
git \
python
# ---------------------------------------------------------
# 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,target=/usr/local/share/.cache \
--mount=type=cache,target=/root/.cache/Cypress \
yarn install --frozen-lockfile --quiet
# ---------------------------------------------------------
# Yarn dependencies
# ---------------------------------------------------------
FROM yarn-base as yarn-deps-prod
RUN --mount=type=cache,target=/usr/local/share/.cache \
--mount=type=cache,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 packages ./packages
COPY patches ./patches
COPY src ./src
COPY webpack ./webpack
COPY .env.oss \
.env.test \
.eslintrc.js \
.nvmrc \
.prettierignore \
apollo.config.js \
babel.config.js \
coffeelint.json \
cypress.json \
dangerfile.ts \
jest.config.v1.js \
jest.config.v2.js \
package.json \
relay.config.js \
test.config.js \
test.mocha.js \
tsconfig.json \
yarn.lock \
./
# ---------------------------------------------------------
# Compile legacy assets
# ---------------------------------------------------------
FROM builder-src as builder-assets-legacy
# Build legacy application
RUN yarn build:assets:legacy
# ---------------------------------------------------------
# Compile assets
# ---------------------------------------------------------
FROM builder-src as builder-assets
RUN yarn build:assets
# ---------------------------------------------------------
# Compile server
# ---------------------------------------------------------
FROM builder-src as builder-server
# Build application
RUN yarn build:server
# ---------------------------------------------------------
# All development assets
# ---------------------------------------------------------
FROM builder-src as builder
# Scripts
COPY ./scripts ./scripts
# Client assets
COPY --from=builder-assets-legacy /app/manifest.json .
COPY --from=builder-assets-legacy /app/public ./public
COPY --from=builder-assets-legacy /app/src ./src
# Client (Novo) assets
COPY --from=builder-assets /app/manifest-novo.json .
COPY --from=builder-assets /app/public ./public
# 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:14.17.5-stretch-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:14.17.5-alpine3.11 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/packages ./packages
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/manifest-novo.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=3072", "--heapsnapshot-signal=SIGUSR2", "./server.dist.js"]