forked from cypress-io/cypress-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-config.js
902 lines (811 loc) · 30.1 KB
/
generate-config.js
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
// @ts-check
// this script generates CircleCI config file by looking at the "base/*" folders
// for each subfolder it creates a separate job
const globby = require('globby');
const fs = require('fs')
const path = require('path')
const os = require('os')
const semver = require('semver')
const { camelCase } = require('lodash')
const slugify = require('slugify')
const skipBaseImages = [
'6',
'8',
'8.0.0',
'8.15.1',
'8.16.0',
'8.2.1',
'8.9.3',
'8.9.3-npm-6.10.1',
'10',
'10.0.0',
'10.11.0',
'10.15.3',
'10.16.0',
'10.16.3',
'10.18.0',
'10.18.1',
'10.2.1',
'11.13.0',
'12.0.0',
'12.1.0',
'12.12.0',
'12.13.0',
'12.14.0',
'12.14.1',
'12.16.0',
'12.16.1',
'12.16.2',
'12.18.0',
'12.18.2',
'12.4.0',
'12.6.0',
'12.8.1',
'13.1.0',
'13.3.0',
'13.6.0',
'13.8.0',
'14.0.0',
'centos7',
'centos7-12.4.0',
'ubuntu16',
'ubuntu16-12.13.1',
'ubuntu16-8',
'ubuntu18-node12.14.1',
'ubuntu19-node12.14.1'
];
const skipBrowserImages = [
'chrome63-ff57',
'chrome65-ff57',
'chrome67',
'chrome67-ff57',
'chrome69',
'node8.15.1-chrome73',
'node8.2.1-chrome73',
'node8.9.3-chrome73',
'node8.9.3-npm6.10.1-chrome75',
'node8.9.3-npm6.10.1-chrome76-ff68',
'node10.11.0-chrome75',
'node10.16.0-chrome76',
'node10.16.0-chrome77',
'node10.16.0-chrome77-ff71',
'node10.16.3-chrome80-ff73',
'node10.2.1-chrome74',
'node11.13.0-chrome73',
'node12.0.0-chrome73',
'node12.0.0-chrome73-ff68',
'node12.0.0-chrome75',
'node12.13.0-chrome78-ff70',
'node12.13.0-chrome78-ff70-brave78',
'node12.13.0-chrome80-ff73',
'node12.13.0-chrome80-ff74',
'node12.14.0-chrome79-ff71',
'node12.14.1-chrome83-ff77',
'node12.16.1-chrome80-ff73',
'node12.16.2-chrome81-ff75',
'node12.18.0-chrome83-ff77',
'node12.4.0-chrome76',
'node12.6.0-chrome75',
'node12.6.0-chrome77',
'node12.8.1-chrome78-ff70',
'node12.8.1-chrome80-ff72',
'node13.1.0-chrome78-ff70',
'node13.3.0-chrome79-ff70',
'node13.6.0-chrome80-ff72'
]
const awsCodeBuildPreamble = `
version: 0.2
env:
variables:
PUBLIC_ECR_ALIAS: "cypress-io"
batch:
fast-fail: false
build-list:`
const awsCodeBuildPostamble = `
phases:
pre_build:
commands:
- aws --version
- echo Check if $IMAGE_TAG is in ECR...
- ./find-ecr-image.sh $IMAGE_REPO_NAME $IMAGE_TAG -p
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- aws ecr-public get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin public.ecr.aws/$PUBLIC_ECR_ALIAS
build:
commands:
- echo Building the Docker image...
- cd $IMAGE_DIR/$IMAGE_TAG
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG public.ecr.aws/$PUBLIC_ECR_ALIAS/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- echo Pushing the Docker image...
- docker push public.ecr.aws/$PUBLIC_ECR_ALIAS/$IMAGE_REPO_NAME:$IMAGE_TAG
`
const preamble = `
# WARNING: this file is automatically generated by ${path.basename(__filename)}
# info on building Docker images on Circle
# https://circleci.com/docs/2.0/building-docker-images/
version: 2.1
orbs:
node: circleci/[email protected]
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
checkNodeVersion:
type: boolean
description: Check if the FROM image name is strict Node version
default: true
steps:
- when:
condition: << parameters.checkNodeVersion >>
steps:
- run:
name: confirm image has Node << parameters.nodeVersion >>
# do not run Docker in the interactive mode - adds control characters!
command: |
version=$(docker run << parameters.imageName >> node --version)
if [ "$version" == "<< parameters.nodeVersion >>" ]; then
echo "Base image has the expected version of Node << parameters.nodeVersion >>";
else
echo "Problem: base image has unexpected Node version"
echo "Expected << parameters.nodeVersion >> and got $version"
exit 1
fi
- run:
name: test image << parameters.imageName >>
no_output_timeout: '3m'
command: |
docker build -t cypress/test -\\<<EOF
FROM << parameters.imageName >>
RUN echo "current user: $(whoami)"
ENV CI=1
WORKDIR /app
RUN npm init --yes
RUN npm install --save-dev cypress cypress-expect
RUN ./node_modules/.bin/cypress verify
RUN npx @bahmutov/cly init
# run Cypress by itself
RUN ./node_modules/.bin/cypress run
# run Cypress using module API and confirm number of passing tests
RUN ./node_modules/.bin/cypress-expect run --passing 1
EOF
- run:
name: test image << parameters.imageName >> using Kitchensink
no_output_timeout: '3m'
command: |
docker build -t cypress/test-kitchensink -\\<<EOF
FROM << parameters.imageName >>
RUN echo "current user: $(whoami)"
ENV CI=1
ENV CYPRESS_INTERNAL_FORCE_SCAFFOLD=1
WORKDIR /app
RUN npm init --yes
RUN npm install --save-dev cypress cypress-expect
RUN ./node_modules/.bin/cypress verify
RUN echo '{}' > cypress.json
# run Cypress and confirm minimum number of passing tets
RUN ./node_modules/.bin/cypress-expect run --min-passing 100
EOF
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 XX"
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: |
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: |
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: |
version=$(docker run << parameters.imageName >> edge --version)
if [[ "$version" =~ ^"<< parameters.edgeVersion >>" ]]; then
echo "Image has the expected version of Edge << parameters.edgeVersion >>"
echo "found $version"
else
echo "Problem: image has unexpected Edge version"
echo "Expected << parameters.edgeVersion >> and got $version"
exit 1
fi
- run:
name: test image << parameters.imageName >>
no_output_timeout: '3m'
command: |
docker build -t cypress/test -\\<<EOF
FROM << parameters.imageName >>
RUN echo "current user: $(whoami)"
ENV CI=1
RUN npm init --yes
RUN npm install --save-dev cypress
RUN ./node_modules/.bin/cypress verify
RUN npx @bahmutov/cly init
EOF
- 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: 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: 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: docker run cypress/test ./node_modules/.bin/cypress run --browser edge
- run:
name: scaffold image << parameters.imageName >> using Kitchensink
no_output_timeout: '3m'
command: |
docker build -t cypress/test-kitchensink -\\<<EOF
FROM << parameters.imageName >>
RUN echo "current user: $(whoami)"
ENV CI=1
ENV CYPRESS_INTERNAL_FORCE_SCAFFOLD=1
RUN npm init --yes
RUN npm install --save-dev cypress
RUN ./node_modules/.bin/cypress verify
RUN echo '{}' > cypress.json
EOF
- when:
condition: << parameters.chromeVersion >>
steps:
- run:
name: Test << parameters.chromeVersion >>
no_output_timeout: '1m'
command: docker run cypress/test-kitchensink ./node_modules/.bin/cypress run --browser chrome
- when:
condition: << parameters.firefoxVersion >>
steps:
- run:
name: Test << parameters.firefoxVersion >>
no_output_timeout: '1m'
command: docker run cypress/test-kitchensink ./node_modules/.bin/cypress run --browser firefox
- when:
condition: << parameters.edgeVersion >>
steps:
- run:
name: Test << parameters.edgeVersion >>
no_output_timeout: '1m'
command: docker run cypress/test-kitchensink ./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
mkdir test
cd test
echo "Initializing test project"
npx @bahmutov/cly init --cypress-version << parameters.cypressVersion >>
echo "Testing using Electron browser"
docker run -it -v $PWD:/e2e -w /e2e cypress/included:<< parameters.cypressVersion >>
echo "Testing using Chrome browser"
docker run -it -v $PWD:/e2e -w /e2e cypress/included:<< parameters.cypressVersion >> --browser chrome
working_directory: /tmp
test-included-image-using-kitchensink:
description: Testing Cypress pre-installed using Kitchensink
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: Testing Kitchensink
no_output_timeout: '3m'
command: |
node --version
mkdir test-kitchensink
cd test-kitchensink
npm init -y
echo '{}' > cypress.json
echo "Testing using Electron browser"
docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_INTERNAL_FORCE_SCAFFOLD=1 cypress/included:<< parameters.cypressVersion >>
echo "Testing using Chrome browser"
docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_INTERNAL_FORCE_SCAFFOLD=1 cypress/included:<< parameters.cypressVersion >> --browser chrome
working_directory: /tmp
docker-push:
description: Log in and push a given image to Docker hub
parameters:
imageName:
type: string
description: Docker image name to push
steps:
# before pushing, let's check again that the Docker Hub does not have the image
# accidental rebuild and overwrite of an image is bad, since it can bump every tool
# https://github.com/cypress-io/cypress/issues/6335
- halt-if-docker-image-exists:
imageName: << parameters.imageName >>
- run:
name: Pushing image << parameters.imageName >> to Docker Hub
command: |
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
docker push << parameters.imageName >>
jobs:
lint-markdown:
executor:
name: node/default
tag: '12'
steps:
- checkout
- node/with-cache:
steps:
- run: npm ci
- run: npm run check:markdown
build-base-image:
machine: true
parameters:
dockerName:
type: string
description: Image name to build
default: cypress/base
dockerTag:
type: string
description: Image tag to build like "12.14.0"
checkNodeVersion:
type: boolean
description: Check if the FROM image name is strict Node version
default: true
steps:
- checkout
- halt-if-docker-image-exists:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- run:
name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>
command: |
docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .
working_directory: base/<< parameters.dockerTag >>
- test-base-image:
nodeVersion: v<< parameters.dockerTag >>
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
checkNodeVersion: << parameters.checkNodeVersion >>
- halt-on-branch
- docker-push:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
build-browser-image:
machine: true
parameters:
dockerName:
type: string
description: Image name to build
default: cypress/browsers
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 XX"
steps:
- checkout
- halt-if-docker-image-exists:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- run:
name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>
command: |
docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .
working_directory: browsers/<< parameters.dockerTag >>
- test-browser-image:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
chromeVersion: << parameters.chromeVersion >>
firefoxVersion: << parameters.firefoxVersion >>
edgeVersion: << parameters.edgeVersion >>
- halt-on-branch
- docker-push:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
build-included-image:
machine: true
parameters:
dockerName:
type: string
description: Image name to build
default: cypress/included
dockerTag:
type: string
description: Image tag to build, should match Cypress version, like "3.8.1"
steps:
- checkout
- halt-if-docker-image-exists:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- run:
name: building Docker image << parameters.dockerName >>:<< parameters.dockerTag >>
command: |
docker build -t << parameters.dockerName >>:<< parameters.dockerTag >> .
working_directory: included/<< parameters.dockerTag >>
- test-included-image-versions:
cypressVersion: << parameters.dockerTag >>
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- test-included-image:
cypressVersion: << parameters.dockerTag >>
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- test-included-image-using-kitchensink:
cypressVersion: << parameters.dockerTag >>
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
- halt-on-branch
- docker-push:
imageName: << parameters.dockerName >>:<< parameters.dockerTag >>
workflows:
version: 2
lint:
jobs:
- lint-markdown
`
const formBaseWorkflow = (baseImages) => {
// skip images that already have been built
// one can update this list if the number of
// build jobs in circleci grows too long
const isSkipped = (tag) => skipBaseImages.includes(tag)
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = baseImages.filter(isIncluded).map(imageAndTag => {
// important to have indent
let job = ' - build-base-image:\n' +
` name: "base ${imageAndTag.tag}"\n` +
` dockerTag: "${imageAndTag.tag}"\n`
// do not check Node versions in some custom images
if (imageAndTag.tag === '12.0.0-libgbm' || imageAndTag.tag === 'manjaro-14.12.0') {
job += ' checkNodeVersion: false\n'
}
return job
})
// indent is important
const workflowName = ' build-base-images:\n' +
' jobs:\n'
const text = workflowName + yml.join('')
return text
}
const fullChromeVersion = (version) =>
`Google Chrome ${version}`
const fullFirefoxVersion = (version) =>
`Mozilla Firefox ${version}`
const fullEdgeVersion = (version) =>
`Microsoft Edge ${version}`
const findChromeVersion = (imageAndTag) => {
// image name like "nodeX.Y.Z-chromeXX..."
// the folder has "chromeXX" name, so extract the "XX" part
const matches = /chrome(\d+)/.exec(imageAndTag)
if (matches && matches[1]) {
return fullChromeVersion(matches[1])
}
return null
}
const findFirefoxVersion = (imageAndTag) => {
// image name like "nodeX.Y.Z-chromeXX-ffYY..."
// the folder has "ffYY" name, so extract the "YY" part
const matches = /-ff(\d+)/.exec(imageAndTag)
if (matches && matches[1]) {
return fullFirefoxVersion(matches[1])
}
return null
}
const findEdgeVersion = (imageAndTag) => {
// image name like "nodeX.Y.Z-edgeXX"
// so we will extract "XX" part
const matches = /-edge(\d+)/.exec(imageAndTag)
if (matches && matches[1]) {
return fullEdgeVersion(matches[1])
}
return null
}
const formBrowserWorkflow = (browserImages) => {
// not every browser image can be tested
// some old images do not have NPX for example
// so let them be
const isSkipped = (tag) => skipBrowserImages.includes(tag)
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = browserImages.filter(isIncluded).map(imageAndTag => {
const chromeVersion = findChromeVersion(imageAndTag.tag)
const firefoxVersion = findFirefoxVersion(imageAndTag.tag)
const edgeVersion = findEdgeVersion(imageAndTag.tag)
const foundBrowser = chromeVersion || firefoxVersion || edgeVersion
if (!foundBrowser) {
throw new Error(`Cannot find any browsers from image tag "${imageAndTag.tag}"`)
}
// important to have indent
let job = ' - build-browser-image:\n' +
` name: "browsers ${imageAndTag.tag}"\n` +
` dockerTag: "${imageAndTag.tag}"\n`
if (chromeVersion) {
job += ` chromeVersion: "${chromeVersion}"\n`
}
if (firefoxVersion) {
job += ` firefoxVersion: "${firefoxVersion}"\n`
}
if (edgeVersion) {
job += ` edgeVersion: "${edgeVersion}"\n`
}
return job
})
// indent is important
const workflowName = ' build-browser-images:\n' +
' jobs:\n'
const text = workflowName + yml.join('')
return text
}
const formIncludedWorkflow = (images) => {
// skip images that have been built already
const isSkipped = (tag) => {
return semver.lt(tag, '6.0.0')
}
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = images.filter(isIncluded).map(imageAndTag => {
// important to have indent
const job = ' - build-included-image:\n' +
` name: "included ${imageAndTag.tag}"\n` +
` dockerTag: "${imageAndTag.tag}"\n`
return job
})
// indent is important
const workflowName = ' build-included-images:\n' +
' jobs:\n'
const text = workflowName + yml.join('')
return text
}
const writeConfigFile = (baseImages, browserImages, includedImages) => {
const base = formBaseWorkflow(baseImages)
const browsers = formBrowserWorkflow(browserImages)
const included = formIncludedWorkflow(includedImages)
const text = preamble.trim() + os.EOL + base + os.EOL + browsers + os.EOL + included
fs.writeFileSync('circle.yml', text, 'utf8')
console.log('generated circle.yml')
}
const splitImageFolderName = (folderName) => {
const [name, tag] = folderName.split('/')
return {
name,
tag
}
}
const formAwsCodeBuildBaseWorkflow = (baseImages) => {
// skip images that already have been built
// one can update this list if the number of
// build jobs in AWS CodeBuild grows too long
const isSkipped = (tag) => skipBaseImages.includes(tag)
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = baseImages.filter(isIncluded).map(imageAndTag => {
console.log('imageAndTag', imageAndTag)
// @ts-ignore
const tagSlug = slugify(imageAndTag.tag, '-')
console.log('tagSlug', tagSlug)
const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)
let job = ` - identifier: ${identifier}
env:
image: aws/codebuild/standard:5.0
type: LINUX_CONTAINER
privileged-mode: true
compute-type: BUILD_GENERAL1_MEDIUM
variables:
IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"
IMAGE_DIR: "${imageAndTag.name}"
IMAGE_TAG: "${imageAndTag.tag}"\n`
return job
})
const text = yml.join('')
return text
}
const formAwsCodeBuildBrowserWorkflow = (baseImages) => {
// skip images that already have been built
// one can update this list if the number of
// build jobs in AWS CodeBuild grows too long
const isSkipped = (tag) => skipBrowserImages.includes(tag)
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = baseImages.filter(isIncluded).map(imageAndTag => {
console.log('imageAndTag', imageAndTag)
// @ts-ignore
const tagSlug = slugify(imageAndTag.tag, '-')
console.log('tagSlug', tagSlug)
const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)
let job = ` - identifier: ${identifier}
env:
image: aws/codebuild/standard:5.0
type: LINUX_CONTAINER
privileged-mode: true
compute-type: BUILD_GENERAL1_MEDIUM
variables:
IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"
IMAGE_DIR: "${imageAndTag.name}"
IMAGE_TAG: "${imageAndTag.tag}"\n`
return job
})
const text = yml.join('')
return text
}
const formAwsCodeBuildIncludedWorkflow = (baseImages) => {
// skip images that already have been built
// one can update this list if the number of
// build jobs in AWS CodeBuild grows too long
const isSkipped = (tag) => skipBaseImages.includes(tag)
const isIncluded = (imageAndTag) => !isSkipped(imageAndTag.tag)
const yml = baseImages.filter(isIncluded).map(imageAndTag => {
console.log('imageAndTag', imageAndTag)
// @ts-ignore
const tagSlug = slugify(imageAndTag.tag, '-')
console.log('tagSlug', tagSlug)
const identifier = camelCase(`${imageAndTag.name}${imageAndTag.tag}`)
let job = ` - identifier: ${identifier}
env:
image: aws/codebuild/standard:5.0
type: LINUX_CONTAINER
privileged-mode: true
compute-type: BUILD_GENERAL1_MEDIUM
variables:
IMAGE_REPO_NAME: "cypress/${imageAndTag.name}"
IMAGE_DIR: "${imageAndTag.name}"
IMAGE_TAG: "${imageAndTag.tag}"\n`
return job
})
const text = yml.join('')
return text
}
const writeBuildspecConfigFile = (baseImages, browserImages, includedImages) => {
const base = formAwsCodeBuildBaseWorkflow(baseImages)
const browsers = formAwsCodeBuildBrowserWorkflow(browserImages)
const included = formAwsCodeBuildIncludedWorkflow(includedImages)
const text = awsCodeBuildPreamble.trim() + os.EOL + base + os.EOL + browsers + os.EOL + included + os.EOL + awsCodeBuildPostamble.trim()
fs.writeFileSync('buildspec.yml', text, 'utf8')
console.log('generated buildspec.yml')
}
(async () => {
const basePaths = await globby('base/*', {onlyDirectories: true});
const base = basePaths.map(splitImageFolderName)
console.log(' *** base images ***')
console.log(base)
const browsersPaths = await globby('browsers/*', {onlyDirectories: true});
const browsers = browsersPaths.map(splitImageFolderName)
console.log(' *** browser images ***')
console.log(browsers)
const includedPaths = await globby('included/*', {onlyDirectories: true});
const included = includedPaths.map(splitImageFolderName)
console.log(' *** included images ***')
console.log(included)
writeConfigFile(base, browsers, included)
writeBuildspecConfigFile(base, browsers, included)
})();