/
circle.yml
373 lines (363 loc) · 16.7 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
# 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:
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: docker compose target being tested
steps:
- run:
name: Check if image for << parameters.target >> 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: |
DOCKER_TAG=''
if [ << parameters.target >> == factory ]; then DOCKER_TAG=cypress/factory:${FACTORY_VERSION}; fi
if [ << parameters.target >> == base ]; then DOCKER_TAG=cypress/base:${BASE_IMAGE_TAG}; fi
if [ << parameters.target >> == browsers ]; then DOCKER_TAG=cypress/browsers:${BROWSERS_IMAGE_TAG}; fi
if [ << parameters.target >> == included ]; then DOCKER_TAG=cypress/included:${INCLUDED_IMAGE_TAG}; fi
if npx docker-image-not-found --repo $DOCKER_TAG; then
echo Docker hub says image $DOCKER_TAG does not exist
else
echo Docker hub has image $DOCKER_TAG or not responding
echo We should stop in this case
circleci-agent step halt
fi
jobs:
check-factory-versions:
machine:
image: ubuntu-2204:2022.10.2
steps:
- checkout
- expand-env-file
- run:
name: building docker image
command: |
docker compose build --progress plain factory
working_directory: factory
- run:
name: build test image
command: |
docker compose build --progress plain test-factory-all-included
working_directory: factory/test-project
- run:
name: check node version
command: |
ACTUAL_VERSION=$(docker compose run 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 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 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 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 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 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:
name: check git version
command: |
ACTUAL_VERSION=$(docker compose run test-factory-all-included git --version)
if [ "git version 2.30.2" != "${ACTUAL_VERSION}" ]; then
echo "Version mismatch, git package version: git version 2.30.2 != ${ACTUAL_VERSION}"
exit 1;
fi
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 test-factory-all-included ssh -V)
echo "Version ${ACTUAL_VERSION} confirmed"
working_directory: factory/test-project
check-node-override-version:
machine:
image: ubuntu-2204:2022.10.2
steps:
- checkout
- expand-env-file
- run:
name: building docker image
command: |
docker compose build --progress plain factory
working_directory: factory
- run:
name: build test image
command: |
docker compose build --progress plain test-factory-node-override
working_directory: factory/test-project
- run:
name: check node version
command: |
ACTUAL_VERSION=$(docker compose run 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:2022.10.2
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 build --progress plain factory; fi
docker compose build --progress plain << parameters.target >>
working_directory: factory
- run:
name: test
command: |
docker compose build --progress plain << parameters.test-target >>
docker compose run << parameters.test-target >>
working_directory: factory/test-project
push:
machine:
image: ubuntu-2204:2022.10.2
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: |
## 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
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:
version: 2
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
- 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
- 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
- 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
- master
requires:
- "Push Factory Image"
- included
- included-arm