All checks were successful
Optimized Build and Deploy / remote-build-and-deploy (push) Successful in 6m15s
71 lines
2.5 KiB
YAML
71 lines
2.5 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 (sin cambios)
|
|
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
|
|
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 }}'
|
|
|
|
echo "Recreando servicios de la aplicación..."
|
|
docker compose up -d --force-recreate
|
|
|
|
# 4. Limpieza
|
|
echo "Realizando limpieza..."
|
|
rm -rf "$TEMP_DIR"
|
|
docker image prune -f --filter "dangling=true"
|
|
|
|
echo "--- DESPLIEGUE COMPLETADO CON ÉXITO ---"
|
|
EOSSH |