Publish images under the git version tag too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
goyban
2026-10-12 10:48:56 +02:00
parent c015e5663b
commit 0ed1bc4a0e
2 changed files with 16 additions and 6 deletions
+14 -5
View File
@@ -5,6 +5,9 @@
# ./publish.sh # builds HEAD
# ./publish.sh v1.2 # builds a tag/branch/commit
#
# The image is tagged with the commit and `latest`, plus the version when the commit has a git tag
# like v1.2. To release a new version: git tag v1.2 && ./publish.sh v1.2
#
# One-time setup: docker login git.goyban.com (password = a Gitea token with package write access)
set -euo pipefail
@@ -15,9 +18,15 @@ REF="${1:-HEAD}"
cd "$(dirname "$0")"
SHA="$(git rev-parse --short "$REF^{commit}")"
echo "Building $IMAGE from $REF ($SHA)"
git archive --format=tar "$REF" | docker build --target runtime -t "$IMAGE:$SHA" -t "$IMAGE:latest" -
# Newest version tag (v1.2, v1.2.3) on this commit, if any.
VERSION="$(git tag --points-at "$SHA" --list 'v[0-9]*' --sort=-v:refname | head -n 1)"
TAGS=("$SHA" latest)
if [ -n "$VERSION" ]; then TAGS+=("$VERSION"); fi
docker push "$IMAGE:$SHA"
docker push "$IMAGE:latest"
echo "Pushed $IMAGE:$SHA and $IMAGE:latest"
echo "Building $IMAGE from $REF ($SHA${VERSION:+, $VERSION})"
BUILD_TAGS=()
for t in "${TAGS[@]}"; do BUILD_TAGS+=(-t "$IMAGE:$t"); done
git archive --format=tar "$REF" | docker build --target runtime "${BUILD_TAGS[@]}" -
for t in "${TAGS[@]}"; do docker push "$IMAGE:$t"; done
echo "Pushed $IMAGE with tags: ${TAGS[*]}"