chore: add ACR build/push script

This commit is contained in:
2026-02-28 17:48:05 +08:00
parent 98506927be
commit 7679e21024

44
build-push-acr.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
require() {
local name="$1"
if [[ -z "${!name:-}" ]]; then
echo "Missing env: ${name}" >&2
exit 2
fi
}
require ACR_REGISTRY
require ACR_NAMESPACE
image_repo="${IMAGE_REPO:-digital-archive-server}"
image_tag="${IMAGE_TAG:-}"
if [[ -z "$image_tag" ]]; then
if command -v git >/dev/null 2>&1; then
image_tag="$(git -C "$script_dir" rev-parse --short HEAD 2>/dev/null || true)"
fi
fi
if [[ -z "$image_tag" ]]; then
image_tag="$(date +%Y%m%d%H%M%S)"
fi
image_ref="${ACR_REGISTRY}/${ACR_NAMESPACE}/${image_repo}:${image_tag}"
if [[ -n "${ACR_USERNAME:-}" && -n "${ACR_PASSWORD:-}" ]]; then
printf '%s' "$ACR_PASSWORD" | docker login "$ACR_REGISTRY" -u "$ACR_USERNAME" --password-stdin
fi
docker build \
-f "$script_dir/Dockerfile" \
-t "$image_ref" \
"$script_dir"
docker push "$image_ref"
echo "Pushed: $image_ref"
echo "SERVER_IMAGE=$image_ref"