Files
GestionIntegralWeb/.drone.yml
2025-06-16 18:50:31 -03:00

87 lines
2.3 KiB
YAML

kind: pipeline
type: docker
name: Build y Deploy
trigger:
branch:
- main
event:
- push
steps:
- name: build-and-publish-backend
image: gcr.io/kaniko-project/executor:v1.9.0-debug
settings:
# El nombre del campo debe ser "repo" para el destino principal,
# y "tags" para las adicionales. El plugin de Drone lo traduce internamente para Kaniko.
repo: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend
tags:
- latest
- ${DRONE_COMMIT_SHA:0:8}
dockerfile: Backend/GestionIntegral.Api/Dockerfile
context: .
# Las credenciales y la flag de inseguro se mantienen
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
insecure: true
- name: build-and-publish-frontend
image: gcr.io/kaniko-project/executor:v1.9.0-debug
settings:
# Misma estructura para el frontend
repo: 192.168.4.128:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend
tags:
- latest
- ${DRONE_COMMIT_SHA:0:8}
dockerfile: Frontend/Dockerfile
context: .
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
insecure: true
depends_on:
- build-and-publish-backend
- name: deploy-to-production
# Este paso no cambia en absoluto
image: alpine:latest
environment:
SSH_KEY:
from_secret: PROD_SERVER_SSH_KEY
PROD_HOST:
from_secret: PROD_SERVER_HOST
PROD_USER:
from_secret: PROD_SERVER_USER
DB_PASSWORD:
from_secret: DB_SA_PASSWORD_SECRET
JWT_KEY:
from_secret: JWT_KEY_SECRET
REGISTRY:
from_secret: REGISTRY_URL
GITEA_USER:
from_secret: GITEA_USER
GITEA_PAT:
from_secret: ACTIONS_PAT
commands:
- apk add --no-cache openssh-client
- mkdir -p ~/.ssh
- echo "$SSH_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H $PROD_HOST >> ~/.ssh/known_hosts
- |
ssh $PROD_USER@$PROD_HOST << 'EOF'
echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---"
cd /opt/gestion-integral
export DB_SA_PASSWORD="${DB_PASSWORD}"
export JWT_KEY="${JWT_KEY}"
docker login ${REGISTRY} -u ${GITEA_USER} -p ${GITEA_PAT}
docker compose pull
docker compose up -d
docker image prune -af
echo "--- DESPLIEGUE COMPLETADO ---"
EOF
depends_on:
- build-and-publish-frontend