Files
escuadron-1/.gitea/workflows/build.yaml
T
2026-11-22 19:01:10 +00:00

53 lines
2.0 KiB
YAML

# Cada push a main: construye y publica las imágenes de api y web en el registro de Gitea
# y actualiza el tag en k8s/kustomization.yaml (commit del bot) para que Argo CD despliegue.
name: publicar
on:
push:
branches: [main]
paths-ignore: ["k8s/kustomization.yaml", "**.md"]
env:
# Registro de imágenes: el nombre PÚBLICO de Gitea (el runner habla con Gitea por su dirección interna, sin TLS)
HOST: gitea.tallerprompt.org
jobs:
publicar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Preparar variables
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
echo "TAG=$(git rev-parse --short=8 HEAD)" >> "$GITHUB_ENV"
- name: Construir y publicar imágenes
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
run: |
set -euo pipefail
echo "$REGISTRY_TOKEN" | docker login "$HOST" -u ci-bot --password-stdin
docker build -t "$HOST/$REPO/api:$TAG" -f api/Dockerfile .
docker build -t "$HOST/$REPO/web:$TAG" web
docker push "$HOST/$REPO/api:$TAG"
docker push "$HOST/$REPO/web:$TAG"
- name: Desplegar (nuevo tag en k8s/kustomization.yaml)
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
run: |
set -euo pipefail
REMOTO="https://ci-bot:${REGISTRY_TOKEN}@${HOST}/${GITHUB_REPOSITORY}.git"
git config user.name "ci-bot"
git config user.email "ci-bot@taller.local"
for intento in 1 2 3 4 5; do
git fetch -q "$REMOTO" main && git checkout -q -B main FETCH_HEAD
sed -i -E "s/^( *newTag: ).*/\1\"$TAG\"/" k8s/kustomization.yaml
git commit -qam "despliegue $TAG [skip ci]" || { echo "Nada que desplegar"; exit 0; }
git push -q "$REMOTO" HEAD:main && { echo "Desplegando $TAG"; exit 0; }
echo "Otro push se adelantó; reintento ($intento)"; sleep 3
done
exit 1