initial commit #1
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 Container | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['*'] | |
| env: | |
| REGISTRY: ghcr.io | |
| # Hardcoded container name here | |
| IMAGE_NAME: ${{ github.repository_owner }}/s3cmdc | |
| jobs: | |
| build-apptainer: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract SCM versions | |
| id: scm | |
| run: | | |
| RAW_VERSION=$(pipx run hatch version) | |
| CLEAN_VERSION=$(echo $RAW_VERSION | tr '+' '-') | |
| echo "tag_version=$CLEAN_VERSION" >> $GITHUB_OUTPUT | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| # The conditional directive is removed to force application | |
| type=raw,value=latest | |
| type=sha,format=short | |
| # Use the SANITIZED version for the registry tag | |
| type=raw,value=${{ steps.scm.outputs.tag_version }} | |
| - name: Setup Apptainer | |
| uses: eWaterCycle/setup-apptainer@v2 | |
| with: | |
| apptainer-version: 1.3.1 | |
| - name: Build Apptainer image | |
| run: | | |
| sudo apptainer build container.sif containers/s3cmdc.def | |
| - name: Push Apptainer image to GHCR | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | apptainer registry login -u ${{ github.actor }} --password-stdin oras://${{ env.REGISTRY }} | |
| # Clean way to loop through tags even if they have weird spacing | |
| TAGS="${{ steps.meta.outputs.tags }}" | |
| for TAG in $TAGS; do | |
| echo "Pushing to oras://$TAG" | |
| apptainer push container.sif "oras://$TAG" | |
| done |