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 - main
jobs: jobs:
build-and-deploy: build-and-push: # Renombramos el job para que sea más claro
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
# --- Instalar Docker en el Entorno del Job --- # Ya no necesitamos login ni build por separado. Kaniko lo hace todo.
- name: Install Docker CLI - name: Build and Push Backend with Kaniko
run: | uses: gcr.io/kaniko-project/executor:v1.9.0
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
with: with:
registry: ${{ secrets.REGISTRY_URL }} # NOTA: Kaniko no usa "with:". Pasamos los argumentos directamente.
username: ${{ secrets.REGISTRY_USER }} # Esta es la sintaxis correcta para Gitea Actions.
password: ${{ secrets.ACTIONS_PAT }} # ¡¡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 - name: Build and Push Frontend with Kaniko
uses: docker/build-push-action@v4 uses: gcr.io/kaniko-project/executor:v1.9.0
with: with:
context: . kaniko-args: >-
file: Backend/GestionIntegral.Api/Dockerfile --context=${{ gitea.workspace }}
push: true --dockerfile=${{ gitea.workspace }}/Frontend/Dockerfile
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 }} --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 }}
- name: Build and Push Frontend Image --insecure
uses: docker/build-push-action@v4 env:
with: REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}'
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 }}
# 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 - name: Deploy to Production
run: | run: |
echo "Deploying to production server..." 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 mkdir -p ~/.ssh
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa