@@ -3,6 +3,9 @@ name: Docker images
33
44# Run this Build for all pushes to 'main' or maintenance branches, or tagged releases.
55# Also run for PRs to ensure PR doesn't break Docker build process
6+ # NOTE: uses "reusable-docker-build.yml" in DSpace/DSpace to actually build each of the Docker images
7+ # https://github.com/DSpace/DSpace/blob/main/.github/workflows/reusable-docker-build.yml
8+ #
69on :
710 push :
811 branches :
@@ -17,7 +20,6 @@ permissions:
1720
1821
1922env :
20- REGISTRY_IMAGE : dspace/dspace-angular
2123 # Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action)
2224 # For a new commit on default branch (main), use the literal tag 'latest' on Docker image.
2325 # For a new commit on other branches, use the branch name as the tag for Docker image.
@@ -34,287 +36,40 @@ env:
3436
3537jobs :
3638 # ############################################################
37- # Build/Push the '${{ env.REGISTRY_IMAGE }} ' image
39+ # Build/Push the 'dspace/dspace-angular ' image
3840 # ############################################################
3941 dspace-angular :
4042 # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular'
4143 if : github.repository == 'dspace/dspace-angular'
42-
43- strategy :
44- matrix :
45- # Architectures / Platforms for which we will build Docker images
46- arch : ['linux/amd64', 'linux/arm64']
47- os : [ubuntu-latest]
48- isPr :
49- - ${{ github.event_name == 'pull_request' }}
50- # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
51- # The below exclude therefore ensures we do NOT build ARM64 for PRs.
52- exclude :
53- - isPr : true
54- os : ubuntu-latest
55- arch : linux/arm64
56-
57- runs-on : ${{ matrix.os }}
58- steps :
59- # https://github.com/actions/checkout
60- - name : Checkout codebase
61- uses : actions/checkout@v4
62-
63- # https://github.com/docker/setup-buildx-action
64- - name : Setup Docker Buildx
65- uses : docker/setup-buildx-action@v3
66-
67- # https://github.com/docker/setup-qemu-action
68- - name : Set up QEMU emulation to build for multiple architectures
69- uses : docker/setup-qemu-action@v3
70-
71- # https://github.com/docker/login-action
72- - name : Login to DockerHub
73- # Only login if not a PR, as PRs only trigger a Docker build and not a push
74- if : ${{ ! matrix.isPr }}
75- uses : docker/login-action@v3
76- with :
77- username : ${{ secrets.DOCKER_USERNAME }}
78- password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
79-
80- # https://github.com/docker/metadata-action
81- # Get Metadata for docker_build step below
82- - name : Sync metadata (tags, labels) from GitHub to Docker for 'dspace-angular' image
83- id : meta_build
84- uses : docker/metadata-action@v5
85- with :
86- images : ${{ env.REGISTRY_IMAGE }}
87- tags : ${{ env.IMAGE_TAGS }}
88- flavor : ${{ env.TAGS_FLAVOR }}
89-
90- # https://github.com/docker/build-push-action
91- - name : Build and push 'dspace-angular' image
92- id : docker_build
93- uses : docker/build-push-action@v5
94- with :
95- context : .
96- file : ./Dockerfile
97- platforms : ${{ matrix.arch }}
98- # For pull requests, we run the Docker build (to ensure no PR changes break the build),
99- # but we ONLY do an image push to DockerHub if it's NOT a PR
100- push : ${{ ! matrix.isPr }}
101- # Use tags / labels provided by 'docker/metadata-action' above
102- tags : ${{ steps.meta_build.outputs.tags }}
103- labels : ${{ steps.meta_build.outputs.labels }}
104-
105- # Export the digest of Docker build locally (for non PRs only)
106- - name : Export digest
107- if : ${{ ! matrix.isPr }}
108- run : |
109- mkdir -p /tmp/digests
110- digest="${{ steps.docker_build.outputs.digest }}"
111- touch "/tmp/digests/${digest#sha256:}"
112-
113- # Upload digest to an artifact, so that it can be used in manifest below
114- - name : Upload digest
115- if : ${{ ! matrix.isPr }}
116- uses : actions/upload-artifact@v3
117- with :
118- name : digests
119- path : /tmp/digests/*
120- if-no-files-found : error
121- retention-days : 1
122-
123- # Merge digests into a manifest.
124- # This runs after all Docker builds complete above, and it tells hub.docker.com
125- # that these builds should be all included in the manifest for this tag.
126- # (e.g. AMD64 and ARM64 should be listed as options under the same tagged Docker image)
127- # Borrowed from https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
128- dspace-angular_manifest :
129- if : ${{ github.event_name != 'pull_request' }}
130- runs-on : ubuntu-latest
131- needs :
132- - dspace-angular
133- steps :
134- - name : Download digests
135- uses : actions/download-artifact@v3
136- with :
137- name : digests
138- path : /tmp/digests
139-
140- - name : Set up Docker Buildx
141- uses : docker/setup-buildx-action@v3
142-
143- - name : Add Docker metadata for image
144- id : meta
145- uses : docker/metadata-action@v5
146- with :
147- images : ${{ env.REGISTRY_IMAGE }}
148- tags : ${{ env.IMAGE_TAGS }}
149- flavor : ${{ env.TAGS_FLAVOR }}
150-
151- - name : Login to Docker Hub
152- uses : docker/login-action@v3
153- with :
154- username : ${{ secrets.DOCKER_USERNAME }}
155- password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
156-
157- - name : Create manifest list from digests and push
158- working-directory : /tmp/digests
159- run : |
160- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
161- $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
162-
163- - name : Inspect image
164- run : |
165- docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
44+ # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image
45+ uses : DSpace/DSpace/.github/workflows/reusable-docker-build.yml@main
46+ with :
47+ build_id : dspace-angular
48+ image_name : dspace/dspace-angular
49+ dockerfile_path : ./Dockerfile
50+ secrets :
51+ DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
52+ DOCKER_ACCESS_TOKEN : ${{ secrets.DOCKER_ACCESS_TOKEN }}
16653
16754 # ############################################################
168- # Build/Push the '${{ env.REGISTRY_IMAGE }} ' image ('-dist' tag)
55+ # Build/Push the 'dspace/dspace-angular ' image ('-dist' tag)
16956 # ############################################################
17057 dspace-angular-dist :
17158 # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular'
17259 if : github.repository == 'dspace/dspace-angular'
173-
174- strategy :
175- matrix :
176- # Architectures / Platforms for which we will build Docker images
177- arch : ['linux/amd64', 'linux/arm64']
178- os : [ubuntu-latest]
179- isPr :
180- - ${{ github.event_name == 'pull_request' }}
181- # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
182- # The below exclude therefore ensures we do NOT build ARM64 for PRs.
183- exclude :
184- - isPr : true
185- os : ubuntu-latest
186- arch : linux/arm64
187-
188- runs-on : ${{ matrix.os }}
189- steps :
190- # https://github.com/actions/checkout
191- - name : Checkout codebase
192- uses : actions/checkout@v4
193-
194- # https://github.com/docker/setup-buildx-action
195- - name : Setup Docker Buildx
196- uses : docker/setup-buildx-action@v3
197-
198- # https://github.com/docker/setup-qemu-action
199- - name : Set up QEMU emulation to build for multiple architectures
200- uses : docker/setup-qemu-action@v3
201-
202- # https://github.com/docker/login-action
203- - name : Login to DockerHub
204- # Only login if not a PR, as PRs only trigger a Docker build and not a push
205- if : ${{ ! matrix.isPr }}
206- uses : docker/login-action@v3
207- with :
208- username : ${{ secrets.DOCKER_USERNAME }}
209- password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
210-
211- # https://github.com/docker/metadata-action
212- # Get Metadata for docker_build_dist step below
213- - name : Sync metadata (tags, labels) from GitHub to Docker for 'dspace-angular-dist' image
214- id : meta_build_dist
215- uses : docker/metadata-action@v5
216- with :
217- images : ${{ env.REGISTRY_IMAGE }}
218- tags : ${{ env.IMAGE_TAGS }}
219- # As this is a "dist" image, its tags are all suffixed with "-dist". Otherwise, it uses the same
220- # tagging logic as the primary '${{ env.REGISTRY_IMAGE }}' image above.
221- flavor : ${{ env.TAGS_FLAVOR }}
222- suffix=-dist
223-
224- - name : Build and push 'dspace-angular-dist' image
225- id : docker_build_dist
226- uses : docker/build-push-action@v5
227- with :
228- context : .
229- file : ./Dockerfile.dist
230- platforms : ${{ matrix.arch }}
231- # For pull requests, we run the Docker build (to ensure no PR changes break the build),
232- # but we ONLY do an image push to DockerHub if it's NOT a PR
233- push : ${{ ! matrix.isPr }}
234- # Use tags / labels provided by 'docker/metadata-action' above
235- tags : ${{ steps.meta_build_dist.outputs.tags }}
236- labels : ${{ steps.meta_build_dist.outputs.labels }}
237-
238- # Export the digest of Docker build locally (for non PRs only)
239- - name : Export digest
240- if : ${{ ! matrix.isPr }}
241- run : |
242- mkdir -p /tmp/digests
243- digest="${{ steps.docker_build_dist.outputs.digest }}"
244- touch "/tmp/digests/${digest#sha256:}"
245-
246- # Upload Digest to an artifact, so that it can be used in manifest below
247- - name : Upload digest
248- if : ${{ ! matrix.isPr }}
249- uses : actions/upload-artifact@v3
250- with :
251- # NOTE: It's important that this artifact has a unique name so that two
252- # image builds don't upload digests to the same artifact.
253- name : digests-dist
254- path : /tmp/digests/*
255- if-no-files-found : error
256- retention-days : 1
257-
258- # If the 'linux/amd64' -dist image was just updated for the 'main' branch,
259- # Then redeploy https://sandbox.dspace.org using that updated image.
260- - name : Redeploy sandbox.dspace.org (based on main branch)
261- if : ${{ ! matrix.isPr && matrix.arch == 'linux/amd64' && github.ref_name == github.event.repository.default_branch }}
262- run : |
263- curl -X POST $REDEPLOY_SANDBOX_URL
264- env :
265- REDEPLOY_SANDBOX_URL : ${{ secrets.REDEPLOY_SANDBOX_URL }}
266-
267- # If the 'linux/amd64' -dist image was just updated for the maintenance branch,
268- # Then redeploy https://demo.dspace.org using that updated image.
269- - name : Redeploy demo.dspace.org (based on maintenace branch)
270- if : ${{ ! matrix.isPr && matrix.arch == 'linux/amd64' && github.ref_name == 'dspace-7_x' }}
271- run : |
272- curl -X POST $REDEPLOY_DEMO_URL
273- env :
274- REDEPLOY_DEMO_URL : ${{ secrets.REDEPLOY_DEMO_URL }}
275-
276- # Merge *-dist digests into a manifest.
277- # This runs after all Docker builds complete above, and it tells hub.docker.com
278- # that these builds should be all included in the manifest for this tag.
279- # (e.g. AMD64 and ARM64 should be listed as options under the same tagged Docker image)
280- dspace-angular-dist_manifest :
281- if : ${{ github.event_name != 'pull_request' }}
282- runs-on : ubuntu-latest
283- needs :
284- - dspace-angular-dist
285- steps :
286- - name : Download digests for -dist builds
287- uses : actions/download-artifact@v3
288- with :
289- name : digests-dist
290- path : /tmp/digests
291-
292- - name : Set up Docker Buildx
293- uses : docker/setup-buildx-action@v3
294-
295- - name : Add Docker metadata for image
296- id : meta_dist
297- uses : docker/metadata-action@v5
298- with :
299- images : ${{ env.REGISTRY_IMAGE }}
300- tags : ${{ env.IMAGE_TAGS }}
301- # As this is a "dist" image, its tags are all suffixed with "-dist". Otherwise, it uses the same
302- # tagging logic as the primary '${{ env.REGISTRY_IMAGE }}' image above.
303- flavor : ${{ env.TAGS_FLAVOR }}
304- suffix=-dist
305-
306- - name : Login to Docker Hub
307- uses : docker/login-action@v3
308- with :
309- username : ${{ secrets.DOCKER_USERNAME }}
310- password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
311-
312- - name : Create manifest list from digests and push
313- working-directory : /tmp/digests
314- run : |
315- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
316- $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
317-
318- - name : Inspect image
319- run : |
320- docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta_dist.outputs.version }}
60+ # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image
61+ uses : DSpace/DSpace/.github/workflows/reusable-docker-build.yml@main
62+ with :
63+ build_id : dspace-angular-dist
64+ image_name : dspace/dspace-angular
65+ dockerfile_path : ./Dockerfile.dist
66+ # As this is a "dist" image, its tags are all suffixed with "-dist". Otherwise, it uses the same
67+ # tagging logic as the primary 'dspace/dspace-angular' image above.
68+ tags_flavor : suffix=-dist
69+ secrets :
70+ DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
71+ DOCKER_ACCESS_TOKEN : ${{ secrets.DOCKER_ACCESS_TOKEN }}
72+ # Enable redeploy of sandbox & demo if the branch for this image matches the deployment branch of
73+ # these sites as specified in reusable-docker-build.xml
74+ REDEPLOY_SANDBOX_URL : ${{ secrets.REDEPLOY_SANDBOX_URL }}
75+ REDEPLOY_DEMO_URL : ${{ secrets.REDEPLOY_DEMO_URL }}
0 commit comments