Skip to content

Updated workflow

Updated workflow #21

Workflow file for this run

name: Apptainer Build
on:
push:
tags:
- "*@*"
jobs:
build-and-push-image:
runs-on: ubuntu-latest
name: Build Apptainer image
permissions:
contents: read
packages: write
steps:
- name: Set Apptainer download version
run: |
APPTAINER_VERSION=1.2.5
echo "APPTAINER_VERSION=$APPTAINER_VERSION" >> $GITHUB_ENV
SETUP_DOWNLOADS_DIR=.setup-downloads
echo "SETUP_DOWNLOADS_DIR=$SETUP_DOWNLOADS_DIR" >> $GITHUB_ENV
mkdir -p "${SETUP_DOWNLOADS_DIR}"
- name: Download Apptainer
run: |
set -eux
[ -r "${SETUP_DOWNLOADS_DIR}/apptainer-${APPTAINER_VERSION}.deb" ] || curl -o "${SETUP_DOWNLOADS_DIR}/apptainer-${APPTAINER_VERSION}.deb" -L https://github.com/apptainer/apptainer/releases/download/v${APPTAINER_VERSION}/apptainer_${APPTAINER_VERSION}_amd64.deb
- name: Install Apptainer
run: |
set -eux
sudo apt install -y "./${SETUP_DOWNLOADS_DIR}/apptainer-${APPTAINER_VERSION}.deb"
- name: Check out code for the container build
uses: actions/checkout@v4
- name: Build Container
run: |
set -eux
apptainer build --fix-perms --force container.sif Singularity
echo "Container built successfully" >&2
echo "Container size:" >&2
du -h container.sif >&2
echo "Container labels:" >&2
apptainer inspect container.sif >&2
- name: Push Container
run: |
set -eux
IMAGE_TAG=${{ github.ref_name }}
IMAGE_TAG=${IMAGE_TAG:-latest}
IMAGE_TAG="${IMAGE_TAG##*@}"
IMAGE_NAME=${{ github.ref_name }}
IMAGE_NAME="${IMAGE_NAME%%@*}"
DST="oras://ghcr.io/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG}"
echo "Pushing to \"${DST}\"" >&2
apptainer remote login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io
apptainer push -U container.sif "${DST}"
echo "Done" >&2