Build multi-architecture container releases
All checks were successful
Build and Publish Container / publish (push) Successful in 8m38s

This commit is contained in:
hhqyb
2026-07-27 15:45:37 +08:00
parent 040cb67715
commit 828bc972c4
2 changed files with 25 additions and 12 deletions

View File

@@ -27,32 +27,36 @@ jobs:
- name: Build and push image
run: |
push_image() {
local image="$1"
docker run --privileged --rm tonistiigi/binfmt --install arm64
BUILDER="stun-nat-${GITHUB_RUN_ID}"
docker buildx create --driver docker-container --name "$BUILDER" --use
trap 'docker buildx rm "$BUILDER"' EXIT
docker buildx inspect --bootstrap
build_and_push() {
local attempt=1
until docker push "$image"; do
until docker buildx build --platform linux/amd64,linux/arm64 --pull --push "${TAGS[@]}" .; do
if [ "$attempt" -ge 3 ]; then
echo "Failed to push ${image} after ${attempt} attempts"
echo "Failed to build and publish multi-architecture image after ${attempt} attempts"
return 1
fi
attempt=$((attempt + 1))
echo "Push failed; retrying ${image} (${attempt}/3) in 10 seconds"
echo "Build or push failed; retrying (${attempt}/3) in 10 seconds"
sleep 10
done
}
SHA_TAG="sha-${GITHUB_SHA}"
docker build --pull --tag "${IMAGE}:${SHA_TAG}" .
push_image "${IMAGE}:${SHA_TAG}"
TAGS=(--tag "${IMAGE}:${SHA_TAG}")
if [ "$GITHUB_REF" = "refs/heads/main" ]; then
docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:latest"
push_image "${IMAGE}:latest"
TAGS+=(--tag "${IMAGE}:latest")
fi
case "$GITHUB_REF" in
refs/tags/v*)
docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:${GITHUB_REF_NAME}"
push_image "${IMAGE}:${GITHUB_REF_NAME}"
TAGS+=(--tag "${IMAGE}:${GITHUB_REF_NAME}")
;;
esac
build_and_push