Files
GestionIntegralWeb/.drone.yml

104 lines
2.4 KiB
YAML
Raw Normal View History

2025-06-15 23:06:51 -03:00
kind: pipeline
type: docker
name: Build y Deploy
volumes:
- name: dockersock
host:
path: /var/run/docker.sock
2025-06-15 23:06:51 -03:00
trigger:
branch:
2025-06-16 01:42:57 -03:00
- main
2025-06-15 23:06:51 -03:00
event:
2025-06-16 01:42:57 -03:00
- push
2025-06-15 23:06:51 -03:00
steps:
- name: build-and-publish-backend
image: plugins/docker
volumes:
- name: dockersock
path: /var/run/docker.sock
2025-06-15 23:06:51 -03:00
settings:
registry:
from_secret: REGISTRY_URL
repo: ${REGISTRY_URL}/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend
2025-06-15 23:06:51 -03:00
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
dockerfile: Backend/GestionIntegral.Api/Dockerfile
tags:
- latest
2025-06-15 23:10:37 -03:00
- ${DRONE_COMMIT_SHA:0:8}
insecure: true
2025-06-16 12:48:22 -03:00
- name: build-and-publish-frontend
image: plugins/docker
volumes:
- name: dockersock
path: /var/run/docker.sock
settings:
registry:
from_secret: REGISTRY_URL
repo: ${REGISTRY_URL}/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend
2025-06-16 12:48:22 -03:00
username:
from_secret: GITEA_USER
password:
from_secret: ACTIONS_PAT
dockerfile: Frontend/Dockerfile
tags:
- latest
- ${DRONE_COMMIT_SHA:0:8}
insecure: true
depends_on:
- build-and-publish-backend
2025-06-15 23:06:51 -03:00
- name: deploy-to-production
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:
# Preparar el entorno SSH
- 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
# Ejecutar comandos remotos
- |
ssh $PROD_USER@$PROD_HOST << 'EOF'
echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---"
cd /opt/gestion-integral
# Exportamos las variables que necesita el docker-compose de la app
export DB_SA_PASSWORD="${DB_PASSWORD}"
export JWT_KEY="${JWT_KEY}"
2025-06-15 22:57:24 -03:00
2025-06-15 23:06:51 -03:00
# Login, pull y deploy
docker login ${REGISTRY} -u ${GITEA_USER} -p ${GITEA_PAT}
docker compose pull
docker compose up -d
docker image prune -af
2025-06-15 22:57:24 -03:00
2025-06-15 23:06:51 -03:00
echo "--- DESPLIEGUE COMPLETADO ---"
EOF
depends_on:
2025-06-16 03:07:17 -03:00
- build-and-publish-frontend