Some checks failed
Optimized Build and Deploy / remote-build-and-deploy (push) Failing after 1m19s
85 lines
3.7 KiB
YAML
85 lines
3.7 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 (sin cambios)
|
|
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 (sin cambios)
|
|
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
|
|
|
|
# Copiamos la versión actualizada del docker-compose.yml al directorio de despliegue.
|
|
echo "Copiando el archivo docker-compose.yml actualizado..."
|
|
cp "$TEMP_DIR/docker-compose.yml" /opt/gestion-integral/docker-compose.yml
|
|
|
|
# (Opcional pero recomendado) Verificamos que el archivo se copió bien
|
|
echo "--- Verificando contenido del docker-compose.yml que se usará ---"
|
|
cat /opt/gestion-integral/docker-compose.yml | head -n 5
|
|
echo "------------------------------------------------------------------"
|
|
|
|
# 3. Crear/Actualizar los Docker Secrets (sin cambios)
|
|
# ... (tus comandos docker secret create) ...
|
|
printf "%s" '${{ secrets.JWT_KEY }}' | docker secret create jwt_key - 2>/dev/null || (printf "%s" '${{ secrets.JWT_KEY }}' | docker secret rm jwt_key && printf "%s" '${{ secrets.JWT_KEY }}' | docker secret create jwt_key -)
|
|
printf "%s" '${{ secrets.DB_SA_PASSWORD_SECRET }}' | docker secret create db_password - 2>/dev/null || (printf "%s" '${{ secrets.DB_SA_PASSWORD_SECRET }}' | docker secret rm db_password && printf "%s" '${{ secrets.DB_SA_PASSWORD_SECRET }}' | docker secret create db_password -)
|
|
|
|
# 4. Desplegar el Stack
|
|
echo "Desplegando el stack..."
|
|
docker stack deploy \
|
|
-c /opt/gestion-integral/docker-compose.yml \
|
|
--with-registry-auth \
|
|
gestion-integral
|
|
|
|
# 5. Limpieza (sin cambios)
|
|
echo "Realizando limpieza..."
|
|
rm -rf "$TEMP_DIR"
|
|
docker image prune -af --filter "until=24h"
|
|
|
|
echo "--- DESPLIEGUE COMPLETADO CON ÉXITO ---"
|
|
EOSSH |