Skip to content

Commit 0da9045

Browse files
author
Dieter Baier
committed
New tagging strategy
1 parent 5f156f6 commit 0da9045

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed
Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,59 @@
1-
name: Build Docs
1+
name: Build Docs Toolbox Image
22

33
on:
44
push:
55
branches: [ main ]
6+
tags:
7+
- '*'
68
workflow_dispatch:
79

810
jobs:
911
build-image:
1012
runs-on: ubuntu-latest
11-
outputs:
12-
image_name: ${{ steps.setImageName.outputs.IMAGE_NAME }}
13+
permissions:
14+
contents: read
15+
packages: write
1316

1417
steps:
1518
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
1621

1722
- name: Set image name
18-
id: setImageName
23+
id: image
24+
shell: bash
1925
run: |
2026
IMAGE_NAME="ghcr.io/${GITHUB_REPOSITORY_OWNER}/docs-toolbox"
21-
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_OUTPUT
27+
echo "image_name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
28+
29+
- name: Compute tags
30+
id: meta
31+
shell: bash
32+
run: |
33+
set -euo pipefail
34+
35+
IMAGE="${{ steps.image.outputs.image_name }}"
36+
37+
DOCKERFILE_HASH="$(sha256sum Dockerfile | awk '{print $1}' | cut -c1-12)"
38+
HASH_TAG="df-${DOCKERFILE_HASH}"
39+
40+
TAGS="${IMAGE}:${HASH_TAG}"
41+
HAS_GIT_TAG=false
42+
GIT_TAG=""
43+
44+
if git tag --points-at HEAD | grep -q .; then
45+
GIT_TAG="$(git tag --points-at HEAD | head -n1)"
46+
HAS_GIT_TAG=true
47+
TAGS="${TAGS},${IMAGE}:${GIT_TAG},${IMAGE}:latest"
48+
fi
49+
50+
echo "dockerfile_hash=${DOCKERFILE_HASH}" >> "$GITHUB_OUTPUT"
51+
echo "hash_tag=${HASH_TAG}" >> "$GITHUB_OUTPUT"
52+
echo "has_git_tag=${HAS_GIT_TAG}" >> "$GITHUB_OUTPUT"
53+
echo "git_tag=${GIT_TAG}" >> "$GITHUB_OUTPUT"
54+
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
55+
56+
echo "Using tags: ${TAGS}"
2257
2358
- name: Login to GHCR
2459
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
@@ -29,12 +64,34 @@ jobs:
2964
- name: Set up Docker Buildx
3065
uses: docker/setup-buildx-action@v3
3166

32-
- name: Build image
67+
- name: Build and push image
68+
shell: bash
3369
run: |
34-
IMAGE=${{ steps.setImageName.outputs.IMAGE_NAME }}
70+
set -euo pipefail
71+
72+
IMAGE="${{ steps.image.outputs.image_name }}"
73+
TAGS="${{ steps.meta.outputs.tags }}"
74+
75+
TAG_ARGS=""
76+
IFS=',' read -ra TAG_ARRAY <<< "$TAGS"
77+
for tag in "${TAG_ARRAY[@]}"; do
78+
TAG_ARGS="$TAG_ARGS -t $tag"
79+
done
80+
3581
docker buildx build \
3682
--platform linux/amd64,linux/arm64 \
3783
--cache-from=type=registry,ref=$IMAGE:cache \
3884
--cache-to=type=registry,ref=$IMAGE:cache,mode=max \
39-
-t $IMAGE:latest \
40-
--push .
85+
$TAG_ARGS \
86+
--push .
87+
88+
- name: Print summary
89+
shell: bash
90+
run: |
91+
echo "Dockerfile hash tag: ${{ steps.meta.outputs.hash_tag }}"
92+
if [[ "${{ steps.meta.outputs.has_git_tag }}" == "true" ]]; then
93+
echo "Git tag: ${{ steps.meta.outputs.git_tag }}"
94+
echo "latest tag was also published"
95+
else
96+
echo "No Git tag on HEAD, so no latest tag published"
97+
fi

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ This image follows a few simple principles:
9898
- 🧼 No hidden magic
9999
100100
## 🔄 Versioning
101-
- latest → most recent stable toolchain
101+
- latest → most recent stable toolbox
102102
- version tags → reproducible builds
103+
- `df-<hash>` → image of latest commit (does not need to be the same as 'latest')
103104

104105
👉 Pin versions in CI for full determinism.
105106

0 commit comments

Comments
 (0)