Build Apptainer Images #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Apptainer Images | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["Build container images for GHCR and Dockerhub"] | |
| types: | |
| - completed | |
| jobs: | |
| build-apptainer: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: | |
| - r-ver | |
| - bioconductor | |
| - tidyverse | |
| - shiny | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get branch and tag info | |
| id: vars | |
| run: | | |
| BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
| echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| # Convert repository owner to lowercase | |
| OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| echo "owner=$OWNER_LOWER" >> $GITHUB_OUTPUT | |
| - name: Install Apptainer | |
| run: | | |
| # Install Apptainer from official Ubuntu/Debian repository | |
| sudo add-apt-repository -y ppa:apptainer/ppa | |
| sudo apt-get update | |
| sudo apt-get install -y apptainer | |
| - name: Verify Apptainer installation | |
| run: | | |
| apptainer version | |
| apptainer --version | |
| - name: Build Apptainer image from Docker | |
| run: | | |
| DOCKER_IMAGE="ghcr.io/${{ steps.vars.outputs.owner }}/${{ matrix.image }}:${{ steps.vars.outputs.branch }}" | |
| SIF_FILE="${{ matrix.image }}-${{ steps.vars.outputs.branch }}.sif" | |
| echo "Building Apptainer image from: $DOCKER_IMAGE" | |
| echo "Output file: $SIF_FILE" | |
| apptainer build "$SIF_FILE" "docker://$DOCKER_IMAGE" | |
| # Verify the image was created | |
| ls -lh "$SIF_FILE" | |
| apptainer inspect "$SIF_FILE" | |
| - name: Login to GitHub Container Registry | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | apptainer registry login -u ${{ github.actor }} --password-stdin oras://ghcr.io | |
| - name: Push to GitHub Container Registry | |
| run: | | |
| SIF_FILE="${{ matrix.image }}-${{ steps.vars.outputs.branch }}.sif" | |
| DEST="oras://ghcr.io/${{ steps.vars.outputs.owner }}/${{ matrix.image }}-apptainer:${{ steps.vars.outputs.branch }}" | |
| echo "Pushing to: $DEST" | |
| apptainer push "$SIF_FILE" "$DEST" | |
| echo "Successfully pushed Apptainer image for ${{ matrix.image }}" |