Skip to content

update spack setup to use the spack official action #26

update spack setup to use the spack official action

update spack setup to use the spack official action #26

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: Setup Spack
uses: spack/setup-spack@v2
with:
ref: release/v0.22
buildcache: true
color: true
path: spack
- name: Generate Dockerfile with Spack
shell: spack-bash {0}
working-directory: spack-env
run: |
spack env activate .
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