#!/usr/bin/env bash # Публикация вспомогательных образов IFT: rebuild при изменениях, иначе promote :ift -> sha-*. # Usage: publish-ift-aux-images.sh set -euo pipefail REGISTRY="${1:?registry}" TAG="${2:?sha-tag}" FILES="${3:-}" rebuild_image() { local name="$1" local context="$2" local dockerfile="$3" local reason="$4" echo "== ${name}: rebuild (${reason})" bash scripts/retry-docker-build.sh 3 30 -- \ docker buildx build -f "${dockerfile}" --push \ -t "${REGISTRY}/${name}:${TAG}" \ -t "${REGISTRY}/${name}:ift" \ --provenance=false --sbom=false \ "${context}" } publish_image() { local name="$1" local path_pattern="$2" local context="$3" local dockerfile="$4" if docker buildx imagetools inspect "${REGISTRY}/${name}:${TAG}" >/dev/null 2>&1; then echo "== ${name}: ${TAG} already in registry, skip" return fi if echo "${FILES}" | grep -qE "${path_pattern}"; then rebuild_image "${name}" "${context}" "${dockerfile}" "matched: ${path_pattern}" return fi echo "== ${name}: unchanged, promote :ift -> ${TAG}" if ! docker buildx imagetools inspect "${REGISTRY}/${name}:ift" >/dev/null 2>&1; then rebuild_image "${name}" "${context}" "${dockerfile}" "bootstrap: :ift not found" return fi docker buildx imagetools create \ -t "${REGISTRY}/${name}:${TAG}" \ "${REGISTRY}/${name}:ift" } publish_image traefik-coraza '^docker/traefik/' docker/traefik docker/traefik/Dockerfile publish_image fallback '^docker/fallback/' docker/fallback docker/fallback/Dockerfile publish_image bot-emulator-users '^test/emulate_users/' . test/emulate_users/Dockerfile publish_image observer-web '^docker/ObserverWeb\.Dockerfile|^docker/observer_web/' . docker/ObserverWeb.Dockerfile publish_image logrotate '^docker/logrotate/' docker/logrotate docker/logrotate/Dockerfile