-
Notifications
You must be signed in to change notification settings - Fork 380
/
circle.yml
407 lines (392 loc) · 18.9 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
# info on building Docker images on Circle
# https://circleci.com/docs/2.0/building-docker-images/
## If you wish to release an older Docker image, do not modify this file in the master branch.
## Follow the instructions in the CONTRIBUTING document and work instead in a feature branch.
## Modify the push jobs below to be triggered on the feature branch, not the master branch.
version: 2.1
commands:
expand-env-file:
description: Sets up bash env to load envs from the env file
steps:
- run:
name: Sets up bash env to load envs from the env file
command: |
touch $BASH_ENV
echo 'set -a && . ~/project/factory/.env && set +a' >> $BASH_ENV
halt-if-docker-image-exists:
description: Halt current CircleCI job if Docker image exists already
parameters:
target:
type: string
description: cypress/* repo name (factory, base, browser or included)
steps:
- run:
name: Check if image for << parameters.target >> exists on Docker Hub
# using Docker HUB API https://docs.docker.com/docker-hub/api/latest/
# to check if Docker Hub definitely does not have this image
command: |
DOCKER_NAMESPACE='cypress'
DOCKER_REPO=<< parameters.target >>
DOCKER_TAG=''
if [ ${DOCKER_REPO} == factory ]; then DOCKER_TAG=${FACTORY_VERSION}; fi
if [ ${DOCKER_REPO} == base ]; then DOCKER_TAG=${BASE_IMAGE_TAG}; fi
if [ ${DOCKER_REPO} == browsers ]; then DOCKER_TAG=${BROWSERS_IMAGE_TAG}; fi
if [ ${DOCKER_REPO} == included ]; then DOCKER_TAG=${INCLUDED_IMAGE_TAG}; fi
DOCKER_NAME=${DOCKER_NAMESPACE}/${DOCKER_REPO}:${DOCKER_TAG}
if curl -s https://hub.docker.com/v2/namespaces/${DOCKER_NAMESPACE}/repositories/${DOCKER_REPO}/tags/${DOCKER_TAG} \
| grep -iq 'httperror 404'; then
echo Docker Hub says image $DOCKER_NAME does not exist - HTTP status 404 returned
echo $DOCKER_NAME available for publishing
else
echo Docker Hub found image $DOCKER_NAME - or error occurred
echo Stopping to avoid republishing
circleci-agent step halt
fi
jobs:
check-factory-versions:
machine:
image: ubuntu-2204:2024.08.1
steps:
- checkout
- expand-env-file
- run:
name: building docker image
command: |
docker compose --progress plain build factory
working_directory: factory
- run:
name: build test image
command: |
docker compose --progress plain build test-factory-all-included
working_directory: factory/test-project
- run:
name: check node version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included node -v)
if [ v${NODE_VERSION} != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, v${NODE_VERSION} != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check yarn version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included yarn -v)
if [ ${YARN_VERSION} != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, ${YARN_VERSION} != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check chrome version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included google-chrome --version | xargs)
TRIMMED_CHROME_VERSION=$(echo ${CHROME_VERSION} | sed -e 's/-.*$//g')
if [ "Google Chrome ${TRIMMED_CHROME_VERSION}" != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, Google Chrome ${TRIMMED_CHROME_VERSION} != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check firefox version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included firefox --version)
if [ "Mozilla Firefox ${FIREFOX_VERSION}" != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, Mozilla Firefox ${FIREFOX_VERSION} != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check edge version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included edge --version | xargs)
TRIMMED_EDGE_VERSION=$(echo ${EDGE_VERSION} | sed -e 's/-.*$//g')
if [ "Microsoft Edge ${TRIMMED_EDGE_VERSION}" != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, Microsoft Edge ${TRIMMED_EDGE_VERSION} != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check cypress version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included cypress -v)
TRIMMED_ACTUAL_VERSION=$(echo ${ACTUAL_VERSION} | sed -e 's/ Cypress binary version:.*$//g')
if [ "Cypress package version: ${CYPRESS_VERSION}" != "${TRIMMED_ACTUAL_VERSION}" ]; then
echo "Version mismatch, Cypress package version: ${CYPRESS_VERSION} != ${TRIMMED_ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
# The git version is determined by BASE_IMAGE and its online package sources
# We check that git is installed and report its version
# There is no check for a certain version of git
name: check git version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included git --version)
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
- run:
name: check ssh version # We don't really care what version ssh has as long as the command doesn't error
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-all-included ssh -V 2>&1)
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
check-node-override-version:
machine:
image: ubuntu-2204:2024.08.1
steps:
- checkout
- expand-env-file
- run:
name: building docker image
command: |
docker compose --progress plain build factory
working_directory: factory
- run:
name: build test image
command: |
docker compose --progress plain build test-factory-node-override
working_directory: factory/test-project
- run:
name: check node version
command: |
ACTUAL_VERSION=$(docker compose run --rm test-factory-node-override node -v)
if [ v18.17.1 != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, v18.17.1 != ${ACTUAL_VERSION}"
exit 1;
fi
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
test-image:
machine:
image: ubuntu-2204:2024.08.1
parameters:
target:
type: string
description: The docker compose target to build
resourceClass:
type: string
description: Resource class to use for this job
test-target:
type: string
description: The docker compose target to run the test
resource_class: << parameters.resourceClass >>
steps:
- checkout
- expand-env-file
- run:
name: building docker image
command: |
if [ << parameters.target >> != factory ]; then docker compose --progress plain build factory; fi
docker compose --progress plain build << parameters.target >>
working_directory: factory
- run:
name: test
command: |
docker compose --progress plain build << parameters.test-target >>
docker compose run --rm << parameters.test-target >>
working_directory: factory/test-project
push:
machine:
image: ubuntu-2204:2024.08.1
parameters:
target:
type: string
description: Name of the docker compose target to build and push.
steps:
- checkout
- expand-env-file
- halt-if-docker-image-exists:
target: << parameters.target >>
- run:
name: Building Docker image for target << parameters.target >>
no_output_timeout: 20m # installing cypress on arm can take some time.
command: |
echo Build environment is ...
echo Node.js $(node --version)
echo $(docker --version)
echo $(docker buildx version)
## see https://docs.docker.com/desktop/multi-arch/
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64,linux/arm64
docker buildx create --name builder --use
# Disable default provenance attestation for Buildx
# https://docs.docker.com/build/building/variables/#buildx_no_default_attestations
# https://docs.docker.com/build/release-notes/#0100
# Keeps using docker
# "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json"
# instead of moving to oci, which may cause compatibility issues, for example
# "mediaType": "application/vnd.oci.image.index.v1+json"
export BUILDX_NO_DEFAULT_ATTESTATIONS=1
docker login -u "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_PASS"
docker buildx bake -f ./docker-compose.yml --progress plain --set *.platform=linux/arm64,linux/amd64 --push << parameters.target >>
## now, let's re-build those same images for Amazon ECR this is basically a re-tag and push because of the cache from the previous build.
## 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
REPO_PREFIX=$AWS_ECR_PREFIX/ docker buildx bake -f ./docker-compose.yml --progress plain --set *.platform=linux/arm64,linux/amd64 --push << parameters.target >>
working_directory: factory
workflows:
test:
jobs:
- check-factory-versions
- check-node-override-version
- test-image:
matrix:
alias: factory-arm
parameters:
test-target: [
test-factory-electron,
test-factory-cypress-included-electron,
test-factory-cypress-included-electron-non-root-user,
test-factory-all-included-electron-only
]
resourceClass: [arm.medium]
target: [factory]
- test-image:
matrix:
alias: factory
parameters:
test-target: [
test-factory-electron,
test-factory-chrome,
test-factory-chrome-non-root-user,
test-factory-firefox,
test-factory-edge,
test-factory-cypress-included-electron,
test-factory-cypress-included-electron-non-root-user,
test-factory-cypress-included-chrome,
test-factory-cypress-included-firefox,
test-factory-cypress-included-firefox-non-root-user,
test-factory-cypress-included-edge,
test-factory-all-included
]
resourceClass: [medium]
target: [factory]
- test-image:
matrix:
alias: base
parameters:
test-target: [
test-base
]
resourceClass: [medium]
target: [base]
- test-image:
matrix:
alias: base-arm
parameters:
test-target: [
test-base
]
resourceClass: [arm.medium]
target: [base]
- test-image:
matrix:
alias: browsers
parameters:
test-target: [
test-browsers-electron,
test-browsers-chrome,
test-browsers-firefox,
test-browsers-edge
]
resourceClass: [medium]
target: [browsers]
- test-image:
matrix:
alias: browsers-arm
parameters:
test-target: [
test-browsers-electron
]
resourceClass: [arm.medium]
target: [browsers]
- test-image:
matrix:
alias: included
parameters:
test-target: [
test-included-electron,
test-included-chrome,
test-included-firefox,
test-included-edge
]
resourceClass: [medium]
target: [included]
- test-image:
matrix:
alias: included-arm
parameters:
test-target: [
test-included-electron
]
resourceClass: [arm.medium]
target: [included]
# pushing the factory image must come first because the other images may pull it down to build
- push:
name: "Push Factory Image"
target: factory
context: test-runner:docker-push
filters:
branches:
only:
# Only branches matching the below regex filters will run
# Change to a feature branch such as <cypress-version>-node-<node.js version>-publish
# if publishing an old version
# This job must run because the base, browsers and included jobs depend on it
- master
requires:
- factory
- factory-arm
- check-node-override-version
- check-factory-versions
- push:
name: "Push Base Image"
target: base
context: test-runner:docker-push
filters:
branches:
only:
# Only branches matching the below regex filters will run
# Change to a feature branch such as <cypress-version>-node-<node.js version>-publish
# if publishing an old version
- master
requires:
- "Push Factory Image"
- base
- base-arm
- push:
name: "Push Browser Image"
target: browsers
context: test-runner:docker-push
filters:
branches:
only:
# Only branches matching the below regex filters will run
# Change to a feature branch such as <cypress-version>-node-<node.js version>-publish
# if publishing an old version
- master
requires:
- "Push Factory Image"
- browsers
- browsers-arm
- push:
target: included
name: "Push Included Image"
context: test-runner:docker-push
filters:
branches:
only:
# Only branches matching the below regex filters will run
# Change to a feature branch such as <cypress-version>-node-<node.js version>-publish
# if publishing an old version
- master
requires:
- "Push Factory Image"
- included
- included-arm