Retry 1149
Some checks failed
Build and Deploy / build-and-push (push) Successful in 17s
Build and Deploy / deploy (push) Failing after 11s

This commit is contained in:
2025-06-17 11:49:04 -03:00
parent 45c8742906
commit b3ed6f6c21

View File

@@ -7,7 +7,7 @@ on:
jobs: jobs:
# =================================================================== # ===================================================================
# JOB 1: CONSTRUIR Y SUBIR LAS IMÁGENES (FUNCIONA PERFECTAMENTE) # JOB 1: CONSTRUIR Y SUBIR LAS IMÁGENES
# =================================================================== # ===================================================================
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -24,7 +24,7 @@ jobs:
docker run --rm -v ${{ gitea.workspace }}:/workspace -v ${{ gitea.workspace }}/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 docker run --rm -v ${{ gitea.workspace }}:/workspace -v ${{ gitea.workspace }}/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
# =================================================================== # ===================================================================
# JOB 2: DESPLEGAR LA APLICACIÓN (LA SOLUCIÓN FINAL Y ROBUSTA) # JOB 2: DESPLEGAR LA APLICACIÓN
# =================================================================== # ===================================================================
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -33,27 +33,32 @@ jobs:
steps: steps:
- name: Deploy to Production via SSH - name: Deploy to Production via SSH
run: | run: |
# Preparamos el cliente SSH como antes set -e # Fallar inmediatamente si algo sale mal
echo "Preparing SSH client..."
apt-get update && apt-get install -y openssh-client apt-get update && apt-get install -y 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
ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
# Creamos el script de despliegue como una única cadena echo "Connecting to host to execute deployment..."
# Usamos '&&' para encadenar comandos y asegurar que falle si algo sale mal ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
DEPLOY_SCRIPT=" set -e # También aquí, para fallar en la sesión remota
set -e; \
echo '--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---'; \
cd /opt/gestion-integral; \
export DB_SA_PASSWORD='${{ secrets.DB_SA_PASSWORD_SECRET }}'; \
export JWT_KEY='${{ secrets.JWT_KEY_SECRET }}'; \
echo '${{ secrets.ACTIONS_PAT }}' | docker login ${{ secrets.REGISTRY_URL }} -u '${{ secrets.REGISTRY_USER }}' --password-stdin; \
docker compose pull; \
docker compose up -d; \
docker image prune -af; \
echo '--- ¡¡DESPLIEGUE COMPLETADO Y VERIFICADO!! ---'; \
"
# Ejecutamos el script remoto echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---"
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} "$DEPLOY_SCRIPT" cd /opt/gestion-integral
export DB_SA_PASSWORD="${{ secrets.DB_SA_PASSWORD_SECRET }}"
export JWT_KEY="${{ secrets.JWT_KEY_SECRET }}"
# La clave: El host se conecta a sí mismo usando la dirección de loopback.
# Gracias al MTU en daemon.json, esta conexión ahora será estable.
echo "${{ secrets.ACTIONS_PAT }}" | docker login 127.0.0.1:5000 -u ${{ secrets.REGISTRY_USER }} --password-stdin
docker compose pull
docker compose up -d
docker image prune -af
echo "--- ¡¡DESPLIEGUE COMPLETADO Y VERIFICADO!! ---"
EOF