mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Ensure Docker images built from PRs are stored as artifacts. This allows us to use those new images when testing deployment (in docker-deploy)
This commit is contained in:
22
.github/workflows/docker.yml
vendored
22
.github/workflows/docker.yml
vendored
@@ -157,15 +157,35 @@ jobs:
|
|||||||
if: github.repository == 'dspace/dspace'
|
if: github.repository == 'dspace/dspace'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# Must run after all major images are built
|
# Must run after all major images are built
|
||||||
needs: [dspace-test, dspace-cli, dspace-postgres-pgcrypto, dspace-solr]
|
needs: [dspace, dspace-test, dspace-cli, dspace-postgres-pgcrypto, dspace-solr]
|
||||||
steps:
|
steps:
|
||||||
|
# Checkout our codebase (to get access to Docker Compose scripts)
|
||||||
- name: Checkout codebase
|
- name: Checkout codebase
|
||||||
uses: actions/checkout@v4
|
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'
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
# Download all Docker images (TAR files) into the /tmp/docker directory
|
||||||
|
pattern: docker-image-*
|
||||||
|
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'
|
||||||
|
run: |
|
||||||
|
find /tmp/docker -type f -name "*.tar" -exec docker image load --input "{}" \;
|
||||||
|
docker image ls -a
|
||||||
# Start backend using our compose script in the codebase.
|
# Start backend using our compose script in the codebase.
|
||||||
- name: Start backend in Docker
|
- name: Start backend in Docker
|
||||||
env:
|
env:
|
||||||
# Override defaults dspace.server.url because backend starts at http://127.0.0.1:8080
|
# Override defaults dspace.server.url because backend starts at http://127.0.0.1:8080
|
||||||
dspace__P__server__P__url: http://127.0.0.1:8080/server
|
dspace__P__server__P__url: http://127.0.0.1:8080/server
|
||||||
|
# Force using "pr-testing" version of Docker images. The "pr-testing" tag is a temporary tag that we assign to
|
||||||
|
# all PR-built docker images in reusabe-docker-build.yml
|
||||||
|
DSPACE_VER: pr-testing
|
||||||
run: |
|
run: |
|
||||||
docker compose -f docker-compose.yml up -d
|
docker compose -f docker-compose.yml up -d
|
||||||
sleep 10
|
sleep 10
|
||||||
|
58
.github/workflows/reusable-docker-build.yml
vendored
58
.github/workflows/reusable-docker-build.yml
vendored
@@ -113,6 +113,12 @@ jobs:
|
|||||||
- name: Set up QEMU emulation to build for multiple architectures
|
- name: Set up QEMU emulation to build for multiple architectures
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
#------------------------------------------------------------
|
||||||
|
# Build & deploy steps for new commits to a branch (non-PRs)
|
||||||
|
#
|
||||||
|
# These steps build the images, push to DockerHub, and
|
||||||
|
# (if necessary) redeploy demo/sandbox sites.
|
||||||
|
#------------------------------------------------------------
|
||||||
# https://github.com/docker/login-action
|
# https://github.com/docker/login-action
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
# Only login if not a PR, as PRs only trigger a Docker build and not a push
|
# Only login if not a PR, as PRs only trigger a Docker build and not a push
|
||||||
@@ -125,6 +131,7 @@ jobs:
|
|||||||
# https://github.com/docker/metadata-action
|
# https://github.com/docker/metadata-action
|
||||||
# Get Metadata for docker_build_deps step below
|
# Get Metadata for docker_build_deps step below
|
||||||
- name: Sync metadata (tags, labels) from GitHub to Docker for image
|
- name: Sync metadata (tags, labels) from GitHub to Docker for image
|
||||||
|
if: ${{ ! matrix.isPr }}
|
||||||
id: meta_build
|
id: meta_build
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
@@ -133,7 +140,9 @@ jobs:
|
|||||||
flavor: ${{ env.TAGS_FLAVOR }}
|
flavor: ${{ env.TAGS_FLAVOR }}
|
||||||
|
|
||||||
# https://github.com/docker/build-push-action
|
# https://github.com/docker/build-push-action
|
||||||
- name: Build and push image
|
- name: Build and push image to DockerHub
|
||||||
|
# Only build & push if not a PR
|
||||||
|
if: ${{ ! matrix.isPr }}
|
||||||
id: docker_build
|
id: docker_build
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
@@ -142,9 +151,7 @@ jobs:
|
|||||||
context: ${{ inputs.dockerfile_context }}
|
context: ${{ inputs.dockerfile_context }}
|
||||||
file: ${{ inputs.dockerfile_path }}
|
file: ${{ inputs.dockerfile_path }}
|
||||||
platforms: ${{ matrix.arch }}
|
platforms: ${{ matrix.arch }}
|
||||||
# For pull requests, we run the Docker build (to ensure no PR changes break the build),
|
push: true
|
||||||
# but we ONLY do an image push to DockerHub if it's NOT a PR
|
|
||||||
push: ${{ ! matrix.isPr }}
|
|
||||||
# Use tags / labels provided by 'docker/metadata-action' above
|
# Use tags / labels provided by 'docker/metadata-action' above
|
||||||
tags: ${{ steps.meta_build.outputs.tags }}
|
tags: ${{ steps.meta_build.outputs.tags }}
|
||||||
labels: ${{ steps.meta_build.outputs.labels }}
|
labels: ${{ steps.meta_build.outputs.labels }}
|
||||||
@@ -189,11 +196,54 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
curl -X POST $REDEPLOY_DEMO_URL
|
curl -X POST $REDEPLOY_DEMO_URL
|
||||||
|
|
||||||
|
#-------------------------------------------------------------
|
||||||
|
# Build steps for PRs only
|
||||||
|
#
|
||||||
|
# These steps build the images and store as a build artifact.
|
||||||
|
# These artifacts can then be used by later jobs to run the
|
||||||
|
# brand-new images for automated testing.
|
||||||
|
#--------------------------------------------------------------
|
||||||
|
# Get Metadata for docker_build_deps step below
|
||||||
|
- name: Create metadata (tags, labels) for local Docker image
|
||||||
|
if: matrix.isPr
|
||||||
|
id: meta_build_pr
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.IMAGE_NAME }}
|
||||||
|
# Hardcode to use custom "pr-testing" tag because that will allow us to spin up this PR
|
||||||
|
# for testing in docker.yml
|
||||||
|
tags: pr-testing
|
||||||
|
flavor: ${{ env.TAGS_FLAVOR }}
|
||||||
|
# Build local image and stores in a TAR file in /tmp directory
|
||||||
|
- name: Build and push image to local image
|
||||||
|
if: matrix.isPr
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
build-contexts: |
|
||||||
|
${{ inputs.dockerfile_additional_contexts }}
|
||||||
|
context: ${{ inputs.dockerfile_context }}
|
||||||
|
file: ${{ inputs.dockerfile_path }}
|
||||||
|
platforms: ${{ matrix.arch }}
|
||||||
|
tags: ${{ steps.meta_build_pr.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta_build_pr.outputs.labels }}
|
||||||
|
# Export image to a local TAR file
|
||||||
|
outputs: 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 }}
|
||||||
|
path: /tmp/${{ inputs.build_id }}.tar
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
# Merge Docker digests (from various architectures) into a manifest.
|
# Merge Docker digests (from various architectures) into a manifest.
|
||||||
# This runs after all Docker builds complete above, and it tells hub.docker.com
|
# This runs after all Docker builds complete above, and it tells hub.docker.com
|
||||||
# that these builds should be all included in the manifest for this tag.
|
# that these builds should be all included in the manifest for this tag.
|
||||||
# (e.g. AMD64 and ARM64 should be listed as options under the same tagged Docker image)
|
# (e.g. AMD64 and ARM64 should be listed as options under the same tagged Docker image)
|
||||||
docker-build_manifest:
|
docker-build_manifest:
|
||||||
|
# Only run if this is NOT a PR
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
|
Reference in New Issue
Block a user