Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 19s
83 lines
3.1 KiB
YAML
83 lines
3.1 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
|
|
|
|
# --- NUEVO PASO: PREPARAMOS UN DIRECTORIO DE SALIDA PERSISTENTE ---
|
|
- name: Create output directory
|
|
run: mkdir -p ${{ gitea.workspace }}/output
|
|
|
|
- name: Build Backend Image and Save to Output
|
|
run: |
|
|
docker run --rm \
|
|
-v ${{ gitea.workspace }}:/workspace \
|
|
-v ${{ gitea.workspace }}/output:/output \
|
|
gcr.io/kaniko-project/executor:v1.9.0 \
|
|
--context=/workspace \
|
|
--dockerfile=/workspace/Backend/GestionIntegral.Api/Dockerfile \
|
|
--no-push \
|
|
--destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest \
|
|
--tarPath=/output/backend.tar
|
|
|
|
- name: Build Frontend Image and Save to Output
|
|
run: |
|
|
docker run --rm \
|
|
-v ${{ gitea.workspace }}:/workspace \
|
|
-v ${{ gitea.workspace }}/output:/output \
|
|
gcr.io/kaniko-project/executor:v1.9.0 \
|
|
--context=/workspace \
|
|
--dockerfile=/workspace/Frontend/Dockerfile \
|
|
--no-push \
|
|
--destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest \
|
|
--tarPath=/output/frontend.tar
|
|
|
|
- name: Verify Artifacts
|
|
run: |
|
|
echo "--- Verifying contents of output directory ---"
|
|
ls -l ${{ gitea.workspace }}/output
|
|
|
|
- name: Deploy to Production via SCP and 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 "Copying image files to production server..."
|
|
# Ahora copiamos desde el subdirectorio 'output'
|
|
scp ${{ gitea.workspace }}/output/backend.tar ${{ gitea.workspace }}/output/frontend.tar ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }}:/opt/gestion-integral/
|
|
|
|
echo "Connecting to host to load images and deploy..."
|
|
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
|
|
set -e
|
|
echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---"
|
|
cd /opt/gestion-integral
|
|
|
|
echo "Loading images into Docker..."
|
|
docker load < backend.tar
|
|
docker load < frontend.tar
|
|
|
|
echo "Starting application stack..."
|
|
export DB_SA_PASSWORD="${{ secrets.DB_SA_PASSWORD_SECRET }}"
|
|
export JWT_KEY="${{ secrets.JWT_KEY_SECRET }}"
|
|
docker compose up -d
|
|
|
|
echo "Cleaning up tar files and old images..."
|
|
rm backend.tar frontend.tar
|
|
docker image prune -af
|
|
|
|
echo "--- ¡¡DESPLIEGUE COMPLETADO Y VERIFICADO!! ---"
|
|
EOF |