Files
ayurishchevandClaude Opus 5.5 d0ab6b94f9 Ansible: deliver validator-agent from the artreg registry instead of building on each host
The role resolves image_tag to a digest once per run and pulls that image
on every validator before replacing the container; the git and build
steps are gone. scripts/publish-agent-image.sh builds and pushes the
agent image (<rev12> and latest tags).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 23:59:33 +03:00

59 lines
1.7 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Сборка и публикация образа validator-agent в реестр.
# Запуск: scripts/publish-agent-image.sh [--no-latest]
# Переменные: REGISTRY (artreg.rxmsk.ru), IMAGE_REPO (civ-agent).
set -euo pipefail
cd "$(dirname "$0")/.."
REGISTRY="${REGISTRY:-artreg.rxmsk.ru}"
IMAGE_REPO="${IMAGE_REPO:-civ-agent}"
PUSH_LATEST=1
for arg in "$@"; do
case "${arg}" in
--no-latest) PUSH_LATEST=0 ;;
*) echo "Неизвестный параметр: ${arg}" >&2; exit 2 ;;
esac
done
if [ -n "$(git status --porcelain)" ]; then
echo "Рабочее дерево не чистое: закоммитьте или уберите изменения." >&2
exit 1
fi
if ! (cd bin && grep ' validator-agent$' SHA256SUMS | sha256sum -c -); then
echo "bin/validator-agent не совпадает с bin/SHA256SUMS." >&2
exit 1
fi
REV="$(git rev-parse HEAD)"
REV12="${REV:0:12}"
if [ -z "$(git branch -r --contains HEAD)" ]; then
echo "Коммит ${REV12} не запушен: сначала git push." >&2
exit 1
fi
REF="${REGISTRY}/${IMAGE_REPO}"
TAGS=(-t "${REF}:${REV12}")
if [ "${PUSH_LATEST}" -eq 1 ]; then
TAGS+=(-t "${REF}:latest")
fi
docker build --platform linux/amd64 --label "git.rev=${REV}" "${TAGS[@]}" \
-f deploy/docker/validator-agent/Dockerfile .
if ! docker run --rm --platform linux/amd64 --entrypoint sh "${REF}:${REV12}" -c 'command -v traceroute' >/dev/null; then
echo "В образе нет traceroute." >&2
exit 1
fi
docker push "${REF}:${REV12}"
if [ "${PUSH_LATEST}" -eq 1 ]; then
docker push "${REF}:latest"
fi
echo "Опубликовано: ${REF}:${REV12}"
docker image inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "${REF}:${REV12}"