Skip to content

Commit bab03fc

Browse files
committed
use digest instead of temp tags
1 parent 03f3c1d commit bab03fc

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

.github/workflows/docker.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
runner: ubuntu-24.04-arm
6464
env:
6565
PUBLISH: ${{ github.event.inputs.publish == 'true' || github.event_name != 'pull_request' }}
66-
BUILD_TAG: &build-tag build-${{ github.run_id }}-${{ matrix.network }}
6766
steps:
6867
- &channel
6968
id: channel
@@ -122,15 +121,32 @@ jobs:
122121
username: ${{ vars.DOCKERHUB_USERNAME }}
123122
password: ${{ secrets.DOCKERHUB_TOKEN }}
124123
- name: Build image
124+
id: build
125125
uses: docker/build-push-action@v5
126126
with:
127127
context: .
128128
platforms: linux/${{ matrix.platform.arch }}
129-
push: ${{ env.PUBLISH == 'true' }}
130-
tags: filecoin/${{ matrix.image }}:${{ env.BUILD_TAG }}-${{ matrix.platform.arch }}
129+
outputs: type=image,name=filecoin/${{ matrix.image }},push-by-digest=true,name-canonical=true,push=${{ env.PUBLISH == 'true' }}
131130
labels: ${{ steps.meta.outputs.labels }}
132131
build-args: |
133132
${{ matrix.network != 'mainnet' && format('GOFLAGS=-tags={0}', matrix.network) || ''}}
133+
- name: Export image digest
134+
if: env.PUBLISH == 'true'
135+
env:
136+
DIGEST: ${{ steps.build.outputs.digest }}
137+
ARCH: ${{ matrix.platform.arch }}
138+
run: |
139+
[[ "$DIGEST" =~ ^sha256:[a-f0-9]{64}$ ]] || exit 1
140+
mkdir -p "$RUNNER_TEMP/digests"
141+
printf '%s\n' "$DIGEST" > "$RUNNER_TEMP/digests/$ARCH"
142+
- name: Upload image digest
143+
if: env.PUBLISH == 'true'
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: image-digests-${{ matrix.image }}-${{ matrix.network }}-${{ matrix.platform.arch }}
147+
path: ${{ runner.temp }}/digests/*
148+
if-no-files-found: error
149+
overwrite: true
134150

135151
publish:
136152
name: Publish Docker (${{ matrix.image }} / ${{ matrix.network }})
@@ -152,14 +168,19 @@ jobs:
152168
- image: lotus
153169
network: mainnet
154170
env:
155-
BUILD_TAG: *build-tag
156171
IMAGE: filecoin/${{ matrix.image }}
157172
steps:
158173
- *channel
159174
- uses: actions/checkout@v4
160175
with:
161176
fetch-depth: 0
162177
- *git
178+
- name: Download image digests
179+
uses: actions/download-artifact@v4
180+
with:
181+
path: ${{ runner.temp }}/digests
182+
pattern: image-digests-${{ matrix.image }}-${{ matrix.network }}-*
183+
merge-multiple: true
163184
- name: Set up Docker Buildx
164185
uses: docker/setup-buildx-action@v3
165186
- *docker-meta
@@ -172,7 +193,12 @@ jobs:
172193
env:
173194
METADATA_JSON: ${{ steps.meta.outputs.json }}
174195
run: |
175-
sources=("$IMAGE:$BUILD_TAG-amd64" "$IMAGE:$BUILD_TAG-arm64")
196+
sources=()
197+
for arch in amd64 arm64; do
198+
digest="$(cat "$RUNNER_TEMP/digests/$arch")"
199+
[[ "$digest" =~ ^sha256:[a-f0-9]{64}$ ]] || exit 1
200+
sources+=("$IMAGE@$digest")
201+
done
176202
177203
tag_args=()
178204
while IFS= read -r tag; do
@@ -186,25 +212,3 @@ jobs:
186212
| sort | unique == ["amd64", "arm64"]
187213
' "$RUNNER_TEMP/manifest.json"
188214
docker buildx imagetools create "${tag_args[@]}" "${sources[@]}"
189-
- name: Remove temporary architecture tags
190-
# A cleanup failure must not invalidate a successfully published image.
191-
continue-on-error: true
192-
env:
193-
IMAGE_TAG: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
194-
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
195-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
196-
run: |
197-
docker buildx imagetools inspect --raw "$IMAGE_TAG" | jq -e '
198-
[.manifests[].platform | select(.os == "linux") | .architecture]
199-
| sort | unique == ["amd64", "arm64"]
200-
'
201-
202-
hub_token="$(jq -n '{identifier: env.DOCKERHUB_USERNAME, secret: env.DOCKERHUB_TOKEN}' |
203-
curl -fsS -H 'Content-Type: application/json' --data-binary @- \
204-
https://hub.docker.com/v2/auth/token |
205-
jq -er '.access_token // empty')"
206-
echo "::add-mask::$hub_token"
207-
for arch in amd64 arm64; do
208-
curl -fsS -X DELETE -H "Authorization: Bearer $hub_token" \
209-
"https://hub.docker.com/v2/namespaces/filecoin/repositories/${IMAGE#*/}/tags/$BUILD_TAG-$arch/"
210-
done

0 commit comments

Comments
 (0)