Skip to content

Commit

Permalink
Attempt to separate builds into stages and skip base image build if i…
Browse files Browse the repository at this point in the history
…t exists.
  • Loading branch information
cameronrutherford committed Aug 6, 2024
1 parent f4b7f88 commit 641ee74
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions .github/workflows/spack_cpu_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ env:
on: [pull_request]

jobs:
base_image_build:
checkout_code:
name: Checkout code
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read

name: Build Custom Base Image
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -28,6 +26,46 @@ jobs:
# Also need to change build script to use spack from base image
submodules: true

check_for_image:
name: Check for image
runs-on: docker.io/kfox1111/misc:skopeo
permissions:
packages: read
steps:
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
# This isn't necessary for skopeo, but spack will need this to push later...
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}

# 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
mkdir -p /etc/gitlab-runner/certs
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
base_image_build:
if: ${{ env.IMAGE_EXISTS == false }}
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read

name: Build Custom Base Image

steps:
# Need to build custom base image with gfortran
- name: Create Dockerfile heredoc
run: |
Expand All @@ -47,14 +85,6 @@ jobs:
&& rm -rf /var/lib/apt/lists/*
EOF
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
Expand Down

0 comments on commit 641ee74

Please sign in to comment.