From 631a094c8c54a643c1e72c5c28b598fa8c599db2 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Tue, 17 Jun 2025 10:00:18 -0300 Subject: [PATCH] Fix Kaniko --- .gitea/workflows/deploy.yml | 63 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index a47dc14..e763dbf 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -6,52 +6,53 @@ on: - main jobs: - build-and-push: # Renombramos el job para que sea más claro + build-and-push: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - # 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: - # 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: Create Kaniko config file + run: | + echo '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}' > /kaniko/config.json + # Este comando crea el fichero de credenciales que Kaniko necesita. + # Lo creamos en un directorio que montaremos en el siguiente paso. - - name: Build and Push Frontend with Kaniko - uses: gcr.io/kaniko-project/executor:v1.9.0 - with: - 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 }} + - name: Build and Push Backend + run: | + docker run --rm \ + -v ${{ gitea.workspace }}:/workspace \ + -v /kaniko/config.json:/kaniko/.docker/config.json \ + gcr.io/kaniko-project/executor:v1.9.0 \ + --context=/workspace \ + --dockerfile=/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 + + - name: Build and Push Frontend + run: | + docker run --rm \ + -v ${{ gitea.workspace }}:/workspace \ + -v /kaniko/config.json:/kaniko/.docker/config.json \ + gcr.io/kaniko-project/executor:v1.9.0 \ + --context=/workspace \ + --dockerfile=/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. + needs: build-and-push steps: - name: Deploy to Production run: | - echo "Deploying to production server..." + # Este paso no necesita cambios, pero para mantenerlo simple, + # lo ejecutaremos directamente sin la acción de checkout, + # ya que no necesita los ficheros del repositorio. apk add --no-cache openssh-client mkdir -p ~/.ssh echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa