#!/usr/bin/env bash # Build all four images before optional publication. Authentication stays in Docker. # Disable tracing even when invoked with bash -x: command output may contain secrets. set +x set -euo pipefail usage() { cat <<'HELP' Usage: publish-images.sh [--tag TAG] [--dry-run] [--push] --tag TAG Image tag (default: full Git HEAD SHA) --dry-run Print the plan without executing Docker --push Publish after all four builds succeed -h, --help Show this help HELP } fail() { printf '%s\n' "$1" >&2; exit 1; } tag='' tag_set=false dry_run=false push=false while (($#)); do case "$1" in --tag) (($# >= 2)) || fail 'Missing value for --tag' tag=$2 tag_set=true shift 2 ;; --dry-run) dry_run=true; shift ;; --push) push=true; shift ;; -h|--help) usage; exit 0 ;; *) fail 'Unknown argument; use --help' ;; esac done # ASCII Docker tag syntax; never echo rejected input. export LC_ALL=C if "$tag_set"; then [[ $tag =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$ ]] || fail 'Invalid image tag' fi root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P) cd -- "$root" # Read-only runtime lookup; no mutation or remote Git operation. revision=$(git rev-parse --verify HEAD 2>/dev/null) || fail 'Cannot resolve Git HEAD' [[ $revision =~ ^[0-9a-f]{40}$ ]] || fail 'Expected a full Git SHA-1 revision' if ! "$tag_set"; then tag=$revision; fi readonly registry='gitea.anthonybouteiller.ovh/blomios' readonly source='https://gitea.anthonybouteiller.ovh/blomios/Tradarr' readonly laya_revision='e150aa92a0d4059ac621875b39b620847cf1b88a' images=() run() { if "$dry_run"; then printf '%q ' "$@" printf '\n' else # Suppress Docker diagnostics; do not expose commands or credentials on failure. "$@" >/dev/null 2>&1 || fail 'Image operation failed; stopped without further publication.' fi } for name in backend frontend scraper laya; do image="$registry/tradarr-$name:$tag" images+=("$image") image_source=$source image_revision=$revision context="$root/$name" extra=() case "$name" in scraper) context="$root/scraper-service" ;; laya) image_source='https://github.com/NandhaKishorM/laya' image_revision=$laya_revision context="$image_source.git#$laya_revision" extra=(--build-arg TORCH_INDEX=cpu) ;; esac run docker build --tag "$image" \ --label "org.opencontainers.image.source=$image_source" \ --label "org.opencontainers.image.revision=$image_revision" \ --label "org.opencontainers.image.version=$tag" \ "${extra[@]}" "$context" if ! "$dry_run"; then printf 'build completed: %s\n' "$image"; fi done if "$push"; then for image in "${images[@]}"; do run docker push "$image" if ! "$dry_run"; then printf 'push completed: %s\n' "$image"; fi done fi