Files
EvoGO/.gitea/workflows/docker-build.yml
T
jfengandClaude Opus 5.5 c9511a636e
CI - Validacao Go / Validar Codigo e Testes (push) Successful in 1m48s
ci: retry registry login, pull and push
A transient timeout on the registry token endpoint failed the publication of
v0.7.2-evogo.2 (run 482) after the image had already been built and scanned.
Login, pull and push now retry up to 5 times with linear backoff.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 07:52:15 -03:00

134 lines
5.2 KiB
YAML

name: Docker - Build e Publicacao
# Publicacao no registry do Gitea (git.jf.eng.br/jfeng/evogo):
# - push de tag v<versao> (ex: v0.7.2-evogo.1) = release aprovado -> publica
# git.jf.eng.br/jfeng/evogo:<versao> (tag semantica)
# git.jf.eng.br/jfeng/evogo:<versao>-<sha7> (tag imutavel do commit)
# - workflow_dispatch com publish_image=true -> idem, versao = target_tag ou VERSION
# - push em maintained-stable -> apenas build + teste + scan (nao publica)
# :latest so e atualizada com promote_latest=true (manual), nunca automaticamente.
on:
push:
branches:
- maintained-stable
tags:
- 'v*'
workflow_dispatch:
inputs:
publish_image:
description: 'Publicar imagem no registry apos build e testes (requer aprovacao)'
type: boolean
default: false
required: true
target_tag:
description: 'Tag semantica para publicacao (ex: 0.7.2-evogo.1). Vazio = arquivo VERSION'
type: string
default: ''
required: false
promote_latest:
description: 'Tambem atualizar :latest (somente versoes aprovadas em maintained-stable)'
type: boolean
default: false
required: false
env:
REGISTRY: git.jf.eng.br
IMAGE: git.jf.eng.br/jfeng/evogo
jobs:
build_docker:
name: Build, Scan e Publicacao
runs-on: ubuntu-latest
steps:
- name: Checkout do Repositorio
uses: actions/checkout@v4
- name: Obter Versao e Commit SHA
id: meta
run: |
COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
PUBLISH=true
else
VERSION="${{ github.event.inputs.target_tag }}"
[ -n "$VERSION" ] || VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0")
PUBLISH="${{ github.event.inputs.publish_image == 'true' }}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "commit_sha=${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
echo "image_tag=${VERSION}-${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
echo "publish=${PUBLISH}" >> "$GITHUB_OUTPUT"
echo "Versao: ${VERSION} | Commit: ${COMMIT_SHA} | Publicar: ${PUBLISH}"
- name: Construir Imagem Docker Local
run: |
docker build \
--build-arg VERSION=${{ steps.meta.outputs.image_tag }} \
-t evogo:ci-${{ steps.meta.outputs.commit_sha }} .
- name: Testar Inicializacao do Container
run: |
# O binario precisa subir e falhar apenas por falta de banco/config,
# nunca por erro de link (CGO/libwebp/libjpeg) ou arquivo ausente.
set +e
timeout 20 docker run --rm evogo:ci-${{ steps.meta.outputs.commit_sha }} > /tmp/run.log 2>&1
set -e
tail -20 /tmp/run.log
if grep -qiE "error while loading shared libraries|exec format error|exec /app/server" /tmp/run.log; then
echo "Falha ao iniciar o binario dentro da imagem"; exit 1
fi
docker run --rm --entrypoint sh evogo:ci-${{ steps.meta.outputs.commit_sha }} -c 'test -x /app/server && test -d /app/manager/dist && cat /app/VERSION'
- name: Verificar Vulnerabilidades (Trivy, nao bloqueante)
continue-on-error: true
run: |
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:latest \
image --severity HIGH,CRITICAL --ignore-unfixed --no-progress \
evogo:ci-${{ steps.meta.outputs.commit_sha }}
- name: Login no Gitea Package Registry
if: steps.meta.outputs.publish == 'true'
run: |
USER="${{ secrets.REGISTRY_USER }}"
[ -n "$USER" ] || USER="${{ github.actor }}"
TOKEN="${{ secrets.REGISTRY_TOKEN }}"
[ -n "$TOKEN" ] || TOKEN="${{ secrets.GITEA_TOKEN }}"
# O registry ja estourou timeout pontualmente (run 482); tenta de novo antes de falhar.
for n in 1 2 3 4 5; do
echo "$TOKEN" | docker login "$REGISTRY" -u "$USER" --password-stdin && exit 0
echo "Login falhou (tentativa $n/5); nova tentativa em $((n*15))s"
sleep $((n*15))
done
exit 1
- name: Publicar Imagens no Registry
if: steps.meta.outputs.publish == 'true'
run: |
push() {
for n in 1 2 3 4 5; do
docker push "$1" && return 0
echo "Push de $1 falhou (tentativa $n/5); nova tentativa em $((n*15))s"
sleep $((n*15))
done
return 1
}
SRC=evogo:ci-${{ steps.meta.outputs.commit_sha }}
for TAG in "${{ steps.meta.outputs.image_tag }}" "${{ steps.meta.outputs.version }}"; do
docker tag "$SRC" "$IMAGE:$TAG"
push "$IMAGE:$TAG"
echo "Publicado: $IMAGE:$TAG"
done
if [ "${{ github.event.inputs.promote_latest }}" = "true" ]; then
docker tag "$SRC" "$IMAGE:latest"
push "$IMAGE:latest"
echo "Publicado: $IMAGE:latest"
fi
- name: Limpeza
if: always()
run: docker image rm -f evogo:ci-${{ steps.meta.outputs.commit_sha }} >/dev/null 2>&1 || true