mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Refactor to use the same local TAR image build for PRs and non-PRs. These TAR images act as a cache for our current build.
This commit is contained in:
4
.github/workflows/docker.yml
vendored
4
.github/workflows/docker.yml
vendored
@@ -170,10 +170,6 @@ jobs:
|
|||||||
signposting__P__enabled: true
|
signposting__P__enabled: true
|
||||||
sword__D__server__P__enabled: true
|
sword__D__server__P__enabled: true
|
||||||
swordv2__D__server__P__enabled: true
|
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 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:
|
steps:
|
||||||
# Checkout our codebase (to get access to Docker Compose scripts)
|
# Checkout our codebase (to get access to Docker Compose scripts)
|
||||||
- name: Checkout codebase
|
- name: Checkout codebase
|
||||||
|
76
.github/workflows/reusable-docker-build.yml
vendored
76
.github/workflows/reusable-docker-build.yml
vendored
@@ -122,16 +122,9 @@ jobs:
|
|||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-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/metadata-action
|
# https://github.com/docker/metadata-action
|
||||||
# Get Metadata for docker_build_deps step below
|
# Extract metadata used for Docker images in all build steps below
|
||||||
- name: Extract metadata (tags, labels) from GitHub for Docker image
|
- name: Extract metadata (tags, labels) from GitHub for Docker image
|
||||||
if: ${{ ! matrix.isPr }}
|
|
||||||
id: meta_build
|
id: meta_build
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
@@ -139,6 +132,12 @@ jobs:
|
|||||||
tags: ${{ env.IMAGE_TAGS }}
|
tags: ${{ env.IMAGE_TAGS }}
|
||||||
flavor: ${{ env.TAGS_FLAVOR }}
|
flavor: ${{ env.TAGS_FLAVOR }}
|
||||||
|
|
||||||
|
#------------------------------------------------------------
|
||||||
|
# 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/build-push-action
|
# https://github.com/docker/build-push-action
|
||||||
- name: Build and push image to DockerHub
|
- name: Build and push image to DockerHub
|
||||||
# Only build & push if not a PR
|
# Only build & push if not a PR
|
||||||
@@ -178,32 +177,6 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
# Build local image (again) and store in a TAR file in /tmp directory
|
|
||||||
# NOTE: This cannot be combined with push to DockerHub registry above as it's a different type of output.
|
|
||||||
- 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.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta_build.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 }}-${{ env.ARCH_NAME }}
|
|
||||||
path: /tmp/${{ inputs.build_id }}.tar
|
|
||||||
if-no-files-found: error
|
|
||||||
retention-days: 1
|
|
||||||
|
|
||||||
# If this build is NOT a PR and passed in a REDEPLOY_SANDBOX_URL secret,
|
# If this build is NOT a PR and passed in a REDEPLOY_SANDBOX_URL secret,
|
||||||
# Then redeploy https://sandbox.dspace.org if this build is for our deployment architecture and 'main' branch.
|
# Then redeploy https://sandbox.dspace.org if this build is for our deployment architecture and 'main' branch.
|
||||||
- name: Redeploy sandbox.dspace.org (based on main branch)
|
- name: Redeploy sandbox.dspace.org (based on main branch)
|
||||||
@@ -227,27 +200,19 @@ jobs:
|
|||||||
curl -X POST $REDEPLOY_DEMO_URL
|
curl -X POST $REDEPLOY_DEMO_URL
|
||||||
|
|
||||||
#-------------------------------------------------------------
|
#-------------------------------------------------------------
|
||||||
# Build steps for PRs only
|
# Shared Build steps.
|
||||||
|
# These are used for PRs as well as new commits to a branch (non-PRs)
|
||||||
#
|
#
|
||||||
# These steps build the images and store as a build artifact.
|
# These steps build the images and cache/store as a build artifact.
|
||||||
# These artifacts can then be used by later jobs to run the
|
# These artifacts can then be used by later jobs to install the
|
||||||
# brand-new images for automated testing.
|
# brand-new images for automated testing. For non-PRs, this cache is
|
||||||
|
# also used to avoid pulling the images we just built from DockerHub.
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
# Get Metadata for docker_build_deps step below
|
|
||||||
- name: Extract 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
|
# Build local image (again) and store in a TAR file in /tmp directory
|
||||||
- name: Build and push image to local image
|
# NOTE: This build is run for both PRs and non-PRs as it's used to "cache" our built images as artifacts.
|
||||||
if: matrix.isPr
|
# NOTE #2: This cannot be combined with push to DockerHub registry above as it's a different type of output.
|
||||||
|
- name: Build and push image to local TAR file
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
build-contexts: |
|
build-contexts: |
|
||||||
@@ -255,8 +220,8 @@ jobs:
|
|||||||
context: ${{ inputs.dockerfile_context }}
|
context: ${{ inputs.dockerfile_context }}
|
||||||
file: ${{ inputs.dockerfile_path }}
|
file: ${{ inputs.dockerfile_path }}
|
||||||
platforms: ${{ matrix.arch }}
|
platforms: ${{ matrix.arch }}
|
||||||
tags: ${{ steps.meta_build_pr.outputs.tags }}
|
tags: ${{ steps.meta_build.outputs.tags }}
|
||||||
labels: ${{ steps.meta_build_pr.outputs.labels }}
|
labels: ${{ steps.meta_build.outputs.labels }}
|
||||||
# Use GitHub cache to load cached Docker images and cache the results of this build
|
# Use GitHub cache to load cached Docker images and cache the results of this build
|
||||||
# This decreases the number of images we need to fetch from DockerHub
|
# This decreases the number of images we need to fetch from DockerHub
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
@@ -265,8 +230,7 @@ jobs:
|
|||||||
outputs: type=docker,dest=/tmp/${{ inputs.build_id }}.tar
|
outputs: type=docker,dest=/tmp/${{ inputs.build_id }}.tar
|
||||||
|
|
||||||
# Upload the local docker image (in TAR file) to a build Artifact
|
# Upload the local docker image (in TAR file) to a build Artifact
|
||||||
- name: Upload local image to artifact
|
- name: Upload local image TAR to artifact
|
||||||
if: matrix.isPr
|
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
|
name: docker-image-${{ inputs.build_id }}-${{ env.ARCH_NAME }}
|
||||||
|
Reference in New Issue
Block a user