forked from cypress-io/cypress-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.yml
451 lines (422 loc) · 21 KB
/
circle.yml
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# WARNING: this file is automatically generated by scripts/generate-config.js
# info on building Docker images on Circle
# https://circleci.com/docs/2.0/building-docker-images/
version: 2.1
orbs:
node: circleci/node@5.0.0
commands:
halt-on-branch:
description: Halt current CircleCI job if not on master branch
steps:
- run:
name: Halting job if not on master branch
command: |
if [[ "$CIRCLE_BRANCH" != "master" ]]; then
echo "Not master branch, will skip the rest of commands"
circleci-agent step halt
else
echo "On master branch, can continue"
fi
halt-if-docker-image-exists:
description: Halt current CircleCI job if Docker image exists already
parameters:
imageName:
type: string
description: Docker image name to test
steps:
- run:
name: Check if image << parameters.imageName >> exists or Docker hub does not respond
# using https://github.com/cypress-io/docker-image-not-found
# to check if Docker hub definitely does not have this image
command: |
if npx docker-image-not-found --repo << parameters.imageName >>; then
echo Docker hub says image << parameters.imageName >> does not exist
else
echo Docker hub has image << parameters.imageName >> or not responding
echo We should stop in this case
circleci-agent step halt
fi
test-base-image:
description: Build a test image from base image and test it
parameters:
nodeVersion:
type: string
description: Node version to expect in the base image, starts with "v"
imageName:
type: string
description: Cypress base docker image to test
steps:
- run:
name: test image << parameters.imageName >> against Kitchensink
no_output_timeout: '3m'
working_directory: '~/project/test-project'
command: |
node --version
npm i cypress@latest
echo "Testing using Electron browser"
docker run -it -v $PWD:/e2e -w /e2e << parameters.imageName >> sh -c "./node_modules/.bin/cypress install && ./node_modules/.bin/cypress run"
test-browser-image:
description: Build a test image from browser image and test it
parameters:
imageName:
type: string
description: Cypress browser docker image to test
chromeVersion:
type: string
default: ''
description: Chrome version to expect in the base image, starts with "Google Chrome XX"
firefoxVersion:
type: string
default: ''
description: Firefox version to expect in the base image, starts with "Mozilla Firefox XX"
edgeVersion:
type: string
default: ''
description: Edge version to expect in the base image, starts with "Microsoft Edge"
steps:
- when:
condition: << parameters.chromeVersion >>
steps:
- run:
name: confirm image has Chrome << parameters.chromeVersion >>
# do not run Docker in the interactive mode - adds control characters!
# and use Bash regex string comparison
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Chrome does not support arm64 yet, skipping"
exit 0
fi
version=$(docker run << parameters.imageName >> google-chrome --version)
if [[ "$version" =~ ^"<< parameters.chromeVersion >>" ]]; then
echo "Image has the expected version of Chrome << parameters.chromeVersion >>"
echo "found $version"
else
echo "Problem: image has unexpected Chrome version"
echo "Expected << parameters.chromeVersion >> and got $version"
exit 1
fi
- when:
condition: << parameters.firefoxVersion >>
steps:
- run:
name: confirm the image has Firefox << parameters.firefoxVersion >>
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Firefox does not support arm64 yet, skipping"
exit 0
fi
version=$(docker run << parameters.imageName >> firefox --version)
if [[ "$version" =~ ^"<< parameters.firefoxVersion >>" ]]; then
echo "Image has the expected version of Firefox << parameters.firefoxVersion >>"
echo "found $version"
else
echo "Problem: image has unexpected Firefox version"
echo "Expected << parameters.firefoxVersion >> and got $version"
exit 1
fi
- when:
condition: << parameters.edgeVersion >>
steps:
- run:
name: confirm the image has Edge << parameters.edgeVersion >>
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Edge does not support arm64 yet, skipping"
exit 0
fi
version=$(docker run << parameters.imageName >> edge --version)
if [[ "$version" ]]; then
echo "Image has the a version of Edge << parameters.edgeVersion >>"
echo "found $version"
else
echo "Problem: image has no Edge version"
echo "Expected to have $version"
exit 1
fi
- run:
name: test image << parameters.imageName >> w Kitchensink
no_output_timeout: '3m'
command: |
sed -i.bak "s|InsertBaseImageHere|<< parameters.imageName >>|g" ./test/Dockerfile.test-project
docker build -t cypress/test -f ./test/Dockerfile.test-project .
- run:
name: Test built-in Electron browser
no_output_timeout: '1m'
command: docker run cypress/test ./node_modules/.bin/cypress run
- when:
condition: << parameters.chromeVersion >>
steps:
- run:
name: Test << parameters.chromeVersion >>
no_output_timeout: '1m'
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Chrome does not support arm64 yet, skipping"
exit 0
fi
docker run cypress/test ./node_modules/.bin/cypress run --browser chrome
- when:
condition: << parameters.firefoxVersion >>
steps:
- run:
name: Test << parameters.firefoxVersion >>
no_output_timeout: '1m'
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Firefox does not support arm64 yet, skipping"
exit 0
fi
docker run cypress/test ./node_modules/.bin/cypress run --browser firefox
- when:
condition: << parameters.edgeVersion >>
steps:
- run:
name: Test << parameters.edgeVersion >>
no_output_timeout: '1m'
command: |
if [[ "$(node -p process.arch)" == 'arm64' ]]; then
echo "Edge does not support arm64 yet, skipping"
exit 0
fi
docker run cypress/test ./node_modules/.bin/cypress run --browser edge
test-included-image-versions:
description: Testing pre-installed versions
parameters:
cypressVersion:
type: string
description: Cypress version to test, like "4.0.0"
imageName:
type: string
description: Cypress included docker image to test
steps:
- run:
name: 'Print versions'
command: docker run -it --entrypoint cypress cypress/included:<< parameters.cypressVersion >> version
- run:
name: 'Print info'
command: docker run -it --entrypoint cypress cypress/included:<< parameters.cypressVersion >> info
- run:
name: 'Check Node version'
command: |
export NODE_VERSION=$(docker run --entrypoint node cypress/included:<< parameters.cypressVersion >> --version)
export CYPRESS_NODE_VERSION=$(docker run --entrypoint cypress cypress/included:<< parameters.cypressVersion >> version --component node)
echo "Included Node $NODE_VERSION"
echo "Cypress includes Node $CYPRESS_NODE_VERSION"
# "node --version" returns something like "v12.1.2"
# and "cypres version ..." returns just "12.1.2"
if [ "$NODE_VERSION" = "v$CYPRESS_NODE_VERSION" ]; then
echo "Node versions match"
else
echo "Node version mismatch 🔥"
# TODO make sure there are no extra characters in the versions
# https://github.com/cypress-io/cypress-docker-images/issues/411
# exit 1
fi
test-included-image:
description: Testing Docker image with Cypress pre-installed
parameters:
cypressVersion:
type: string
description: Cypress version to test, like "4.0.0"
imageName:
type: string
description: Cypress included docker image to test
steps:
- run:
name: New test project and testing
no_output_timeout: '3m'
command: |
node --version
cd test-project
echo "Testing using Electron browser"
docker run -it -v $PWD:/e2e -w /e2e cypress/included:<< parameters.cypressVersion >>
jobs:
lint-markdown:
executor:
name: node/default
tag: '12.22'
steps:
- checkout
- node/install-packages:
override-ci-command: yarn install --frozen-lockfile
- run: npm run check:markdown
test:
executor:
name: node/default
tag: '12.22'
steps:
- checkout
- node/install-packages:
override-ci-command: yarn install --frozen-lockfile
- run: yarn test
build-base-image:
machine:
image: ubuntu-2004:202111-02
parameters:
dockerTag:
type: string
description: Image tag to build like "12.14.0"
resourceClass:
type: string
description: Resource class to use for this job
platformArg:
type: string
description: --platform arg for docker build
resource_class: << parameters.resourceClass >>
steps:
- checkout
- halt-if-docker-image-exists:
imageName: cypress/base:<< parameters.dockerTag >>
- run:
name: building Docker image cypress/base:<< parameters.dockerTag >>
command: |
docker build -t cypress/base:<< parameters.dockerTag >> --platform << parameters.platformArg >> .
working_directory: base/<< parameters.dockerTag >>
- test-base-image:
nodeVersion: v<< parameters.dockerTag >>
imageName: cypress/base:<< parameters.dockerTag >>
build-browser-image:
machine:
image: ubuntu-2004:202111-02
parameters:
resourceClass:
type: string
description: Resource class to use for this job
platformArg:
type: string
description: --platform arg for docker build
dockerTag:
type: string
description: Image tag to build like "node12.4.0-chrome76"
chromeVersion:
type: string
default: ''
description: Chrome version to expect in the base image, starts with "Google Chrome XX"
firefoxVersion:
type: string
default: ''
description: Firefox version to expect in the base image, starts with "Mozilla Firefox XX"
edgeVersion:
type: string
default: ''
description: Edge version to expect in the base image, starts with "Microsoft Edge"
resource_class: << parameters.resourceClass >>
steps:
- checkout
- halt-if-docker-image-exists:
imageName: cypress/browsers:<< parameters.dockerTag >>
- run:
name: building Docker image cypress/browsers:<< parameters.dockerTag >>
command: |
docker build -t cypress/browsers:<< parameters.dockerTag >> --platform << parameters.platformArg >> .
working_directory: browsers/<< parameters.dockerTag >>
- test-browser-image:
imageName: cypress/browsers:<< parameters.dockerTag >>
chromeVersion: << parameters.chromeVersion >>
firefoxVersion: << parameters.firefoxVersion >>
edgeVersion: << parameters.edgeVersion >>
build-included-image:
machine:
image: ubuntu-2004:202111-02
parameters:
dockerTag:
type: string
description: Image tag to build, should match Cypress version, like "3.8.1"
resourceClass:
type: string
description: Resource class to use for this job
platformArg:
type: string
description: --platform arg for docker build
resource_class: << parameters.resourceClass >>
steps:
- checkout
- halt-if-docker-image-exists:
imageName: cypress/included:<< parameters.dockerTag >>
- run:
name: building Docker image cypress/included:<< parameters.dockerTag >>
command: |
docker build -t cypress/included:<< parameters.dockerTag >> --platform << parameters.platformArg >> .
working_directory: included/<< parameters.dockerTag >>
- test-included-image-versions:
cypressVersion: << parameters.dockerTag >>
imageName: cypress/included:<< parameters.dockerTag >>
- test-included-image:
cypressVersion: << parameters.dockerTag >>
imageName: cypress/included:<< parameters.dockerTag >>
push-images:
## the multi-arch images have been built and tested by previous jobs, so we're safe to blindly build+push
machine:
image: ubuntu-2004:202111-02
parameters:
dockerName:
type: string
description: Image name to build
dockerTag:
type: string
description: Image tag to build, should match Cypress version, like "3.8.1"
workingDirectory:
type: string
description: Directory with the Dockerfile
steps:
- checkout
- halt-if-docker-image-exists:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- halt-on-branch
- run:
name: build + push multi-arch image
working_directory: << parameters.workingDirectory >>
command: |
## install QEMU, pulled from https://github.com/docker/setup-qemu-action/blob/4620c11b701e878e3f2b7aa142927d0646857fd9/src/main.ts
## avoids https://github.com/docker/buildx/issues/499
## this allows us to build for arm64 from x86_64 in CI, by installing QEMU utils and binfmt data on our Docker host
## if this suddenly breaks, try a newer digest version or the docker/binfmt fork
BINFMT_IMAGE=tonistiigi/binfmt:latest@sha256:85683def11494bc0055d98dd1081e73cb5e70bbc1ae532be3d12cf054e2b11f1
docker pull $BINFMT_IMAGE
docker image inspect $BINFMT_IMAGE
docker run --rm --privileged $BINFMT_IMAGE --install linux/amd64,linux/arm64
## see https://docs.docker.com/desktop/multi-arch/
docker login -u "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_PASS"
docker buildx create --name builder --use
docker buildx inspect --bootstrap
DOCKER_TAG=<< parameters.dockerName >>:<< parameters.dockerTag >>
docker buildx build --build-arg CI_XBUILD=1 --progress plain --platform linux/arm64,linux/amd64 -t $DOCKER_TAG --push .
## now, let's re-build those same images for Amazon ECR
## see https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html
docker login --username AWS --password "$(aws ecr-public get-login-password --region $AWS_ECR_REGION)" $AWS_ECR_PREFIX
## it is inefficient to re-build here - look below for a TODO on how this could be made faster
docker buildx build --build-arg CI_XBUILD=1 --progress plain --platform linux/arm64,linux/amd64 -t $AWS_ECR_PREFIX/$DOCKER_TAG --push .
## TODO: figure out why we can't simply 're-tag' a manifest - the below code gives "authentication required" for some unknown reason
#apt-get install jq -y
### since we can't just re-push a manifest, we have to extract the list of digests from the existing manifest to make a new one
#MANIFESTS=docker manifest inspect $DOCKER_TAG | jq '[.manifests[].digest]|join(" ")'
#echo "MANIFESTS=$MANIFESTS"
#docker manifest create $AWS_ECR_PREFIX/$DOCKER_TAG $MANIFESTS
#docker push $AWS_ECR_PREFIX/$DOCKER_TAG
workflows:
version: 2
lint:
jobs:
- lint-markdown
- test
build-base-images:
jobs:
- build-base-image:
name: "build+test base 16.18.1 arm64"
dockerTag: "16.18.1"
resourceClass: arm.large
platformArg: linux/arm64
- build-base-image:
name: "build+test base 16.18.1 x64"
dockerTag: "16.18.1"
resourceClass: large
platformArg: linux/amd64
- push-images:
name: "push base 16.18.1 images"
dockerName: 'cypress/base'
dockerTag: '16.18.1'
workingDirectory: '~/project/base/16.18.1'
context: test-runner:docker-push
requires:
- "build+test base 16.18.1 arm64"
- "build+test base 16.18.1 x64"