diff --git a/.gitea/workflows/deploy-ift.yml b/.gitea/workflows/deploy-ift.yml index 164b2a7..4abc04b 100644 --- a/.gitea/workflows/deploy-ift.yml +++ b/.gitea/workflows/deploy-ift.yml @@ -5,6 +5,11 @@ on: branches: [master, main] workflow_dispatch: +# Один runner (WSL): параллельные workflow ломают buildx/act. +concurrency: + group: eventhub-frontadmin-deploy-ift + cancel-in-progress: false + env: REGISTRY: git.sabilin.com/eventhub BUILDKIT_PROGRESS: quiet @@ -13,13 +18,13 @@ env: jobs: deploy-ift-admin: runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v4 - name: Compute image tag id: meta - run: echo "tag=sha-${GITHUB_SHA::12}" >> "$GITHUB_OUTPUT" + run: echo "tag=sha-${GITHUB_SHA:0:12}" >> "$GITHUB_OUTPUT" - uses: actions/setup-node@v4 with: @@ -39,16 +44,27 @@ jobs: username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and push admin-ui - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: | - ${{ env.REGISTRY }}/eventhub-admin-ui:${{ steps.meta.outputs.tag }} - ${{ env.REGISTRY }}/eventhub-admin-ui:ift - provenance: false - sbom: false + - name: Build admin-ui image + run: | + set -euo pipefail + bash scripts/retry-docker-build.sh 5 60 -- \ + docker buildx build \ + --network=host \ + --file Dockerfile \ + --tag eventhub-admin-ui:local \ + --load \ + --provenance=false \ + --sbom=false \ + . + + - name: Push admin-ui image + run: | + set -euo pipefail + TAG="${{ steps.meta.outputs.tag }}" + docker tag eventhub-admin-ui:local "${REGISTRY}/eventhub-admin-ui:${TAG}" + docker tag eventhub-admin-ui:local "${REGISTRY}/eventhub-admin-ui:ift" + bash scripts/retry-docker-build.sh 5 30 -- docker push "${REGISTRY}/eventhub-admin-ui:${TAG}" + bash scripts/retry-docker-build.sh 5 30 -- docker push "${REGISTRY}/eventhub-admin-ui:ift" - name: Deploy admin on IFT via SSH uses: appleboy/ssh-action@v0.1.5 @@ -59,4 +75,4 @@ jobs: script: | export REGISTRY_USER='${{ secrets.REGISTRY_USER }}' export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}' - /opt/eventhub-ift/devops/scripts/deploy-service.sh ift admin ${{ steps.meta.outputs.tag }} + bash /opt/eventhub-ift/devops/scripts/deploy-service.sh ift admin ${{ steps.meta.outputs.tag }} diff --git a/scripts/retry-docker-build.sh b/scripts/retry-docker-build.sh new file mode 100644 index 0000000..0b0190e --- /dev/null +++ b/scripts/retry-docker-build.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Retry docker/buildx commands on transient network/registry failures. +# Usage: retry-docker-build.sh [max_attempts] [wait_seconds] -- +set -euo pipefail + +MAX="${1:-3}" +WAIT="${2:-30}" +shift 2 +[[ "${1:-}" == "--" ]] && shift + +if [[ $# -eq 0 ]]; then + echo "Usage: $0 [max_attempts] [wait_seconds] -- " >&2 + exit 2 +fi + +attempt=1 +while true; do + echo "== docker build attempt ${attempt}/${MAX}: $*" + set +e + "$@" + code=$? + set -e + if (( code == 0 )); then + exit 0 + fi + if (( attempt >= MAX )); then + echo "== all ${MAX} attempts failed (last exit ${code})" + exit "${code}" + fi + echo "== attempt ${attempt} failed (exit ${code}), retry in ${WAIT}s..." + docker buildx prune -f >/dev/null 2>&1 || true + sleep "${WAIT}" + attempt=$((attempt + 1)) +done