-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDockerfile
More file actions
310 lines (261 loc) · 10.7 KB
/
Dockerfile
File metadata and controls
310 lines (261 loc) · 10.7 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# ============================================================================
# Base image with system dependencies
# ============================================================================
FROM adguard/node-ssh:22.17--0 AS base
SHELL ["/bin/bash", "-lc"]
RUN apt-get update \
&& apt-get install -y zip \
&& rm -rf /var/lib/apt/lists/*
# Prevent "dubious ownership" error in git
RUN git config --global --add safe.directory '*'
WORKDIR /extension
ENV npm_config_store_dir=/pnpm-store
# ============================================================================
# Stage: deps
# Cached until package.json/pnpm-lock.yaml changes
# ============================================================================
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
pnpm install \
--frozen-lockfile \
--prefer-offline \
--ignore-scripts
# ============================================================================
# Stage: source
# Has source + node_modules
# ============================================================================
FROM deps AS source
COPY . /extension
# ============================================================================
# Stage: lint
# Runs ESLint + type checking
# ============================================================================
FROM source AS lint
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
pnpm lint && \
mkdir -p /out && \
touch /out/lint.txt
FROM scratch AS lint-output
COPY --from=lint /out/ /
# ============================================================================
# Stage: unit-tests
# Runs unit tests with JUnit output
# TEST_RUN_ID busts cache so tests always re-run
# ============================================================================
FROM source AS unit-tests
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
mkdir -p /out/tests-reports && \
set +e; \
pnpm test:ci; \
EXIT_CODE=$?; \
if [ -d tests-reports ]; then \
cp -R tests-reports/. /out/tests-reports/; \
fi; \
echo ${EXIT_CODE} > /out/exit-code.txt; \
exit 0
FROM scratch AS unit-tests-output
COPY --from=unit-tests /out/ /
# ============================================================================
# Stage: bundle-size-check
# Builds and checks bundle sizes for a given BUILD_TYPE and optional BROWSER
# ============================================================================
FROM source AS bundle-size-check
ARG BUILD_TYPE
ARG BROWSER=""
ARG STAGE_ENV
ARG VPN_API_URL
ARG ACCOUNTS_API_URL
ARG FORWARDER_DOMAIN
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
export STAGE_ENV="${STAGE_ENV}" && \
export VPN_API_URL="${VPN_API_URL}" && \
export AUTH_API_URL="${ACCOUNTS_API_URL}" && \
export FORWARDER_DOMAIN="${FORWARDER_DOMAIN}" && \
pnpm ${BUILD_TYPE} ${BROWSER} && \
pnpm bundle-size check ${BUILD_TYPE} ${BROWSER} && \
mkdir -p /out && \
touch /out/bundle-size-check.txt
FROM scratch AS bundle-size-check-output
COPY --from=bundle-size-check /out/ /
# ============================================================================
# Stage: locales-check
# Validates translation files
# TEST_RUN_ID busts cache so check always re-runs
# ============================================================================
FROM source AS locales-check
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
pnpm locales validate --min && \
mkdir -p /out && \
touch /out/locales-check.txt
FROM scratch AS locales-check-output
COPY --from=locales-check /out/ /
# ============================================================================
# Stage: dev-build
# Creates dev builds with both test and prod API endpoints
# ============================================================================
FROM source AS dev-build
ARG TEST_RUN_ID
ARG VPN_API_URL_TEST
ARG ACCOUNTS_API_URL_TEST
ARG FORWARDER_DOMAIN_TEST
ARG VPN_API_URL_PROD
ARG ACCOUNTS_API_URL_PROD
ARG FORWARDER_DOMAIN_PROD
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
# Build with test API endpoints.
STAGE_ENV=test \
VPN_API_URL="${VPN_API_URL_TEST}" \
AUTH_API_URL="${ACCOUNTS_API_URL_TEST}" \
FORWARDER_DOMAIN="${FORWARDER_DOMAIN_TEST}" \
pnpm dev && \
# Build CRX with test env.
STAGE_ENV=test pnpm crx:dev && \
# Build with prod API endpoints.
STAGE_ENV=prod \
VPN_API_URL="${VPN_API_URL_PROD}" \
AUTH_API_URL="${ACCOUNTS_API_URL_PROD}" \
FORWARDER_DOMAIN="${FORWARDER_DOMAIN_PROD}" \
pnpm dev && \
# Build CRX with prod env.
STAGE_ENV=prod pnpm crx:dev && \
mkdir -p /out/artifacts && \
# Test env artifacts.
cp build/dev/chrome.zip /out/artifacts/ && \
cp build/dev/edge.zip /out/artifacts/ && \
cp build/dev/opera.zip /out/artifacts/ && \
cp build/dev/firefox.zip /out/artifacts/ && \
cp build/dev/chrome.crx /out/artifacts/ && \
# Prod env artifacts (with -prod suffix).
cp build/dev/chrome-prod.zip /out/artifacts/ && \
cp build/dev/edge-prod.zip /out/artifacts/ && \
cp build/dev/opera-prod.zip /out/artifacts/ && \
cp build/dev/firefox-prod.zip /out/artifacts/ && \
cp build/dev/chrome-prod.crx /out/artifacts/
FROM scratch AS dev-build-output
COPY --from=dev-build /out/ /
# ============================================================================
# Stage: beta-build
# Creates beta build with zip files for CI artifacts
# Requires private repo for CRX certificate (passed via named build context)
# ============================================================================
FROM source AS beta-build
COPY --from=private . /extension/private
ARG STAGE_ENV
ARG VPN_API_URL
ARG ACCOUNTS_API_URL
ARG FORWARDER_DOMAIN
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
export STAGE_ENV="${STAGE_ENV}" && \
export VPN_API_URL="${VPN_API_URL}" && \
export AUTH_API_URL="${ACCOUNTS_API_URL}" && \
export FORWARDER_DOMAIN="${FORWARDER_DOMAIN}" && \
pnpm beta && \
pnpm crx:beta && \
mkdir -p /out/artifacts && \
mv build/beta/chrome.zip /out/artifacts/ && \
mv build/beta/edge.zip /out/artifacts/ && \
mv build/beta/opera.zip /out/artifacts/ && \
mv build/beta/chrome.crx /out/artifacts/ && \
mv build/beta/update.xml /out/artifacts/ && \
mv build/beta/build.txt /out/artifacts/
FROM scratch AS beta-build-output
COPY --from=beta-build /out/ /
# ============================================================================
# Stage: firefox-beta-build
# Creates Firefox beta build with zip files and source archive for AMO
# ============================================================================
FROM source AS firefox-beta-build
ARG STAGE_ENV
ARG VPN_API_URL
ARG ACCOUNTS_API_URL
ARG FORWARDER_DOMAIN
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
export STAGE_ENV="${STAGE_ENV}" && \
export VPN_API_URL="${VPN_API_URL}" && \
export AUTH_API_URL="${ACCOUNTS_API_URL}" && \
export FORWARDER_DOMAIN="${FORWARDER_DOMAIN}" && \
pnpm beta firefox && \
./bamboo-specs/scripts/archive-source.sh beta && \
mkdir -p /out/artifacts && \
mv build/beta/firefox.zip /out/artifacts/ && \
mv build/beta/update.json /out/artifacts/ && \
mv build/beta/build.txt /out/artifacts/ && \
mv build/beta/source.zip /out/artifacts/ && \
mv build/beta/approval-notes.txt /out/artifacts/
FROM scratch AS firefox-beta-build-output
COPY --from=firefox-beta-build /out/ /
# ============================================================================
# Stage: firefox-beta-sign
# Signs Firefox beta with go-webext (requires AMO credentials)
# Expects artifacts via named build context: --build-context firefox-artifacts=...
# Uses adguard/extension-builder image which has go-webext pre-installed
# ============================================================================
FROM adguard/extension-builder:22.17--0.4.1--0 AS firefox-beta-sign
WORKDIR /sign
COPY --from=firefox-artifacts firefox.zip /sign/firefox.zip
COPY --from=firefox-artifacts update.json /sign/update.json
COPY --from=firefox-artifacts source.zip /sign/source.zip
COPY --from=firefox-artifacts build.txt /sign/build.txt
COPY --from=firefox-artifacts approval-notes.txt /sign/approval-notes.txt
ARG FIREFOX_CLIENT_ID
ARG TEST_RUN_ID
RUN --mount=type=secret,id=FIREFOX_CLIENT_SECRET \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
mkdir -p /out/artifacts && \
FIREFOX_CLIENT_ID="${FIREFOX_CLIENT_ID}" \
FIREFOX_CLIENT_SECRET="$(cat /run/secrets/FIREFOX_CLIENT_SECRET)" \
go-webext -v sign firefox -f 'firefox.zip' -s 'source.zip' -o 'firefox.xpi' \
-n "$(cat approval-notes.txt)" && \
cp build.txt /out/artifacts/ && \
cp firefox.zip /out/artifacts/ && \
cp firefox.xpi /out/artifacts/ && \
cp update.json /out/artifacts/ && \
cp source.zip /out/artifacts/
FROM scratch AS firefox-beta-sign-output
COPY --from=firefox-beta-sign /out/ /
# ============================================================================
# Stage: release-build
# Creates release build with zip files for CI artifacts
# Requires private repo for CRX certificate (passed via named build context)
# ============================================================================
FROM source AS release-build
COPY --from=private . /extension/private
ARG STAGE_ENV
ARG VPN_API_URL
ARG ACCOUNTS_API_URL
ARG FORWARDER_DOMAIN
ARG TEST_RUN_ID
RUN --mount=type=cache,target=/pnpm-store,id=vpn-extension-pnpm \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
export STAGE_ENV="${STAGE_ENV}" && \
export VPN_API_URL="${VPN_API_URL}" && \
export AUTH_API_URL="${ACCOUNTS_API_URL}" && \
export FORWARDER_DOMAIN="${FORWARDER_DOMAIN}" && \
pnpm release && \
pnpm crx:release && \
./bamboo-specs/scripts/archive-source.sh release && \
mkdir -p /out/artifacts && \
mv build/release/chrome.zip /out/artifacts/ && \
mv build/release/edge.zip /out/artifacts/ && \
mv build/release/opera.zip /out/artifacts/ && \
mv build/release/firefox.zip /out/artifacts/ && \
mv build/release/chrome.crx /out/artifacts/ && \
mv build/release/build.txt /out/artifacts/ && \
mv build/release/source.zip /out/artifacts/ && \
mv build/release/approval-notes.txt /out/artifacts/
FROM scratch AS release-build-output
COPY --from=release-build /out/ /