|
| 1 | +name: Build Apptainer Images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + workflow_run: |
| 6 | + workflows: ["Build container images for GHCR and Dockerhub"] |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-apptainer: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + image: |
| 18 | + - r-ver |
| 19 | + - bioconductor |
| 20 | + - tidyverse |
| 21 | + - shiny |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Free root space |
| 27 | + uses: almahmoud/free-root-space@main |
| 28 | + with: |
| 29 | + verbose: true |
| 30 | + |
| 31 | + - name: Get branch and tag info |
| 32 | + id: vars |
| 33 | + run: | |
| 34 | + BRANCH_NAME=${GITHUB_REF#refs/heads/} |
| 35 | + echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 36 | + |
| 37 | + # Convert repository owner to lowercase |
| 38 | + OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 39 | + echo "owner=$OWNER_LOWER" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Install Apptainer |
| 42 | + run: | |
| 43 | + # Install Apptainer from official Ubuntu/Debian repository |
| 44 | + sudo add-apt-repository -y ppa:apptainer/ppa |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y apptainer |
| 47 | +
|
| 48 | + - name: Verify Apptainer installation |
| 49 | + run: | |
| 50 | + apptainer version |
| 51 | + apptainer --version |
| 52 | +
|
| 53 | + - name: Build Apptainer image from Docker |
| 54 | + run: | |
| 55 | + DOCKER_IMAGE="ghcr.io/${{ steps.vars.outputs.owner }}/${{ matrix.image }}:${{ steps.vars.outputs.branch }}" |
| 56 | + SIF_FILE="${{ matrix.image }}-${{ steps.vars.outputs.branch }}.sif" |
| 57 | + |
| 58 | + echo "Building Apptainer image from: $DOCKER_IMAGE" |
| 59 | + echo "Output file: $SIF_FILE" |
| 60 | + |
| 61 | + apptainer build "$SIF_FILE" "docker://$DOCKER_IMAGE" |
| 62 | + |
| 63 | + # Verify the image was created |
| 64 | + ls -lh "$SIF_FILE" |
| 65 | + apptainer inspect "$SIF_FILE" |
| 66 | +
|
| 67 | + - name: Login to GitHub Container Registry |
| 68 | + run: | |
| 69 | + echo "${{ secrets.GITHUB_TOKEN }}" | apptainer remote login -u ${{ github.actor }} --password-stdin oras://ghcr.io |
| 70 | +
|
| 71 | + - name: Push to GitHub Container Registry |
| 72 | + run: | |
| 73 | + SIF_FILE="${{ matrix.image }}-${{ steps.vars.outputs.branch }}.sif" |
| 74 | + DEST="oras://ghcr.io/${{ steps.vars.outputs.owner }}/${{ matrix.image }}-apptainer:${{ steps.vars.outputs.branch }}" |
| 75 | + |
| 76 | + echo "Pushing to: $DEST" |
| 77 | + apptainer push "$SIF_FILE" "$DEST" |
| 78 | + |
| 79 | + echo "Successfully pushed Apptainer image for ${{ matrix.image }}" |
0 commit comments