11name : Docker
22
3- # This workflow uses actions that are not certified by GitHub.
4- # They are provided by a third-party and are governed by
5- # separate terms of service, privacy policy, and support
6- # documentation.
7-
83on :
94 push :
10- # Publish semver tags as releases.
11- tags : [ 'v*.*.*' ]
5+ tags : ['v*.*.*']
126
137env :
14- # Use docker.io for Docker Hub if empty
158 REGISTRY : ghcr.io
16- # github.repository as <account>/<repo>
179 IMAGE_NAME : ${{ github.repository }}
1810
19-
2011jobs :
2112 build :
22-
23- runs-on : ubuntu-latest
13+ runs-on : ${{ matrix.runner }}
2414 permissions :
2515 contents : read
2616 packages : write
27- # This is used to complete the identity challenge
28- # with sigstore/fulcio when running outside of PRs.
29- id-token : write
30-
17+ strategy :
18+ fail-fast : false
19+ matrix :
20+ include :
21+ - platform : linux/amd64
22+ runner : ubuntu-latest
23+ - platform : linux/arm64
24+ runner : ubuntu-24.04-arm
3125 steps :
3226 - name : Checkout repository
3327 uses : actions/checkout@v4
3428
3529 - name : Clean up disk space
3630 uses : jlumbroso/free-disk-space@main
3731
38- # Install the cosign tool except on PR
39- # https://github.com/sigstore/cosign-installer
40- - name : Install cosign
41- if : github.event_name != 'pull_request'
42- uses : sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
43- with :
44- cosign-release : ' v2.2.4'
45-
46- # Set up BuildKit Docker container builder to be able to build
47- # multi-platform images and export cache
48- # https://github.com/docker/setup-buildx-action
4932 - name : Set up Docker Buildx
50- uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
33+ uses : docker/setup-buildx-action@v3
5134
52- # Login against a Docker registry except on PR
53- # https://github.com/docker/login-action
54- - name : Log into registry ${{ env.REGISTRY }}
55- if : github.event_name != 'pull_request'
56- uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
35+ - name : Log into registry
36+ uses : docker/login-action@v3
5737 with :
5838 registry : ${{ env.REGISTRY }}
5939 username : ${{ github.actor }}
6040 password : ${{ secrets.GITHUB_TOKEN }}
6141
62- # Extract metadata (tags, labels) for Docker
63- # https://github.com/docker/metadata-action
42+ - name : Repository to lowercase
43+ id : lower-repo
44+ run : echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
45+
6446 - name : Extract Docker metadata
6547 id : meta
66- uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
48+ uses : docker/metadata-action@v5
6749 with :
68- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+ images : ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}
6951
70- # Build and push Docker image with Buildx (don't push on PR)
71- # https://github.com/docker/build-push-action
72- - name : Build and push Docker image
73- id : build-and-push
74- uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
52+ - name : Prepare platform pair
53+ id : platform
54+ run : echo "pair=${platform//\//-}" >> $GITHUB_OUTPUT
55+ env :
56+ platform : ${{ matrix.platform }}
57+
58+ - name : Build and push by digest
59+ id : build
60+ uses : docker/build-push-action@v5
7561 with :
7662 context : .
77- push : ${{ github.event_name != 'pull_request' }}
78- tags : ${{ steps.meta.outputs.tags }}
79- labels : ${{ steps.meta .outputs.labels }}
80- cache-from : type=gha
81- cache-to : type=gha,mode=max
63+ file : .devcontainer/Dockerfile
64+ platforms : ${{ matrix.platform }}
65+ outputs : type=image,name= ${{ env.REGISTRY }}/${{ steps.lower-repo .outputs.repository }},push-by-digest=true,name-canonical=true,push=true
66+ cache-from : type=gha,scope=${{ steps.platform.outputs.pair }}
67+ cache-to : type=gha,mode=max,scope=${{ steps.platform.outputs.pair }}
8268
83- - name : Free disk space after Docker build
69+ - name : Export digest
8470 run : |
85- docker buildx ls --format '{{.Name}}' | grep -v default | xargs -I {} docker buildx rm {} 2>/dev/null || true
86- docker system prune -af --volumes
87- docker builder prune -af
71+ mkdir -p /tmp/digests
72+ digest="${{ steps.build.outputs.digest }}"
73+ touch "/tmp/digests/${digest#sha256:}"
74+
75+ - name : Upload digest
76+ uses : actions/upload-artifact@v4
77+ with :
78+ name : digest-${{ steps.platform.outputs.pair }}
79+ path : /tmp/digests/*
80+ if-no-files-found : error
81+ retention-days : 1
82+
83+ merge :
84+ runs-on : ubuntu-latest
85+ needs : build
86+ permissions :
87+ contents : read
88+ packages : write
89+ steps :
90+ - name : Download digests
91+ uses : actions/download-artifact@v4
92+ with :
93+ path : /tmp/digests
94+ pattern : digest-*
95+ merge-multiple : true
96+
97+ - name : Log into registry
98+ uses : docker/login-action@v3
99+ with :
100+ registry : ${{ env.REGISTRY }}
101+ username : ${{ github.actor }}
102+ password : ${{ secrets.GITHUB_TOKEN }}
88103
89- rm -rf ~/.docker/buildx || true
90- rm -rf /tmp/docker-actions-toolkit-*/* 2>/dev/null || true
104+ - name : Repository to lowercase
105+ id : lower-repo
106+ run : echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
91107
92- df -h /
108+ - name : Extract Docker metadata
109+ id : meta
110+ uses : docker/metadata-action@v5
111+ with :
112+ images : ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}
93113
94- - id : lower-repo
95- name : Repository to lowercase
114+ - name : Create manifest list and push
115+ working-directory : /tmp/digests
96116 run : |
97- echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
117+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
118+ $(printf '${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}@sha256:%s ' *)
119+
120+ apptainer :
121+ runs-on : ubuntu-latest
122+ needs : merge
123+ permissions :
124+ contents : read
125+ packages : write
126+ steps :
127+ - name : Checkout repository
128+ uses : actions/checkout@v4
129+
130+ - name : Clean up disk space
131+ uses : jlumbroso/free-disk-space@main
132+
133+ - name : Repository to lowercase
134+ id : lower-repo
135+ run : echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
136+
137+ - name : Extract Docker metadata
138+ id : meta
139+ uses : docker/metadata-action@v5
140+ with :
141+ images : ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}
98142
99- # Build and push .sif files for Apptainer
100143 - name : Setup Apptainer
101144 uses : eWaterCycle/setup-apptainer@v2
145+
102146 - name : Build and push Apptainer
103147 env :
104148 TAGS : ${{ steps.meta.outputs.tags }}
105149 run : |
106- echo ${{ secrets.GITHUB_TOKEN }} | apptainer registry login -u ${{ secrets.GHCR_USERNAME }} --password-stdin docker://ghcr.io
107- apptainer build container.sif docker://${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}:latest
108- echo "${TAGS}" | xargs -I {} apptainer push container.sif oras://{}-sif
150+ echo ${{ secrets.GITHUB_TOKEN }} | apptainer registry login -u ${{ secrets.GHCR_USERNAME }} --password-stdin docker://ghcr.io
151+ apptainer build container.sif docker://${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.repository }}:latest
152+ echo "${TAGS}" | xargs -I {} apptainer push container.sif oras://{}-sif
0 commit comments