#!/usr/bin/env bash # Builds the image on this machine and pushes it to the Gitea package registry (ADR 0009, ADR 0015). The normal path # is release.yml on a vX.Y.Z tag; use this when the runner is not available. It does NOT create git tags: pushing the # tag later makes release.yml find the version in the registry and only create the release. # # scripts/publish-image.sh vX.Y.Z [--arm64] [--force] # # Environment: GITEA_TOKEN (required, scope write:package), GITEA_URL (https://gitea.encke-hake.ts.net), # GITEA_OWNER (BalboSoft), GITEA_USER (login of the token owner; defaults to GITEA_OWNER). set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root" tag="${1:-}" [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || { echo "uso: publish-image.sh vX.Y.Z [--arm64] [--force]" >&2; exit 2; } shift platforms="linux/amd64" force=false for arg in "$@"; do case "$arg" in --arm64) platforms="linux/amd64,linux/arm64" ;; --force) force=true ;; *) echo "argomento sconosciuto: $arg" >&2; exit 2 ;; esac done gitea_url="${GITEA_URL:-https://gitea.encke-hake.ts.net}" gitea_url="${gitea_url%/}" registry="${gitea_url#https://}" registry="${registry#http://}" owner="${GITEA_OWNER:-BalboSoft}" owner_lc="$(printf '%s' "$owner" | tr '[:upper:]' '[:lower:]')" image="$registry/$owner_lc/khaemhat" version="${tag#v}" sha="$(git rev-parse --short HEAD)" token="${GITEA_TOKEN:?imposta GITEA_TOKEN (permesso write:package)}" if [[ -n "$(git status --porcelain)" ]]; then echo "ATTENZIONE: ci sono modifiche non committate; l'immagine riporterà lo SHA $sha." >&2 fi status="$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: token $token" \ "$gitea_url/api/v1/packages/$owner/container/khaemhat/$version")" if [[ "$status" == "200" && "$force" != true ]]; then echo "La versione $version è già nel registro: niente da fare (usa --force per sovrascriverla)." >&2 exit 1 fi # Versioned icon for Unraid if committed, otherwise the plain one (ADR 0016). major_minor="${version%%-*}" major_minor="${major_minor%.*}" icon_url="$gitea_url/$owner/Khaemhat/raw/branch/main/assets/icon-256.png" if git cat-file -e "origin/main:assets/icon-v${major_minor}-256.png" 2>/dev/null; then icon_url="$gitea_url/$owner/Khaemhat/raw/branch/main/assets/icon-v${major_minor}-256.png" fi tags=(-t "$image:$version") [[ "$version" == *-* ]] || tags+=(-t "$image:latest") printf '%s' "$token" | docker login "$registry" -u "${GITEA_USER:-$owner}" --password-stdin docker buildx build --platform "$platforms" -f docker/Dockerfile \ --build-arg VERSION="$version" \ --build-arg GIT_SHA="$sha" \ --build-arg CREATED="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ --build-arg SOURCE_URL="$gitea_url/$owner/Khaemhat" \ --build-arg ICON_URL="$icon_url" \ "${tags[@]}" --push . echo "Pubblicata $image:$version ($platforms)."