From 0ed1bc4a0e25aded6134ac6d267cb4c7517fbe9d Mon Sep 17 00:00:00 2001 From: goyban Date: Mon, 12 Oct 2026 10:48:56 +0200 Subject: [PATCH] Publish images under the git version tag too Co-Authored-By: Claude Opus 5.5 --- README.md | 3 ++- publish.sh | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3554236..7da4344 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ docker compose down # stop docker compose pull && docker compose up -d # update to the newest published version ``` -To pin a version, set `WHATTODO_TAG=` in `.env` (default: `latest`). +To pin a version, set `WHATTODO_TAG=` in `.env`, e.g. `v1.0` or a commit (default: `latest`). ## Develop (build from source) @@ -58,6 +58,7 @@ docker compose run --rm test # run the test suite (in Docker) `./publish.sh` builds the last commit (uncommitted changes are left out) and pushes it to `git.goyban.com/goyban/whattodo` as `:latest` and `:`. `./publish.sh ` publishes another version. +To release a numbered version, tag the commit first: `git tag v1.1 && ./publish.sh v1.1` also pushes the image as `:v1.1`. Log in once first with `docker login git.goyban.com`, using a Gitea token with package write access as the password. ### Testing on your phone (same Wi-Fi) diff --git a/publish.sh b/publish.sh index 0f2d83e..160f9a4 100755 --- a/publish.sh +++ b/publish.sh @@ -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[*]}"