Retry Kaniko
This commit is contained in:
		| @@ -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 }} | ||||||
|  |             --insecure | ||||||
|  |         env: | ||||||
|  |           REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}' | ||||||
|  |  | ||||||
|       - name: Build and Push Frontend Image |   # Creamos un segundo job para el despliegue, que depende del primero. | ||||||
|         uses: docker/build-push-action@v4 |   deploy: | ||||||
|         with: |     runs-on: ubuntu-latest | ||||||
|           context: . |     needs: build-and-push # Este job no se ejecuta hasta que el anterior termine con éxito. | ||||||
|           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 }} |  | ||||||
|      |      | ||||||
|  |     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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user