1+ name : Publish Docker image
2+
3+ # !!! NEVER add on push when there is on workflow_call
4+ # if you do that the workflow can run multiple times
5+ # for instance if you re-use this docker build workflow for prod deployment and for local-env in PR
6+ # it will build the docker image it twice
7+ # if you build => deploy => run e2e against prod it will build the image 3 times!
8+ on :
9+ # to allow to wait for a docker image to be published to proceed in another workflow
10+ workflow_call :
11+
12+ jobs :
13+ build-amd64 :
14+ runs-on : ubuntu-24.04
15+ steps :
16+ - name : Check out the repo
17+ uses : actions/checkout@v4
18+
19+ # this is needed to address this issue according to the comment https://github.com/devcontainers/ci/issues/271#issuecomment-2301764487
20+ # otherwise our TourmalineCore org name cannot be used in docker image names, only tourmalinecore
21+ - name : Add Registry Image Env Var With Lowercase Organization and Repo Name
22+ run : |
23+ echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
24+ - name : Prepare
25+ run : |
26+ platform=linux/amd64
27+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
28+ - name : Docker meta
29+ id : meta
30+ uses : docker/metadata-action@v5
31+ with :
32+ images : ${{ env.REGISTRY_IMAGE }}
33+
34+ - name : Log in to GitHub Container Registry
35+ uses : docker/login-action@v3
36+ with :
37+ registry : ghcr.io
38+ username : ${{ github.actor }}
39+ password : ${{ secrets.GITHUB_TOKEN }}
40+
41+ - name : Set up Docker Buildx
42+ uses : docker/setup-buildx-action@v3
43+
44+ - name : Build and push by digest
45+ id : build
46+ uses : docker/build-push-action@v6
47+ with :
48+ platforms : linux/amd64
49+ context : .
50+ file : ./Api/Dockerfile
51+ build-args : |
52+ EXCLUDE_UNIT_TESTS_FROM_BUILD=true
53+ labels : ${{ steps.meta.outputs.labels }}
54+ tags : ${{ env.REGISTRY_IMAGE }}
55+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
56+
57+ - name : Export digest
58+ run : |
59+ mkdir -p ${{ runner.temp }}/digests
60+ digest="${{ steps.build.outputs.digest }}"
61+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
62+ - name : Upload digest
63+ uses : actions/upload-artifact@v4
64+ with :
65+ name : digests-${{ env.PLATFORM_PAIR }}
66+ path : ${{ runner.temp }}/digests/*
67+ if-no-files-found : error
68+ retention-days : 1
69+
70+ build-arm64 :
71+ runs-on : ubuntu-24.04-arm
72+ steps :
73+ - name : Check out the repo
74+ uses : actions/checkout@v4
75+
76+ # this is needed to address this issue according to the comment https://github.com/devcontainers/ci/issues/271#issuecomment-2301764487
77+ # otherwise our TourmalineCore org name cannot be used in docker image names, only tourmalinecore
78+ - name : Add Registry Image Env Var With Lowercase Organization and Repo Name
79+ run : |
80+ echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
81+ - name : Prepare
82+ run : |
83+ platform=linux/arm64
84+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
85+ - name : Docker meta
86+ id : meta
87+ uses : docker/metadata-action@v5
88+ with :
89+ images : ${{ env.REGISTRY_IMAGE }}
90+
91+ - name : Log in to GitHub Container Registry
92+ uses : docker/login-action@v3
93+ with :
94+ registry : ghcr.io
95+ username : ${{ github.actor }}
96+ password : ${{ secrets.GITHUB_TOKEN }}
97+
98+ - name : Set up Docker Buildx
99+ uses : docker/setup-buildx-action@v3
100+
101+ - name : Build and push by digest
102+ id : build
103+ uses : docker/build-push-action@v6
104+ with :
105+ platforms : linux/arm64
106+ context : .
107+ file : ./Api/Dockerfile
108+ build-args : |
109+ EXCLUDE_UNIT_TESTS_FROM_BUILD=true
110+ labels : ${{ steps.meta.outputs.labels }}
111+ tags : ${{ env.REGISTRY_IMAGE }}
112+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
113+
114+ - name : Export digest
115+ run : |
116+ mkdir -p ${{ runner.temp }}/digests
117+ digest="${{ steps.build.outputs.digest }}"
118+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
119+ - name : Upload digest
120+ uses : actions/upload-artifact@v4
121+ with :
122+ name : digests-${{ env.PLATFORM_PAIR }}
123+ path : ${{ runner.temp }}/digests/*
124+ if-no-files-found : error
125+ retention-days : 1
126+ merge :
127+ runs-on : ubuntu-24.04
128+ needs :
129+ - build-amd64
130+ - build-arm64
131+ steps :
132+ # this is needed to address this issue according to the comment https://github.com/devcontainers/ci/issues/271#issuecomment-2301764487
133+ # otherwise our TourmalineCore org name cannot be used in docker image names, only tourmalinecore
134+ - name : Add Registry Image Env Var With Lowercase Organization and Repo Name
135+ run : |
136+ echo "REGISTRY_IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
137+ - name : Download digests
138+ uses : actions/download-artifact@v4
139+ with :
140+ path : ${{ runner.temp }}/digests
141+ pattern : digests-*
142+ merge-multiple : true
143+
144+ - name : Log in to GitHub Container Registry
145+ uses : docker/login-action@v3
146+ with :
147+ registry : ghcr.io
148+ username : ${{ github.actor }}
149+ password : ${{ secrets.GITHUB_TOKEN }}
150+
151+ - name : Set up Docker Buildx
152+ uses : docker/setup-buildx-action@v3
153+
154+ - name : Extract metadata (tags, labels) for Docker
155+ id : meta
156+ uses : docker/metadata-action@v5
157+ with :
158+ images : ${{ env.REGISTRY_IMAGE }}
159+ tags : |
160+ # minimal (short sha)
161+ type=sha
162+ # full length sha
163+ type=sha,format=long
164+ # set latest tag for default branch
165+ # https://github.com/docker/metadata-action/issues/171 explains how to tag latest only on default branch
166+ type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
167+ env :
168+ # https://github.com/docker/metadata-action/issues/283
169+ # without this flag it won't tag the image using the commit SHA
170+ # for non push events like pull_request ones it requires this :(
171+ DOCKER_METADATA_PR_HEAD_SHA : true
172+
173+ - name : Create manifest list and push
174+ working-directory : ${{ runner.temp }}/digests
175+ run : |
176+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
177+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
178+ - name : Inspect image
179+ run : |
180+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments