Skip to content

Commit

Permalink
Merge pull request DSpace#10079 from tdonohue/use_local_images_for_de…
Browse files Browse the repository at this point in the history
…ploy

[GitHub Actions] Ensure we always do a test Docker deployment from the locally created images
  • Loading branch information
tdonohue authored Dec 5, 2024
2 parents 72d36a3 + b035ea9 commit 560dae4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
24 changes: 11 additions & 13 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}

########################################################################
# Test Deployment via Docker to ensure images are working properly
########################################################################
#################################################################################
# Test Deployment via Docker to ensure newly built images are working properly
#################################################################################
docker-deploy:
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace'
if: github.repository == 'dspace/dspace'
Expand All @@ -172,25 +172,23 @@ jobs:
swordv2__D__server__P__enabled: true
# If this is a PR, force using "pr-testing" version of all Docker images. Otherwise, if on main branch, use the
# "latest" tag. Otherwise, use the branch name. NOTE: the "pr-testing" tag is a temporary tag that we assign to
# all PR-built docker images in reusabe-docker-build.yml
# all PR-built docker images in reusable-docker-build.yml
DSPACE_VER: ${{ (github.event_name == 'pull_request' && 'pr-testing') || (github.ref_name == github.event.repository.default_branch && 'latest') || github.ref_name }}
steps:
# Checkout our codebase (to get access to Docker Compose scripts)
- name: Checkout codebase
uses: actions/checkout@v4
# For PRs, download Docker image artifacts (built by reusable-docker-build.yml for all PRs)
- name: Download Docker image artifacts (for PRs)
if: github.event_name == 'pull_request'
# Download Docker image artifacts (which were just built by reusable-docker-build.yml)
- name: Download Docker image artifacts
uses: actions/download-artifact@v4
with:
# Download all Docker images (TAR files) into the /tmp/docker directory
pattern: docker-image-*
# Download all amd64 Docker images (TAR files) into the /tmp/docker directory
pattern: docker-image-*-linux-amd64
path: /tmp/docker
merge-multiple: true
# For PRs, load each of the images into Docker by calling "docker image load" for each.
# This ensures we are using the images built from this PR & not the prior versions on DockerHub
- name: Load all downloaded Docker images (for PRs)
if: github.event_name == 'pull_request'
# Load each of the images into Docker by calling "docker image load" for each.
# This ensures we are using the images just built & not any prior versions on DockerHub
- name: Load all downloaded Docker images
run: |
find /tmp/docker -type f -name "*.tar" -exec docker image load --input "{}" \;
docker image ls -a
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/reusable-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
#------------------------------------------------------------
# https://github.com/docker/metadata-action
# Get Metadata for docker_build_deps step below
- name: Sync metadata (tags, labels) from GitHub to Docker for image
- name: Extract metadata (tags, labels) from GitHub for Docker image
if: ${{ ! matrix.isPr }}
id: meta_build
uses: docker/metadata-action@v5
Expand All @@ -151,10 +151,23 @@ jobs:
context: ${{ inputs.dockerfile_context }}
file: ${{ inputs.dockerfile_path }}
platforms: ${{ matrix.arch }}
push: true
# Use tags / labels provided by 'docker/metadata-action' above
tags: ${{ steps.meta_build.outputs.tags }}
labels: ${{ steps.meta_build.outputs.labels }}
# Export image to both Docker registry & to a local TAR file
outputs: |
registry
type=docker,dest=/tmp/${{ inputs.build_id }}.tar
# Upload the local docker image (in TAR file) to a build Artifact
- name: Upload local image to artifact
if: ${{ ! matrix.isPr }}
uses: actions/upload-artifact@v4
with:
name: docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
path: /tmp/${{ inputs.build_id }}.tar
if-no-files-found: error
retention-days: 1

# Export the digest of Docker build locally (for non PRs only)
- name: Export Docker build digest
Expand Down Expand Up @@ -204,7 +217,7 @@ jobs:
# brand-new images for automated testing.
#--------------------------------------------------------------
# Get Metadata for docker_build_deps step below
- name: Create metadata (tags, labels) for local Docker image
- name: Extract metadata (tags, labels) for local Docker image
if: matrix.isPr
id: meta_build_pr
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -233,7 +246,7 @@ jobs:
if: matrix.isPr
uses: actions/upload-artifact@v4
with:
name: docker-image-${{ inputs.build_id }}
name: docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
path: /tmp/${{ inputs.build_id }}.tar
if-no-files-found: error
retention-days: 1
Expand Down

0 comments on commit 560dae4

Please sign in to comment.