Files
GestionIntegralWeb/.gitea/workflows/deploy.yml
dmolinari 34e98b283f
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 32s
Retry 1246
2025-06-17 12:46:32 -03:00

70 lines
2.5 KiB
YAML

name: Build and Deploy
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# Ya no necesitamos crear config.json. La acción de login lo maneja.
- name: Login to Gitea Registry
uses: docker/login-action@v2
with:
registry: 127.0.0.1:5000
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.ACTIONS_PAT }}
- name: Build and Push Backend
uses: docker/build-push-action@v4
with:
context: .
file: Backend/GestionIntegral.Api/Dockerfile
push: true
# La imagen se etiqueta para el registro local
tags: 127.0.0.1:5000/dmolinari/gestionintegralweb-backend:latest,127.0.0.1:5000/dmolinari/gestionintegralweb-backend:${{ gitea.sha_short }}
- name: Build and Push Frontend
uses: docker/build-push-action@v4
with:
context: .
file: Frontend/Dockerfile
push: true
tags: 127.0.0.1:5000/dmolinari/gestionintegralweb-frontend:latest,127.0.0.1:5000/dmolinari/gestionintegralweb-frontend:${{ gitea.sha_short }}
# El despliegue ahora es un paso final en el mismo job
- name: Deploy to Production via SSH
run: |
set -e
echo "Preparing SSH client..."
apt-get update && apt-get install -y openssh-client
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
echo "Connecting to host to deploy..."
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
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 }}"
# El login ya no es necesario aquí, el demonio ya tiene la sesión
# del paso anterior del pipeline. Pero lo dejamos por robustez.
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