Skip to content

Commit 99f4cb5

Browse files
committed
Improve docker image tracking
- Adds the exact debian image digest we used in the layer history. - Adds the base image manifest list digest as an annotation for both the base and release images. - Tags the base image used for a release with the release version number.
1 parent 1a3cda1 commit 99f4cb5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.github/workflows/base-image.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
- name: Base image
4242
id: build-and-push
4343
run: |
44+
BASE_DIGEST=$(docker buildx imagetools inspect "debian:bookworm-slim" --format '{{json .}}' | jq -r '.manifest.digest')
45+
46+
sed -i "s|FROM debian:bookworm-slim|FROM debian:bookworm-slim@$BASE_DIGEST|" "image/Dockerfile-base"
47+
4448
docker buildx build \
4549
--tag "danielflook/terraform-github-actions-base:$GITHUB_RUN_ID" \
4650
--tag danielflook/terraform-github-actions-base:latest \
@@ -55,6 +59,7 @@ jobs:
5559
--annotation "index,manifest:builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
5660
--annotation "index,manifest:ref.tag=$GITHUB_RUN_ID" \
5761
--annotation "index,manifest:org.opencontainers.image.base.name=docker.io/debian:bookworm-slim" \
62+
--annotation "index,manifest:base.manifest.digest=$BASE_DIGEST" \
5863
--file image/Dockerfile-base \
5964
--push \
6065
--iidfile manifest-list-digest.txt \

.github/workflows/release.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
url: https://hub.docker.com/r/danielflook/terraform-github-actions/tags?name=${{ github.event.release.tag_name }}
2323
outputs:
2424
digest: ${{ steps.image_build.outputs.digest }}
25+
base-digest: ${{ steps.image_build.outputs.base-digest }}
2526
steps:
2627
- name: Checkout
2728
uses: actions/checkout@v4
@@ -74,12 +75,14 @@ jobs:
7475
--annotation "index,manifest:builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
7576
--annotation "index,manifest:ref.tag=$RELEASE_TAG" \
7677
--annotation "index,manifest:org.opencontainers.image.base.name=docker.io/danielflook/terraform-github-actions-base" \
78+
--annotation "index,manifest:base.manifest.digest=$BASE_DIGEST" \
7779
--annotation "index:org.opencontainers.image.base.ref=$BASE_TAG" \
7880
--push \
7981
--iidfile manifest-list-digest.txt \
8082
image
8183
8284
echo "digest=$(<manifest-list-digest.txt)" >> "$GITHUB_OUTPUT"
85+
echo "base-digest=$BASE_DIGEST" >> "$GITHUB_OUTPUT"
8386
8487
- name: Dockerhub ref attestation
8588
uses: actions/attest-build-provenance@v2
@@ -184,3 +187,35 @@ jobs:
184187
echo "Skipping dflook/$action"
185188
fi
186189
done
190+
191+
tag-base-image:
192+
runs-on: ubuntu-24.04
193+
name: Tag base image with release version
194+
needs:
195+
- image
196+
- actions
197+
permissions:
198+
contents: read
199+
packages: write
200+
environment:
201+
name: dockerhub
202+
url: https://hub.docker.com/r/danielflook/terraform-github-actions-base/tags?name=${{ github.event.release.tag_name }}
203+
steps:
204+
- name: Registry login
205+
env:
206+
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
207+
run: |
208+
echo "$DOCKER_TOKEN" | docker login --username danielflook --password-stdin
209+
210+
- name: Set up Docker Buildx
211+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
212+
213+
- name: Tag and push base image with release version
214+
env:
215+
RELEASE_TAG: "${{ github.event.release.tag_name }}"
216+
BASE_DIGEST: ${{ needs.image.outputs.base-digest }}
217+
run: |
218+
# Tag the base image manifest list with the release version
219+
docker buildx imagetools create \
220+
--tag "danielflook/terraform-github-actions-base:$RELEASE_TAG" \
221+
"danielflook/terraform-github-actions-base@$BASE_DIGEST"

0 commit comments

Comments
 (0)