Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
348 lines (295 loc) · 12.8 KB
/
Copy pathDockerfile
File metadata and controls
348 lines (295 loc) · 12.8 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# ============================================================================
# Base image with system dependencies
# ============================================================================
FROM adguard/node-ssh:22.22--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 the cache so tests re-run on every publish; PR CI passes
# no TEST_RUN_ID and may reuse cached layers (deliberate — see ci.yml).
# ============================================================================
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 the cache so the check re-runs on every publish
# (PR CI passes no TEST_RUN_ID and may reuse cached layers — deliberate).
# ============================================================================
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: sign-src-beta
# Symlinks the beta CRX certificate from a BuildKit secret (never copied into
# an image layer). Requires CERTIFICATE_PEM at build time.
# ============================================================================
FROM source AS sign-src-beta
# sha256 of the PEM. BuildKit secret *content* is not in the RUN cache
# key; ARG values are. Echoing CERT_DIGEST here busts the signed layers
# when the certificate rotates (including re-runs of the same RUN_ID),
# and BuildKit cascades the invalidation to every stage FROM this one.
# The file is not read later — it exists only to bind the ARG to this layer.
ARG CERT_DIGEST
RUN --mount=type=secret,id=CERTIFICATE_PEM,mode=0444 \
echo "${CERT_DIGEST}" > /tmp/.cert-digest && \
mkdir -p private/AdguardVPN && \
ln -sf /run/secrets/CERTIFICATE_PEM \
private/AdguardVPN/certificate-beta.pem
# ============================================================================
# Stage: sign-src-release
# Symlinks the release CRX certificate from a BuildKit secret.
# ============================================================================
FROM source AS sign-src-release
# See sign-src-beta: ARG is the cert-rotation cache key.
ARG CERT_DIGEST
RUN --mount=type=secret,id=CERTIFICATE_PEM,mode=0444 \
echo "${CERT_DIGEST}" > /tmp/.cert-digest && \
mkdir -p private/AdguardVPN && \
ln -sf /run/secrets/CERTIFICATE_PEM \
private/AdguardVPN/certificate-release.pem
# ============================================================================
# Stage: beta-build
# Creates beta build with zip files for CI artifacts.
# The CRX certificate comes from a BuildKit secret via sign-src-beta
# (see above), replacing the former Bamboo extensions-private checkout.
# ============================================================================
FROM sign-src-beta AS 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 \
--mount=type=secret,id=CERTIFICATE_PEM,mode=0444 \
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/
FROM scratch AS beta-build-output
COPY --from=beta-build /out/artifacts/ /
# ============================================================================
# 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 && \
./scripts/ci/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/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/artifacts/ /
# ============================================================================
# Stage: firefox-beta-sign
# Signs Firefox beta with go-webext (requires AMO credentials).
# Reuses artifacts from the firefox-beta-build stage (single docker build
# invocation builds both stages; AMO credentials are BuildKit secrets and
# never land in an image layer).
# Uses adguard/extension-builder image which has go-webext pre-installed.
# ============================================================================
FROM adguard/extension-builder:22.22--0.4.1--0 AS firefox-beta-sign
WORKDIR /sign
COPY --from=firefox-beta-build /out/artifacts/firefox.zip /sign/firefox.zip
COPY --from=firefox-beta-build /out/artifacts/update.json /sign/update.json
COPY --from=firefox-beta-build /out/artifacts/source.zip /sign/source.zip
COPY --from=firefox-beta-build /out/artifacts/approval-notes.txt /sign/approval-notes.txt
ARG TEST_RUN_ID
# Bound the AMO sign wait (go-webext polls without a timeout of its own) so
# a stuck AMO cannot occupy the runner until the 180 min job cap kills it.
ARG AMO_SIGN_TIMEOUT_S=900
RUN --mount=type=secret,id=FIREFOX_CLIENT_ID \
--mount=type=secret,id=FIREFOX_CLIENT_SECRET \
echo "${TEST_RUN_ID}" > /tmp/.test-run-id && \
mkdir -p /out/artifacts && \
FIREFOX_CLIENT_ID="$(cat /run/secrets/FIREFOX_CLIENT_ID)" \
FIREFOX_CLIENT_SECRET="$(cat /run/secrets/FIREFOX_CLIENT_SECRET)" \
timeout --kill-after=60 "${AMO_SIGN_TIMEOUT_S}" \
go-webext -v sign firefox -f 'firefox.zip' -s 'source.zip' -o 'firefox.xpi' \
-n "$(cat approval-notes.txt)" && \
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/artifacts/ /
# ============================================================================
# Stage: release-build
# Creates release build with zip files for CI artifacts.
# The CRX certificate comes from a BuildKit secret via sign-src-release
# (see above), replacing the former Bamboo extensions-private checkout.
# ============================================================================
FROM sign-src-release AS release-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 \
--mount=type=secret,id=CERTIFICATE_PEM,mode=0444 \
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 && \
./scripts/ci/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/source.zip /out/artifacts/ && \
mv build/release/approval-notes.txt /out/artifacts/
FROM scratch AS release-build-output
COPY --from=release-build /out/artifacts/ /