88 workflow_call :
99 # Possible Inputs to this reusable job
1010 inputs :
11+ python_version_script_dest :
12+ required : false
13+ default : version.txt
14+ type : string
15+ run_python_version_script :
16+ required : false
17+ default : false
18+ type : boolean
1119 # Build name/id for this Docker build. Used for digest storage to avoid digest overlap between builds.
1220 build_id :
1321 required : true
5866 # e.g. PR against 'main' will use "latest". a PR against 'dspace-7_x' will use 'dspace-7_x'.
5967 IMAGE_TAGS : |
6068 type=raw,value=latest,enable=${{ github.ref_name == github.event.repository.default_branch }}
69+ type=raw,value=${{ github.sha }}
6170 type=ref,event=branch,enable=${{ github.ref_name != github.event.repository.default_branch }}
6271 type=ref,event=tag
63- type=raw,value=${{ (github.event.pull_request.base.ref == github.event.repository.default_branch && 'latest') || github.event.pull_request.base.ref }},enable=${{ github.event_name == 'pull_request' }}
6472 # Define default tag "flavor" for docker/metadata-action per
6573 # https://github.com/docker/metadata-action#flavor-input
6674 # We manage the 'latest' tag ourselves to the 'main' branch (see settings above)
7785 DEPLOY_ARCH : ' linux/amd64'
7886 # Registry used during building of Docker images. (All images are later copied to docker.io registry)
7987 # We use GitHub's Container Registry to avoid aggressive rate limits at DockerHub.
80- DOCKER_BUILD_REGISTRY : ghcr .io
88+ DOCKER_BUILD_REGISTRY : docker .io
8189
8290jobs :
8391 docker-build :
8492
8593 strategy :
8694 matrix :
8795 # Architectures / Platforms for which we will build Docker images
88- arch : [ 'linux/amd64', 'linux/arm64' ]
96+ # arch: [ 'linux/amd64', 'linux/arm64' ]
97+ arch : [ 'linux/amd64' ]
98+ os : [ ubuntu-latest ]
8999 isPr :
90100 - ${{ github.event_name == 'pull_request' }}
91- # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
92- # The below exclude therefore ensures we do NOT build ARM64 for PRs.
93- exclude :
94- - isPr : true
95- arch : linux/arm64
101+ # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
102+ # The below exclude therefore ensures we do NOT build ARM64 for PRs.
103+ # exclude:
104+ # - isPr: true
105+ # os: ubuntu-latest
106+ # arch: linux/arm64
96107
97- # If ARM64, then use the Ubuntu ARM64 runner. Otherwise, use the Ubuntu AMD64 runner
98- runs-on : ${{ matrix.arch == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
108+ runs-on : ${{ matrix.os }}
99109
100110 steps :
101111 # This step converts the slashes in the "arch" matrix values above into dashes & saves to env.ARCH_NAME
@@ -111,15 +121,21 @@ jobs:
111121 - name : Checkout codebase
112122 uses : actions/checkout@v6
113123
124+ - name : Add version
125+ if : ${{ inputs.run_python_version_script }}
126+ run : python scripts/sourceversion.py ${{ github.server_url }}/${{ github.repository }}/actions/runs/ ${{ github.run_id }} > ${{ inputs.python_version_script_dest }}
127+
128+
114129 # https://github.com/docker/login-action
115130 # NOTE: This login occurs for BOTH non-PRs or PRs. PRs *must* also login to access private images from GHCR
116131 # during the build process
117132 - name : Login to ${{ env.DOCKER_BUILD_REGISTRY }}
133+ # Only login if not a PR, as PRs only trigger a Docker build and not a push
134+ if : ${{ ! matrix.isPr }}
118135 uses : docker/login-action@v4
119136 with :
120- registry : ${{ env.DOCKER_BUILD_REGISTRY }}
121- username : ${{ github.repository_owner }}
122- password : ${{ secrets.GITHUB_TOKEN }}
137+ username : ${{ secrets.DOCKER_USERNAME }}
138+ password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
123139
124140 # https://github.com/docker/setup-buildx-action
125141 - name : Setup Docker Buildx
@@ -164,193 +180,4 @@ jobs:
164180 # Use GitHub cache to load cached Docker images and cache the results of this build
165181 # This decreases the number of images we need to fetch from DockerHub
166182 cache-from : type=gha,scope=${{ inputs.build_id }}
167- cache-to : type=gha,scope=${{ inputs.build_id }},mode=min
168-
169- # Export the digest of Docker build locally
170- - name : Export Docker build digest
171- if : ${{ ! matrix.isPr }}
172- run : |
173- mkdir -p /tmp/digests
174- digest="${{ steps.docker_build.outputs.digest }}"
175- touch "/tmp/digests/${digest#sha256:}"
176-
177- # Upload digest to an artifact, so that it can be used in combined manifest below
178- # (The purpose of the combined manifest is to list both amd64 and arm64 builds under same tag)
179- - name : Upload Docker build digest to artifact
180- if : ${{ ! matrix.isPr }}
181- uses : actions/upload-artifact@v7
182- with :
183- name : digests-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
184- path : /tmp/digests/*
185- if-no-files-found : error
186- retention-days : 1
187-
188- # ------------------------------------------------------------------------------
189- # Second, we build the image again in order to store it in a local TAR file.
190- # This TAR of the image is cached/saved as an artifact, so that it can be used
191- # by later jobs to install the brand-new images for automated testing.
192- # This TAR build is performed BOTH for PRs and for branch commits (non-PRs).
193- #
194- # (This approach has the advantage of avoiding having to download the newly built
195- # image from DockerHub or GHCR during automated testing.)
196- #
197- # See the 'docker-deploy' job in docker.yml as an example of where this TAR is used.
198- # -------------------------------------------------------------------------------
199- # Build local image (again) and store in a TAR file in /tmp directory
200- # This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
201- # NOTE: This step cannot be combined with the build above as it's a different type of output.
202- - name : Build and push image to local TAR file
203- if : ${{ matrix.arch == 'linux/amd64'}}
204- uses : docker/build-push-action@v7
205- with :
206- build-contexts : |
207- ${{ inputs.dockerfile_additional_contexts }}
208- context : ${{ inputs.dockerfile_context }}
209- file : ${{ inputs.dockerfile_path }}
210- # Tell DSpace's Docker files to use the build registry instead of DockerHub
211- build-args :
212- DOCKER_REGISTRY=${{ env.DOCKER_BUILD_REGISTRY }}
213- platforms : ${{ matrix.arch }}
214- tags : ${{ steps.meta_build.outputs.tags }}
215- labels : ${{ steps.meta_build.outputs.labels }}
216- # Use GitHub cache to load cached Docker images and cache the results of this build
217- # This decreases the number of images we need to fetch from DockerHub
218- cache-from : type=gha,scope=${{ inputs.build_id }}
219- cache-to : type=gha,scope=${{ inputs.build_id }},mode=min
220- # Export image to a local TAR file
221- outputs : type=docker,dest=/tmp/${{ inputs.build_id }}.tar
222-
223- # Upload the local docker image (in TAR file) to a build Artifact
224- # This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
225- - name : Upload local image TAR to artifact
226- if : ${{ matrix.arch == 'linux/amd64'}}
227- uses : actions/upload-artifact@v7
228- with :
229- name : docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
230- path : /tmp/${{ inputs.build_id }}.tar
231- if-no-files-found : error
232- retention-days : 1
233-
234- # #########################################################################################
235- # Merge Docker digests (from various architectures) into a single manifest.
236- # This runs after all Docker builds complete above. The purpose is to include all builds
237- # under a single manifest for this tag.
238- # (e.g. both linux/amd64 and linux/arm64 should be listed under the same tagged Docker image)
239- # #########################################################################################
240- docker-build_manifest :
241- # Only run if this is NOT a PR
242- if : ${{ github.event_name != 'pull_request' }}
243- runs-on : ubuntu-latest
244- needs :
245- - docker-build
246- steps :
247- - name : Download Docker build digests
248- uses : actions/download-artifact@v8
249- with :
250- path : /tmp/digests
251- # Download digests for both AMD64 and ARM64 into same directory
252- pattern : digests-${{ inputs.build_id }}-*
253- merge-multiple : true
254-
255- - name : Login to ${{ env.DOCKER_BUILD_REGISTRY }}
256- uses : docker/login-action@v4
257- with :
258- registry : ${{ env.DOCKER_BUILD_REGISTRY }}
259- username : ${{ github.repository_owner }}
260- password : ${{ secrets.GITHUB_TOKEN }}
261-
262- - name : Set up Docker Buildx
263- uses : docker/setup-buildx-action@v4
264-
265- - name : Add Docker metadata for image
266- id : meta
267- uses : docker/metadata-action@v6
268- with :
269- images : ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}
270- tags : ${{ env.IMAGE_TAGS }}
271- flavor : ${{ env.TAGS_FLAVOR }}
272-
273- - name : Create manifest list from digests and push to ${{ env.DOCKER_BUILD_REGISTRY }}
274- working-directory : /tmp/digests
275- run : |
276- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
277- $(printf '${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
278-
279- - name : Inspect manifest in ${{ env.DOCKER_BUILD_REGISTRY }}
280- run : |
281- docker buildx imagetools inspect ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
282-
283- # #########################################################################################
284- # Copy images / manifest to DockerHub.
285- # This MUST run after *both* images (AMD64 and ARM64) are built and uploaded to GitHub
286- # Container Registry (GHCR). Attempting to run this in parallel to GHCR builds can result
287- # in a race condition...i.e. the copy to DockerHub may fail if GHCR image has been updated
288- # at the moment when the copy occurs.
289- # #########################################################################################
290- docker-copy_to_dockerhub :
291- # Only run if this is NOT a PR
292- if : ${{ github.event_name != 'pull_request' }}
293- runs-on : ubuntu-latest
294- needs :
295- - docker-build_manifest
296-
297- steps :
298- # 'regctl' is used to more easily copy the image to DockerHub and obtain the digest from DockerHub
299- # See https://github.com/regclient/regclient/blob/main/docs/regctl.md
300- - name : Install regctl for Docker registry tools
301- run : |
302- export REGCTL_VERSION=v0.9.2
303- mkdir -p bin
304- curl -sSLo bin/regctl https://github.com/regclient/regclient/releases/download/${REGCTL_VERSION}/regctl-linux-amd64
305- chmod a+x bin/regctl
306- echo "$(pwd)/bin" >> $GITHUB_PATH
307-
308- # This recreates Docker tags for DockerHub
309- - name : Add Docker metadata for image
310- id : meta_dockerhub
311- uses : docker/metadata-action@v6
312- with :
313- images : ${{ env.IMAGE_NAME }}
314- tags : ${{ env.IMAGE_TAGS }}
315- flavor : ${{ env.TAGS_FLAVOR }}
316-
317- # Login to source registry first, as this is where we are copying *from*
318- - name : Login to ${{ env.DOCKER_BUILD_REGISTRY }}
319- uses : docker/login-action@v4
320- with :
321- registry : ${{ env.DOCKER_BUILD_REGISTRY }}
322- username : ${{ github.repository_owner }}
323- password : ${{ secrets.GITHUB_TOKEN }}
324-
325- # Login to DockerHub, since this is where we are copying *to*
326- - name : Login to DockerHub
327- uses : docker/login-action@v4
328- with :
329- username : ${{ secrets.DOCKER_USERNAME }}
330- password : ${{ secrets.DOCKER_ACCESS_TOKEN }}
331-
332- # Copy the image from source to DockerHub
333- - name : Copy image from ${{ env.DOCKER_BUILD_REGISTRY }} to docker.io
334- run : |
335- regctl image copy ${{ env.DOCKER_BUILD_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta_dockerhub.outputs.version }} docker.io/${{ env.IMAGE_NAME }}:${{ steps.meta_dockerhub.outputs.version }}
336-
337- # --------------------------------------------------------------------
338- # Finally, check whether demo.dspace.org or sandbox.dspace.org need
339- # to be redeployed based on these new DockerHub images.
340- # --------------------------------------------------------------------
341- # If this build is for the branch that Sandbox uses and passed in a REDEPLOY_SANDBOX_URL secret,
342- # Then redeploy https://sandbox.dspace.org
343- - name : Redeploy sandbox.dspace.org (based on main branch)
344- if : |
345- env.REDEPLOY_SANDBOX_URL != '' &&
346- github.ref_name == env.DEPLOY_SANDBOX_BRANCH
347- run : |
348- curl -X POST $REDEPLOY_SANDBOX_URL
349- # If this build is for the branch that Demo uses and passed in a REDEPLOY_DEMO_URL secret,
350- # Then redeploy https://demo.dspace.org
351- - name : Redeploy demo.dspace.org (based on maintenance branch)
352- if : |
353- env.REDEPLOY_DEMO_URL != '' &&
354- github.ref_name == env.DEPLOY_DEMO_BRANCH
355- run : |
356- curl -X POST $REDEPLOY_DEMO_URL
183+ cache-to : type=gha,scope=${{ inputs.build_id }},mode=max
0 commit comments