Files
whattodo/publish.sh
T
2026-10-12 10:48:56 +02:00

33 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the app image from a committed version and push it to the Gitea registry.
# Only committed files are used (via `git archive`), so uncommitted work never ends up in the image.
#
# ./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
REGISTRY=git.goyban.com
IMAGE="$REGISTRY/goyban/whattodo"
REF="${1:-HEAD}"
cd "$(dirname "$0")"
SHA="$(git rev-parse --short "$REF^{commit}")"
# 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
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[*]}"