Fix Gitea Actions image tags and push retries
All checks were successful
Build and Publish Container / publish (push) Successful in 1m7s

This commit is contained in:
hhqyb
2026-07-27 15:36:06 +08:00
parent 3c5679f31e
commit 040cb67715

View File

@@ -27,18 +27,32 @@ jobs:
- name: Build and push image - name: Build and push image
run: | run: |
SHA_TAG="sha-${GITEA_SHA}" push_image() {
docker build --pull --tag "${IMAGE}:${SHA_TAG}" . local image="$1"
docker push "${IMAGE}:${SHA_TAG}" local attempt=1
until docker push "$image"; do
if [ "$attempt" -ge 3 ]; then
echo "Failed to push ${image} after ${attempt} attempts"
return 1
fi
attempt=$((attempt + 1))
echo "Push failed; retrying ${image} (${attempt}/3) in 10 seconds"
sleep 10
done
}
if [ "$GITEA_REF" = "refs/heads/main" ]; then SHA_TAG="sha-${GITHUB_SHA}"
docker build --pull --tag "${IMAGE}:${SHA_TAG}" .
push_image "${IMAGE}:${SHA_TAG}"
if [ "$GITHUB_REF" = "refs/heads/main" ]; then
docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:latest" docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:latest"
docker push "${IMAGE}:latest" push_image "${IMAGE}:latest"
fi fi
case "$GITEA_REF" in case "$GITHUB_REF" in
refs/tags/v*) refs/tags/v*)
docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:${GITEA_REF_NAME}" docker tag "${IMAGE}:${SHA_TAG}" "${IMAGE}:${GITHUB_REF_NAME}"
docker push "${IMAGE}:${GITEA_REF_NAME}" push_image "${IMAGE}:${GITHUB_REF_NAME}"
;; ;;
esac esac