Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 47s
76 lines
3.0 KiB
YAML
76 lines
3.0 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
|
|
|
|
# --- Instalar Docker en el Entorno del Job ---
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends ca-certificates curl
|
|
install -m 0755 -d /etc/apt/keyrings
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
|
|
chmod a+r /etc/apt/keyrings/docker.asc
|
|
echo \
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
|
|
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
|
|
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
apt-get update
|
|
apt-get install -y docker-ce-cli
|
|
|
|
- name: Login to Gitea Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.ACTIONS_PAT }}
|
|
|
|
- name: Build and Push Backend Image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
file: Backend/GestionIntegral.Api/Dockerfile
|
|
push: true
|
|
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }}
|
|
|
|
- name: Build and Push Frontend Image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
file: Frontend/Dockerfile
|
|
push: true
|
|
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }}
|
|
|
|
- name: Deploy to Production
|
|
run: |
|
|
echo "Deploying to production server..."
|
|
# Ya no necesitamos instalar openssh-client, porque la imagen base ya lo tiene.
|
|
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
|
|
|
|
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
|
|
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 }}"
|
|
|
|
docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.ACTIONS_PAT }}
|
|
docker compose pull
|
|
docker compose up -d
|
|
docker image prune -af
|
|
|
|
echo "--- DESPLIEGUE COMPLETADO ---"
|
|
EOF |