Skip to content

Commit

Permalink
Add check for existing base image to speedup pipelines.
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronrutherford committed Sep 3, 2024
1 parent 7767511 commit 5f0ec6f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/spack_cpu_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,29 @@ jobs:
# Also need to change build script to use spack from base image
submodules: true

# No GHCR base image with skopeo, so this will do...
- name: "Set up skopeo"
uses: warjiang/[email protected]
with:
version: latest

# Use skopeo to check for image for convenience
- name: Check for existing base images
run: |
set -e
CONTAINER_TAG=${{ env.BASE_VERSION }}
OCI_URL="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }}"
echo Checking for CONTAINER_TAG $CONTAINER_TAG
skopeo inspect \
docker://$OCI_URL \
--raw \
--creds "${{ env.USERNAME }}:${{ secrets.GITHUB_TOKEN }}" \
> /dev/null && echo "Image already exists. Please bump version." && exit 0
echo "IMAGE_EXISTS=false" >> $GITHUB_ENV
# Need to build custom base image with gfortran
- name: Create Dockerfile heredoc
if: ${{ env.IMAGE_EXISTS == 'false' }}
run: |
cat << EOF > Dockerfile
FROM ubuntu:24.04
Expand Down Expand Up @@ -61,13 +82,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
if: ${{ env.IMAGE_EXISTS == 'false' }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: org.opencontainers.image.version=${{ env.BASE_VERSION }}

- name: Build and push Docker base image
if: ${{ env.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
context: .
Expand Down

0 comments on commit 5f0ec6f

Please sign in to comment.