74 lines
2.3 KiB
Bash
74 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Публикация вспомогательных образов IFT: rebuild при изменениях, иначе promote :ift -> sha-*.
|
|
# Usage: publish-ift-aux-images.sh <registry> <sha-tag> <changed-files-list>
|
|
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"
|
|
local attempts="${5:-3}"
|
|
local wait="${6:-30}"
|
|
|
|
echo "== ${name}: rebuild (${reason})"
|
|
bash scripts/retry-docker-build.sh "${attempts}" "${wait}" -- \
|
|
docker buildx build -f "${dockerfile}" --push \
|
|
-t "${REGISTRY}/${name}:${TAG}" \
|
|
-t "${REGISTRY}/${name}:ift" \
|
|
-t "${REGISTRY}/${name}:dev" \
|
|
--provenance=false --sbom=false \
|
|
"${context}"
|
|
}
|
|
|
|
try_rebuild() {
|
|
local optional="$1"
|
|
shift
|
|
if rebuild_image "$@"; then
|
|
return 0
|
|
fi
|
|
if [[ "${optional}" == "1" ]]; then
|
|
echo "WARN: $1: rebuild failed (optional), will try on IFT server or skip"
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
publish_image() {
|
|
local name="$1"
|
|
local path_pattern="$2"
|
|
local context="$3"
|
|
local dockerfile="$4"
|
|
local optional="${5:-0}"
|
|
|
|
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
|
|
try_rebuild "${optional}" "${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
|
|
try_rebuild "${optional}" "${name}" "${context}" "${dockerfile}" "bootstrap: :ift not found"
|
|
return
|
|
fi
|
|
docker buildx imagetools create \
|
|
-t "${REGISTRY}/${name}:${TAG}" \
|
|
-t "${REGISTRY}/${name}:dev" \
|
|
"${REGISTRY}/${name}:ift"
|
|
}
|
|
|
|
publish_image traefik-coraza '^docker/traefik/' docker/traefik docker/traefik/Dockerfile 0
|
|
publish_image fallback '^docker/fallback/' docker/fallback docker/fallback/Dockerfile 0
|
|
publish_image bot-emulator-users '^test/emulate_users/' . test/emulate_users/Dockerfile 0
|
|
publish_image observer-web '^docker/ObserverWeb\.Dockerfile|^docker/observer_web/' . docker/ObserverWeb.Dockerfile 1
|
|
publish_image logrotate '^docker/logrotate/' docker/logrotate docker/logrotate/Dockerfile 1
|