Retry Kaniko
Some checks failed
Build and Deploy / build-and-push (push) Failing after 7s
Build and Deploy / deploy (push) Has been skipped

This commit is contained in:
2025-06-17 09:58:48 -03:00
parent 8f488405ee
commit 98c2593bf0

View File

@@ -6,55 +6,53 @@ on:
- main
jobs:
build-and-deploy:
build-and-push: # Renombramos el job para que sea más claro
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# --- Instalar Docker en el Entorno del Job ---
- name: Install Docker CLI
run: |
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce-cli
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
# Ya no necesitamos login ni build por separado. Kaniko lo hace todo.
- name: Build and Push Backend with Kaniko
uses: gcr.io/kaniko-project/executor:v1.9.0
with:
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.ACTIONS_PAT }}
# NOTA: Kaniko no usa "with:". Pasamos los argumentos directamente.
# Esta es la sintaxis correcta para Gitea Actions.
# ¡¡IMPORTANTE!! Pasamos los secretos como variables de entorno al contenedor.
kaniko-args: >-
--context=${{ gitea.workspace }}
--dockerfile=${{ gitea.workspace }}/Backend/GestionIntegral.Api/Dockerfile
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }}
--insecure
env:
# Kaniko necesita las credenciales como un archivo de configuración.
# Esta es la forma estándar de crearlo al vuelo.
REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}'
- name: Build and Push Backend Image
uses: docker/build-push-action@v4
- name: Build and Push Frontend with Kaniko
uses: gcr.io/kaniko-project/executor:v1.9.0
with:
context: .
file: Backend/GestionIntegral.Api/Dockerfile
push: true
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }}
- name: Build and Push Frontend Image
uses: docker/build-push-action@v4
with:
context: .
file: Frontend/Dockerfile
push: true
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }}
kaniko-args: >-
--context=${{ gitea.workspace }}
--dockerfile=${{ gitea.workspace }}/Frontend/Dockerfile
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }}
--insecure
env:
REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}'
# Creamos un segundo job para el despliegue, que depende del primero.
deploy:
runs-on: ubuntu-latest
needs: build-and-push # Este job no se ejecuta hasta que el anterior termine con éxito.
steps:
- name: Deploy to Production
run: |
echo "Deploying to production server..."
# Ya no necesitamos instalar openssh-client, porque la imagen base ya lo tiene.
apk add --no-cache openssh-client
mkdir -p ~/.ssh
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa