Skip to content

Build and Push Spack Container #22

Build and Push Spack Container

Build and Push Spack Container #22

name: Build and Push Spack Container
on:
workflow_dispatch:
pull_request:
branches: [main]
paths:
- 'spack-env/spack.yaml'
- '.github/workflows/spack-container-build.yml'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Spack
run: |
git clone --depth 1 --branch v0.23.0 https://github.com/spack/spack.git
echo "${GITHUB_WORKSPACE}/spack/bin" >> $GITHUB_PATH
- name: Generate Dockerfile with Spack
run: |
cd spack-env
../spack/bin/spack containerize > Dockerfile
# Update the Dockerfile for human review for debugging if necessary
- name: Upload generated Dockerfile
uses: actions/upload-artifact@v4
with:
name: spack-dockerfile
path: spack-env/Dockerfile
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Lowercase the github.repository name
# This step addresses https://github.com/orgs/community/discussions/25768
run: |
echo "REPO_NAME=`echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV
# Consider changing the push step to a load and test before pushing to the registry
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: ./spack-env/
push: true
tags: ghcr.io/${{ env.REPO_NAME }}/spack-env:latest
cache-from: type=gha
cache-to: type=gha,mode=max