55 branches : [main]
66 pull_request : {}
77
8+ env :
9+ REGISTRY : ghcr.io
10+ IMAGE_NAME : ${{ github.repository }}
11+
812jobs :
913 build :
10- runs-on : ubuntu-24.04
14+ name : build (${{ matrix.platform }})
15+ runs-on : ubuntu-24.04${{ matrix.platform == 'linux/arm64' && '-arm' || ''}}
16+ strategy :
17+ fail-fast : false
18+ matrix :
19+ platform :
20+ - linux/amd64
21+ - linux/arm64
1122 permissions :
1223 id-token : write
1324 packages : write
1425 contents : read
1526 attestations : write
1627 env :
17- REGISTRY : ghcr.io
18- IMAGE_NAME : ${{ github.repository }}
28+ PLATFORM : ${{ matrix.platform }}
1929
2030 steps :
2131 - name : Checkout
2232 uses : actions/checkout@v5
23- - name : Set up QEMU
24- id : qemu
25- uses : docker/setup-qemu-action@v3
33+ - name : Build time variables
34+ run : |-
35+ echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >>"$GITHUB_ENV"
36+ echo "TOR_VERSION=$(tr -d '\n' <VERSION)" >>"$GITHUB_ENV"
37+ - name : Skip if already published
38+ env :
39+ FULL_DOCKER_IMAGE : " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TOR_VERSION }}"
40+ run : |-
41+ echo "Checking if $FULL_DOCKER_IMAGE exists ..."
42+ if docker manifest inspect "$FULL_DOCKER_IMAGE" &>/dev/null; then
43+ echo "$FULL_DOCKER_IMAGE already exists, skipping build"
44+ gh run cancel "$GITHUB_RUN_ID"
45+ exit 0
46+ fi
2647 - name : Set up Docker Buildx
2748 uses : docker/setup-buildx-action@v3
2849 - name : Login to GitHub Container Registry
@@ -31,27 +52,85 @@ jobs:
3152 registry : ${{ env.REGISTRY }}
3253 username : ${{ github.actor }}
3354 password : ${{ secrets.GITHUB_TOKEN }}
34- - run : echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >>"$GITHUB_ENV"
35- - run : echo "TOR_VERSION=$(tr -d '\n' <VERSION) >>"$GITHUB_ENV"
55+ - name : Download Gentoo
56+ run : ./scripts/fetch-gentoo.sh "${PLATFORM##*/}"
57+ - name : Docker meta
58+ id : meta
59+ uses : docker/metadata-action@v5
60+ with :
61+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3662 - name : Build and push image
3763 uses : docker/build-push-action@v6
38- id : push
64+ id : build
3965 env :
4066 SOURCE_DATE_EPOCH : ${{ env.TIMESTAMP }}
4167 with :
4268 context : .
43- outputs : type=registry,rewrite-timestamp=true
4469 sbom : true
45- push : ${{ github.event_name != 'pull_request' }}
46- provenance : " max "
70+ provenance : mode=max
71+ labels : ${{ steps.meta.outputs.labels }}
4772 build-args : TOR_VERSION=${{ env.TOR_VERSION }}
48- platforms : " linux/amd64,linux/arm64"
49- tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TOR_VERSION }}
73+ tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
74+ outputs : type=image,rewrite-timestamp=true,push-by-digest=true,name-canonical=true,push=${{ github.event_name == 'push' }}
75+ - name : Export digest
76+ run : |-
77+ mkdir -p "${{ runner.temp }}/digests"
78+ digest="${{ steps.build.outputs.digest }}"
79+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
80+ - name : Escape platform (/ -> -)
81+ id : platform
82+ run : echo "escaped=${PLATFORM//\//-}" >"$GITHUB_OUTPUT"
83+ - name : Upload digest
84+ uses : actions/upload-artifact@v4
85+ with :
86+ name : digests-${{ steps.platform.outputs.escaped }}
87+ path : ${{ runner.temp }}/digests/*
88+ if-no-files-found : error
89+ retention-days : 1
90+ - name : Attest
91+ uses : actions/attest-build-provenance@v3
92+ id : attest
93+ if : ${{ github.event_name == 'push' }}
94+ with :
95+ subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
96+ subject-digest : ${{ steps.build.outputs.digest }}
97+ push-to-registry : true
98+
99+ merge :
100+ if : ${{ github.event_name == 'push' }}
101+ runs-on : ubuntu-24.04
102+ needs :
103+ - build
104+ steps :
105+ - name : Checkout
106+ uses : actions/checkout@v5
107+ - name : Build time variables
108+ run : |-
109+ echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >>"$GITHUB_ENV"
110+ echo "TOR_VERSION=$(tr -d '\n' <VERSION)" >>"$GITHUB_ENV"
111+ - name : Download digests
112+ uses : actions/download-artifact@v4
113+ with :
114+ path : ${{ runner.temp }}/digests
115+ pattern : digests-*
116+ merge-multiple : true
117+ - name : Set up Docker Buildx
118+ uses : docker/setup-buildx-action@v3
119+ - name : Create manifest
120+ id : manifest
121+ env :
122+ FULL_DOCKER_IMAGE : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TOR_VERSION }}
123+ DOCKER_IMAGE : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
124+ run : |-
125+ readarray -t digests < <(printf "$DOCKER_IMAGE@sha256:%s\n" *)
126+ docker buildx imagetools create -t "$FULL_DOCKER_IMAGE" "${digests[@]}"
127+ docker buildx imagetools inspect "$FULL_DOCKER_IMAGE"
128+ echo "digest=$(docker buildx imagetools inspect "$FULL_DOCKER_IMAGE" | grep "Digest:" | awk '{ print $2 }')" >"$GITHUB_OUTPUT"
50129 - name : Attest
51- uses : actions/attest-build-provenance@v2
130+ uses : actions/attest-build-provenance@v3
52131 id : attest
53132 if : ${{ github.event_name == 'push' }}
54133 with :
55134 subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
56- subject-digest : ${{ steps.push .outputs.digest }}
135+ subject-digest : ${{ steps.manifest .outputs.digest }}
57136 push-to-registry : true
0 commit comments