From 914ebc9dbff54ace9d2b5e1cf054dce51d74d09e Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Tue, 16 Jun 2026 08:30:05 +0200 Subject: [PATCH] ci: pipeline de build no Gitea Actions (Etapa 5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .gitea/workflows/build.yml — em push na main + tags v*, builda backend+frontend com carimbo de versão e publica no registry (sem deploy). Login tolerante (secret REGISTRY_TOKEN se existir; senão credencial do host). Retry p/ 499. Runner self-hosted 'vps4-builder' (modo host) registrado na VPS4. Co-Authored-By: Claude Opus 4.8 --- .gitea/workflows/build.yml | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .gitea/workflows/build.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..f122f68 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,66 @@ +name: build-and-push + +# Etapa 5: a cada push na main (ou tag vX.Y.Z), builda as imagens com o carimbo +# de versão e envia ao Container Registry do Gitea. NÃO faz deploy (Etapa 6 separada). +on: + push: + branches: [main] + tags: ['v*'] + +jobs: + build: + # Roda direto no host VPS4 (runner registrado com label de host + acesso ao Docker). + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Calcular versão/commit/data + id: vars + run: | + echo "version=$(grep -oE 'V[0-9]+\.[0-9]+\.[0-9]+' frontend/constants.ts | head -1 | tr 'V' 'v')" >> "$GITHUB_OUTPUT" + echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + echo "build_time=$(date -u +'%Y-%m-%d %H:%M UTC')" >> "$GITHUB_OUTPUT" + + - name: Login no registry + run: | + if [ -n "${{ secrets.REGISTRY_TOKEN }}" ]; then + echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.clube67.com -u ruicesar --password-stdin + else + echo "REGISTRY_TOKEN não definido — usando a credencial já presente no host (~/.docker/config.json)." + fi + + - name: Build (compose, com carimbo de versão) + env: + APP_VERSION: ${{ steps.vars.outputs.version }} + GIT_COMMIT: ${{ steps.vars.outputs.commit }} + BUILD_TIME: ${{ steps.vars.outputs.build_time }} + APP_ENV: PROD + run: docker compose build scoreodonto-backend scoreodonto-frontend + + - name: Tag + push (com retry p/ 499 transitório) + run: | + set -e + V="${{ steps.vars.outputs.version }}" + C="${{ steps.vars.outputs.commit }}" + for app in backend frontend; do + SRC="scoreodontocom-scoreodonto-${app}:latest" + DST="git.clube67.com/ruicesar/scoreodonto-${app}" + docker tag "$SRC" "$DST:$V" + docker tag "$SRC" "$DST:$C" + docker tag "$SRC" "$DST:latest" + for tag in "$V" "$C" "latest"; do + n=0 + until docker push "$DST:$tag"; do + n=$((n+1)); [ $n -ge 4 ] && { echo "push falhou após 4 tentativas: $DST:$tag"; exit 1; } + echo "retry $n (499 transitório) em $DST:$tag"; sleep 3 + done + done + done + + - name: Resumo + run: | + echo "Imagens publicadas:" + echo " git.clube67.com/ruicesar/scoreodonto-backend:${{ steps.vars.outputs.version }}" + echo " git.clube67.com/ruicesar/scoreodonto-frontend:${{ steps.vars.outputs.version }}" + echo "Deploy NÃO foi executado (Etapa 6 trata disso)."