1- name : Docker
1+ name : CI and Docker Deploy
22
33on :
44 push :
5- branches : [ 'main', 'dev', 'staging' ]
6- tags : [ 'v*.*.*' ]
5+ branches : ['main', 'dev', 'staging']
6+ tags : ['v*.*.*']
77 pull_request :
8- branches : [ 'main', ' dev', 'staging' ]
8+ branches : [' dev']
99
1010concurrency :
1111 group : ${{ github.workflow }}-${{ github.ref }}
@@ -14,26 +14,10 @@ concurrency:
1414env :
1515 # github.repository as <account>/<repo>
1616 IMAGE_NAME : mnestix-browser
17- IMAGE_TAG : latest
1817 # Update the version manually
19- IMAGE_TAG_VERSION : 1.4.0
20- REGISTRY_USER : ${{ secrets.DOCKER_USERNAME }}
21- REGISTRY_PASS : ${{ secrets.DOCKER_API_TOKEN }}
18+ IMAGE_TAG_VERSION : 1.4.1
2219
2320jobs :
24- unit-tests :
25- name : Unit Tests
26- runs-on : ubuntu-latest
27- permissions :
28- contents : read
29-
30- steps :
31- - name : Checkout repository
32- uses : actions/checkout@v4
33- - name : Run unit tests
34- id : test_units
35- run : yarn install && npx jest
36-
3721 build-browser-image :
3822 name : Build browser image
3923 runs-on : ubuntu-latest
@@ -45,52 +29,75 @@ jobs:
4529 - name : Checkout repository
4630 uses : actions/checkout@v4
4731
32+ - name : Set up Docker Buildx
33+ uses : docker/setup-buildx-action@v3
34+
4835 - name : Build image
49- id : build
50- run : docker compose build mnestix-browser
36+ uses : docker/build-push-action@v6
37+ with :
38+ platforms : linux/amd64
39+ context : ' .'
40+ cache-to : type=local,dest=/tmp/buildx-amd64-cache,mode=max
41+ target : production
42+ push : false
43+ tags : mnestix/mnestix-browser:latest
44+ load : true
45+
46+ - name : Cache buildx
47+ uses : actions/cache/save@v4
48+ with :
49+ path : |
50+ /tmp/buildx-amd64-cache
51+ key : buildx-amd64-${{github.ref}}-${{ github.run_id }}
52+ enableCrossOsArchive : true
5153
5254 - name : Save mnestix-browser image
5355 run : docker save mnestix/mnestix-browser:latest -o mnestix-browser.tar
5456
55- - name : Upload mnestix-browser artifact
56- uses : actions/upload-artifact @v4
57+ - name : Cache image
58+ uses : actions/cache/save @v4
5759 with :
58- retention-days : 1
59- name : mnestix-browser
6060 path : mnestix-browser.tar
61+ key : docker-image-${{github.ref}}-${{ github.run_id }}
6162
6263 e2e-tests :
6364 name : e2e test matrix
6465 runs-on : ubuntu-latest
65- needs : [ 'build-browser-image' ]
66+ needs : ['build-browser-image']
6667 permissions :
6768 contents : read
6869 strategy :
6970 fail-fast : false
7071 matrix :
7172 # add more containers to run more tests in parallel
72- containers : [ 1, 2, 3, 4 ]
73+ containers : [1, 2, 3, 4]
7374
7475 steps :
7576 - name : Checkout repository
7677 uses : actions/checkout@v4
7778
78- - name : Download mnestix-browser artifact
79- uses : actions/download-artifact @v4
79+ - name : Restore image
80+ uses : actions/cache/restore @v4
8081 with :
81- name : mnestix-browser
82+ path : mnestix-browser.tar
83+ key : docker-image-${{github.ref}}-${{ github.run_id }}
8284
8385 # image too big to be reused
84- - name : prepare tests
85- run : |
86- docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests build cypress-test
87- docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests pull
86+ - name : Build test image
87+ run : docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests build cypress-test
88+
89+ - name : Pull images
90+ run : docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests pull
8891
92+ # overwrite the pulled image with the new image
8993 - name : Load mnestix-browser image
9094 run : docker load -i mnestix-browser.tar
9195
9296 - name : Run e2e tests
93- id : test
97+ # 18-minute timeout to speed up failing tests that are retried too long.
98+ # If the timeout is reached under normal test conditions, consider increasing
99+ # the number of containers to run more tests in parallel.
100+ timeout-minutes : 18
94101 run : |
95102 docker compose -f compose.yml -f docker-compose/compose.test.yml --profile tests up -d &&
96103 docker compose -f compose.yml -f docker-compose/compose.test.yml attach cypress-test
@@ -101,62 +108,126 @@ jobs:
101108 TEST_USER_PASSWORD : ${{ secrets.TEST_USER_PASSWORD }}
102109
103110 - name : E2E test collect artifact
104- id : test_artifact
111+ if : always()
105112 uses : actions/upload-artifact@v4
106113 with :
107114 name : cypress-artifacts-${{ matrix.containers }}
108115 path : cypress-artifacts/
109116
110- - name : Fail if e2e tests failed
111- if : ${{ failure() }}
112- run : exit 1
117+ unit-tests :
118+ name : Unit Tests
119+ runs-on : ubuntu-latest
120+ permissions :
121+ contents : read
122+
123+ steps :
124+ - name : Checkout repository
125+ uses : actions/checkout@v4
126+ - name : Install dependencies
127+ run : yarn install
128+ - name : Run unit tests
129+ run : npx jest
130+
131+ # Target for PR Merge Check
132+ ci-success :
133+ name : Successful build and tests
134+ runs-on : ubuntu-latest
135+ needs : ['unit-tests', 'e2e-tests']
136+ steps :
137+ - name : Success
138+ run : echo "Success"
139+
140+ # It takes 22 minutes to build the arm64 image in amd64-QEMU so we build a cache on the arm64 runner
141+ # Github Issues point to a yarn problem
142+ # https://github.com/docker/build-push-action/issues/471
143+ # https://github.com/nodejs/docker-node/issues/1335
144+ build-arm-cache :
145+ name : Build arm image cache
146+ runs-on : ubuntu-24.04-arm
147+ permissions :
148+ contents : read
149+ steps :
150+ - name : Checkout repository
151+ uses : actions/checkout@v4
152+
153+ - name : Set up Docker Buildx
154+ uses : docker/setup-buildx-action@v3
155+
156+ - name : Build
157+ uses : docker/build-push-action@v6
158+ with :
159+ platforms : linux/arm64
160+ context : ' .'
161+ cache-to : type=local,dest=/tmp/buildx-arm64-cache,mode=max
162+ target : production
163+ push : false
164+
165+ - name : Cache buildx
166+ uses : actions/cache/save@v4
167+ with :
168+ path : |
169+ /tmp/buildx-arm64-cache
170+ key : buildx-arm64-${{github.ref}}-${{ github.run_id }}
171+ enableCrossOsArchive : true
113172
114173 push-image :
115174 name : Push image to registry
116- needs : [ 'build-browser-image ', 'unit-tests', 'e2e-tests' ]
175+ needs : ['ci-success ', 'build-arm-cache' ]
117176 runs-on : ubuntu-latest
118- if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/dev'
177+ if : github.event_name != 'pull_request' &&
178+ github.repository_owner == 'eclipse-mnestix' &&
179+ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/dev')
119180 permissions :
120181 contents : read
121182 packages : write
122183
123184 steps :
124- - name : Extract branch name
125- id : extract_branch
126- run : echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
185+ - name : Restore amd64 cache
186+ uses : actions/cache/restore@v4
187+ with :
188+ path : |
189+ /tmp/buildx-amd64-cache
190+ key : buildx-amd64-${{github.ref}}-${{ github.run_id }}
191+ # can be build without cache
192+ fail-on-cache-miss : false
193+ - name : Restore arm64 cache
194+ uses : actions/cache/restore@v4
195+ with :
196+ path : |
197+ /tmp/buildx-arm64-cache
198+ key : buildx-arm64-${{github.ref}}-${{ github.run_id }}
199+ # building takes ages
200+ fail-on-cache-miss : true
127201
128202 - name : Checkout repository
129203 uses : actions/checkout@v4
130204
131- - name : Download mnestix-browser artifact
132- uses : actions/download-artifact@v4
205+ - name : Set up QEMU
206+ uses : docker/setup-qemu-action@v3
207+ - name : Set up Docker Buildx
208+ uses : docker/setup-buildx-action@v3
209+
210+ - name : Login to DockerHub
211+ uses : docker/login-action@v3
133212 with :
134- name : mnestix-browser
213+ username : ${{ secrets.DOCKER_USERNAME }}
214+ password : ${{ secrets.DOCKER_API_TOKEN }}
135215
136- - name : Load mnestix-browser image
137- run : docker load -i mnestix-browser.tar
216+ - name : Extract branch name
217+ id : extract_branch
218+ run : echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
138219
139- # Login against a Docker registry except on PR
140- # https://github.com/docker/login-action
141- - name : Log into docker hub
142- if : github.event_name != 'pull_request'
143- uses : docker/login-action@v3
220+ - name : Build and push docker images
221+ uses : docker/build-push-action@v6
144222 with :
145- username : ${{ env.REGISTRY_USER }}
146- password : ${{ env.REGISTRY_PASS }}
147-
148- - name : Push Image to Production
149- id : push-prod
150- if : github.ref == 'refs/heads/main'
151- run : docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$IMAGE_TAG &&
152- docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$IMAGE_TAG_VERSION &&
153- docker push mnestix/$IMAGE_NAME:$IMAGE_TAG &&
154- docker push mnestix/$IMAGE_NAME:$IMAGE_TAG_VERSION
155-
156- - name : Push Image to development
157- id : push-dev
158- if : github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/staging'
159- env :
160- BRANCH_NAME : ${{ steps.extract_branch.outputs.branch }}
161- run : docker tag mnestix/$IMAGE_NAME mnestix/$IMAGE_NAME:$BRANCH_NAME &&
162- docker push mnestix/$IMAGE_NAME:$BRANCH_NAME
223+ platforms : linux/amd64,linux/arm64
224+ context : ' .'
225+ cache-from : |
226+ type=local,src=/tmp/buildx-arm64-cache
227+ type=local,src=/tmp/buildx-amd64-cache
228+ target : production
229+ push : true
230+ tags : |
231+ ${{ github.ref == 'refs/heads/main' && format('mnestix/{0}:{1}', env.IMAGE_NAME, env.IMAGE_TAG_VERSION) || '' }}
232+ ${{ github.ref == 'refs/heads/main' && format('mnestix/{0}:latest', env.IMAGE_NAME) || '' }}
233+ ${{ github.ref != 'refs/heads/main' && format('mnestix/{0}:{1}', env.IMAGE_NAME, steps.extract_branch.outputs.branch) || '' }}
0 commit comments