#!/usr/bin/env bash set -euo pipefail usage() { printf '%s\n' 'Usage: build-push.sh [TAG]' \ 'Build this checkout and push it to the Gitea container registry.' \ 'TAG defaults to NODECAST_TAG or latest; NODECAST_IMAGE overrides the image repository.' } if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then usage exit 0 fi if [[ $# -gt 1 ]]; then usage >&2 exit 1 fi repo_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" image="${NODECAST_IMAGE:-gitea.anthonybouteiller.ovh/blomios/nodecast-tv}" tag="${1-${NODECAST_TAG:-latest}}" if [[ ! $tag =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$ ]]; then printf '%s\n' 'Error: Invalid Docker tag (1–128 letters, digits, underscores, dots or hyphens; cannot start with dot/hyphen).' >&2 exit 1 fi if [[ $image != */* || $image == *://* || $image == *@* || $image =~ [[:space:]] || ${image##*/} == *:* ]]; then printf '%s\n' 'Error: NODECAST_IMAGE must be a registry/repository path without a tag or digest.' >&2 exit 1 fi if ! command -v docker >/dev/null 2>&1; then printf '%s\n' 'Error: Docker is required to build and push the image.' >&2 exit 1 fi reference="${image}:${tag}" printf 'Building %s from %s\n' "$reference" "$repo_dir" docker build --file "$repo_dir/Dockerfile" --tag "$reference" "$repo_dir" printf 'Pushing %s\n' "$reference" docker push "$reference"