Some checks failed
		
		
	
	Optimized Build and Deploy / remote-build-and-deploy (push) Failing after 1m25s
				
			
		
			
				
	
	
		
			79 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
| name: Optimized Build and Deploy
 | |
| 
 | |
| on:
 | |
|   push:
 | |
|     branches:
 | |
|       - main
 | |
| 
 | |
| jobs:
 | |
|   remote-build-and-deploy:
 | |
|     runs-on: ubuntu-latest
 | |
| 
 | |
|     steps:
 | |
|       - name: Run Optimized CI/CD Process on Host via SSH
 | |
|         run: |
 | |
|           set -e
 | |
|           
 | |
|           # Configura SSH
 | |
|           apt-get update -qq && apt-get install -y openssh-client git
 | |
|           mkdir -p ~/.ssh
 | |
|           echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
 | |
|           chmod 600 ~/.ssh/id_rsa
 | |
|           ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
 | |
|           
 | |
|           # Ejecuta en el host remoto
 | |
|           ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOSSH'
 | |
|             set -e
 | |
|             echo "--- INICIO DEL DESPLIEGUE OPTIMIZADO ---"
 | |
|             
 | |
|             # 1. Preparar entorno
 | |
|             TEMP_DIR=$(mktemp -d)
 | |
|             REPO_OWNER="dmolinari"
 | |
|             REPO_NAME="gestionintegralweb"
 | |
|             GITEA_REPO_PATH="/var/lib/docker/volumes/gitea-stack_gitea-data/_data/git/repositories/${REPO_OWNER}/${REPO_NAME}.git"
 | |
|             
 | |
|             echo "Clonando repositorio desde: $GITEA_REPO_PATH ..."
 | |
|             git clone "$GITEA_REPO_PATH" "$TEMP_DIR"
 | |
|             cd "$TEMP_DIR"
 | |
|             git checkout "${{ gitea.sha }}"
 | |
|             
 | |
|             # 2. Construcción paralela con Docker nativo (más rápido y fiable)
 | |
|             build_image() {
 | |
|               local dockerfile=$1
 | |
|               local image_name=$2
 | |
|               local context=$3
 | |
|               
 | |
|               echo "Construyendo $image_name..."
 | |
|               docker build \
 | |
|                 -t "$image_name" \
 | |
|                 -f "$dockerfile" \
 | |
|                 "$context"
 | |
|             }
 | |
|             
 | |
|             echo "Construyendo imágenes en paralelo..."
 | |
|             (build_image "Backend/GestionIntegral.Api/Dockerfile" "dmolinari/gestionintegralweb-backend:latest" ".") &
 | |
|             (build_image "Frontend/Dockerfile" "dmolinari/gestionintegralweb-frontend:latest" ".") &
 | |
|             wait
 | |
|             
 | |
|             # 3. Despliegue con Docker Compose
 | |
|             cd /opt/gestion-integral
 | |
|             export DB_SA_PASSWORD='${{ secrets.DB_SA_PASSWORD_SECRET }}'
 | |
|             
 | |
|             # Pasa el secreto de Gitea a un Docker Secret
 | |
|             # El comando "tr -d '\n'" elimina cualquier salto de línea final
 | |
|             printf "%s" "${{ secrets.JWT_KEY }}" | tr -d '\n' | docker secret create jwt_secret_key - || docker secret inspect jwt_secret_key > /dev/null
 | |
|             
 | |
|             echo "Desplegando el stack..."
 | |
|             docker stack deploy \
 | |
|               -c /opt/gestion-integral/docker-compose.yml \
 | |
|               --with-registry-auth \
 | |
|               gestion-integral
 | |
|             
 | |
|             # 4. Limpieza
 | |
|             echo "Realizando limpieza..."
 | |
|             rm -rf "$TEMP_DIR"
 | |
|             docker image prune -af --filter "until=24h"
 | |
|             
 | |
|             echo "--- DESPLIEGUE COMPLETADO CON ÉXITO ---"
 | |
|             echo "Tiempo total: $(($SECONDS / 60)) minutos y $(($SECONDS % 60)) segundos"
 | |
|           EOSSH |