@@ -122,8 +122,13 @@ jobs:
122122 password : ${{ secrets.GITHUB_TOKEN }}
123123
124124 # https://github.com/docker/setup-buildx-action
125+ # For PR builds of images that depend on dspace-dependencies (dspace-prod, dspace-test, dspace-cli),
126+ # use the 'docker' driver so buildx can access images loaded into the local Docker daemon.
127+ # For all other builds, use the default 'docker-container' driver.
125128 - name : Setup Docker Buildx
126129 uses : docker/setup-buildx-action@v3
130+ with :
131+ driver : ${{ (matrix.isPr && (inputs.build_id == 'dspace-prod' || inputs.build_id == 'dspace-test' || inputs.build_id == 'dspace-cli')) && 'docker' || 'docker-container' }}
127132
128133 # https://github.com/docker/metadata-action
129134 # Extract metadata used for Docker images in all build steps below
@@ -135,6 +140,29 @@ jobs:
135140 tags : ${{ env.IMAGE_TAGS }}
136141 flavor : ${{ env.TAGS_FLAVOR }}
137142
143+ # --------------------------------------------------------------------
144+ # For PR builds that depend on dspace-dependencies (dspace-prod, dspace-cli,
145+ # dspace-test), download and load the dspace-dependencies image from the
146+ # artifact uploaded by the dspace-dependencies job. This ensures that
147+ # PR builds use the freshly built dependencies image rather than pulling
148+ # an outdated version from the registry.
149+ # NOTE: Only these three build_ids use dspace-dependencies as a base image.
150+ # Other builds (dspace-solr, dspace-postgres-loadsql) have independent Dockerfiles.
151+ # --------------------------------------------------------------------
152+ # https://github.com/actions/download-artifact
153+ - name : Download dspace-dependencies image artifact
154+ if : ${{ matrix.isPr && (inputs.build_id == 'dspace-prod' || inputs.build_id == 'dspace-test' || inputs.build_id == 'dspace-cli') && matrix.arch == 'linux/amd64' }}
155+ uses : actions/download-artifact@v4
156+ with :
157+ name : docker-image-dspace-dependencies-linux-amd64
158+ path : /tmp/docker
159+
160+ - name : Load dspace-dependencies image into Docker
161+ if : ${{ matrix.isPr && (inputs.build_id == 'dspace-prod' || inputs.build_id == 'dspace-test' || inputs.build_id == 'dspace-cli') && matrix.arch == 'linux/amd64' }}
162+ run : |
163+ docker image load --input /tmp/docker/dspace-dependencies.tar
164+ docker image ls | grep dspace-dependencies || true
165+
138166 # --------------------------------------------------------------------
139167 # First, for all branch commits (non-PRs) we build the image & upload
140168 # to GitHub Container Registry (GHCR). After uploading the image
@@ -199,27 +227,53 @@ jobs:
199227 # Build local image (again) and store in a TAR file in /tmp directory
200228 # This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
201229 # 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'}}
230+ # For non-PR builds OR builds that don't depend on dspace-dependencies, use docker-container driver
231+ # with direct tarball export. This includes: dspace-dependencies, dspace-solr, dspace-postgres-loadsql
232+ - name : Build and push image to local TAR file (docker-container driver)
233+ if : ${{ matrix.arch == 'linux/amd64' && (!matrix.isPr || (inputs.build_id != 'dspace-prod' && inputs.build_id != 'dspace-test' && inputs.build_id != 'dspace-cli')) }}
204234 uses : docker/build-push-action@v5
205235 with :
206236 build-contexts : |
207237 ${{ inputs.dockerfile_additional_contexts }}
208238 context : ${{ inputs.dockerfile_context }}
209239 file : ${{ inputs.dockerfile_path }}
210- # Tell DSpace's Docker files to use the build registry instead of DockerHub
240+ # Use GHCR as build registry to avoid DockerHub rate limits
211241 build-args :
212242 DOCKER_REGISTRY=${{ env.DOCKER_BUILD_REGISTRY }}
213243 platforms : ${{ matrix.arch }}
214244 tags : ${{ steps.meta_build.outputs.tags }}
215245 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
246+ # Cache Docker layers in GitHub Actions cache to speed up builds
247+ # and reduce pulls from DockerHub
218248 cache-from : type=gha,scope=${{ inputs.build_id }}
219249 cache-to : type=gha,scope=${{ inputs.build_id }},mode=min
220- # Export image to a local TAR file
250+ # Export to TAR for use in automated testing jobs
221251 outputs : type=docker,dest=/tmp/${{ inputs.build_id }}.tar
222252
253+ # For PR builds of images that depend on dspace-dependencies (dspace-prod, dspace-cli, dspace-test),
254+ # use docker driver which can access the locally loaded dspace-dependencies image.
255+ # The docker driver doesn't support tarball export, so we use 'load: true' and then 'docker save'.
256+ - name : Build image (docker driver for local dependencies access)
257+ if : ${{ matrix.arch == 'linux/amd64' && matrix.isPr && (inputs.build_id == 'dspace-prod' || inputs.build_id == 'dspace-test' || inputs.build_id == 'dspace-cli') }}
258+ uses : docker/build-push-action@v5
259+ with :
260+ build-contexts : |
261+ ${{ inputs.dockerfile_additional_contexts }}
262+ context : ${{ inputs.dockerfile_context }}
263+ file : ${{ inputs.dockerfile_path }}
264+ # Use GHCR as build registry to avoid DockerHub rate limits
265+ build-args :
266+ DOCKER_REGISTRY=${{ env.DOCKER_BUILD_REGISTRY }}
267+ tags : ${{ steps.meta_build.outputs.tags }}
268+ labels : ${{ steps.meta_build.outputs.labels }}
269+ # Load into local Docker daemon (docker driver doesn't support direct TAR export)
270+ load : true
271+
272+ - name : Save image to TAR file (for docker driver builds)
273+ if : ${{ matrix.arch == 'linux/amd64' && matrix.isPr && (inputs.build_id == 'dspace-prod' || inputs.build_id == 'dspace-test' || inputs.build_id == 'dspace-cli') }}
274+ run : |
275+ docker save -o /tmp/${{ inputs.build_id }}.tar ${{ steps.meta_build.outputs.tags }}
276+
223277 # Upload the local docker image (in TAR file) to a build Artifact
224278 # This step is only done for AMD64, as that's the only image we use in our automated testing (at this time).
225279 - name : Upload local image TAR to artifact
0 commit comments