From 641ee748c766962fcb5ca6323dab8d12e35658c3 Mon Sep 17 00:00:00 2001 From: "Rutherford, Cameron" Date: Tue, 6 Aug 2024 16:12:32 -0400 Subject: [PATCH] Attempt to separate builds into stages and skip base image build if it exists. --- .github/workflows/spack_cpu_build.yaml | 54 ++++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/.github/workflows/spack_cpu_build.yaml b/.github/workflows/spack_cpu_build.yaml index 524fea5e..3f1dc24e 100644 --- a/.github/workflows/spack_cpu_build.yaml +++ b/.github/workflows/spack_cpu_build.yaml @@ -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 @@ -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: | @@ -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