Singularity Build (within a docker instance) #9
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: Singularity Build (within a docker instance) | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - 'v*' | |
| # # Do the builds on all pull requests (to test them) | |
| # pull_request: | |
| jobs: | |
| #changes: | |
| # name: "Changed Singularity Recipes" | |
| # runs-on: ubuntu-latest | |
| # outputs: | |
| # changed_file: ${{ steps.files.outputs.added_modified }} | |
| # steps: | |
| # - id: files | |
| # uses: jitterbit/get-changed-files@d06c756e3609dd3dd5d302dde8d1339af3f790f2 | |
| # with: | |
| # format: 'json' | |
| gather-metadata: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| # | |
| steps: | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v6.0.0 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=schedule | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=ref,event=pr | |
| type=sha | |
| # type=semver,pattern={{version}} | |
| # type=semver,pattern={{major}}.{{minor}} | |
| build-test-containers: | |
| needs: | |
| - gather-metadata | |
| # - changes | |
| runs-on: ubuntu-latest | |
| # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| strategy: | |
| # Keep going on other deployments if anything bloops | |
| fail-fast: false | |
| matrix: | |
| # changed_file: ${{ fromJson(needs.changes.outputs.changed_file) }} | |
| changed_file: [ 'installation/Singularity.def' ] | |
| singularity_version: | |
| - '4.3.1' | |
| container: | |
| image: quay.io/singularity/singularity:v${{ matrix.singularity_version }} | |
| options: --privileged | |
| name: Check ${{ matrix.changed_file }} | |
| steps: | |
| - name: Check out code for the container builds | |
| uses: actions/checkout@v6 | |
| - name: Continue if Singularity Recipe | |
| run: | | |
| # Continue if we have a changed Singularity recipe | |
| case "${{ matrix.changed_file }}" in | |
| */Singularity*def) | |
| echo "keepgoing=true" >> "$GITHUB_ENV" | |
| ;; | |
| esac | |
| - name: Build Container | |
| if: env.keepgoing == 'true' | |
| env: | |
| recipe: ${{ matrix.changed_file }} | |
| run: | | |
| ls | |
| if [ -f "$recipe" ]; then | |
| sudo -E singularity build --build-arg treecript_checkout=${{ github.sha }} container.sif "$recipe" | |
| tag="${recipe/Singularity\./}" | |
| if [ "$tag" == "def" ]; then | |
| tag=latest | |
| fi | |
| # Build the container and name by tag | |
| echo "Tag is $tag." | |
| echo "tag=$tag" >> "$GITHUB_ENV" | |
| else | |
| echo "$recipe is not found." | |
| echo "Present working directory: $PWD" | |
| ls | |
| fi | |
| - name: Login and Deploy Container | |
| if: (github.event_name != 'pull_request') && ( env.keepgoing == 'true' ) | |
| shell: /bin/bash {0} | |
| run: | | |
| singularity registry login -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}" oras://ghcr.io | |
| declare -a tags=( ${{ needs.gather-metadata.outputs.tags }} ) | |
| for tag in "${tags[@]}" ; do | |
| singularity push container.sif "oras://ghcr.io/${GITHUB_REPOSITORY}:${tag#*:}" | |
| done |