Fix de yml para Drone.
This commit is contained in:
58
.drone.yml
58
.drone.yml
@@ -1,68 +1,46 @@
|
|||||||
# .drone.yml
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: Build y Deploy
|
name: Build y Deploy
|
||||||
|
|
||||||
# --- DISPARADOR (TRIGGER) ---
|
|
||||||
# Este pipeline se ejecutará solo cuando hagas push a la rama 'main'
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
|
|
||||||
# --- PASOS DEL PIPELINE ---
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
# --- PASO 1: CONSTRUIR LA IMAGEN DEL BACKEND ---
|
|
||||||
- name: build-and-publish-backend
|
- name: build-and-publish-backend
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
# --- Configuración del Registro ---
|
|
||||||
# Usamos el registro de Gitea. El valor viene de los secretos de Drone.
|
|
||||||
registry:
|
registry:
|
||||||
from_secret: REGISTRY_URL
|
from_secret: REGISTRY_URL
|
||||||
# Drone inyecta automáticamente un secreto para autenticarse en el registro.
|
|
||||||
# Usaremos un PAT (Token de Acceso Personal) de Gitea.
|
|
||||||
username:
|
username:
|
||||||
from_secret: GITEA_USER
|
from_secret: GITEA_USER
|
||||||
password:
|
password:
|
||||||
from_secret: ACTIONS_PAT
|
from_secret: ACTIONS_PAT
|
||||||
|
|
||||||
# --- Configuración de la Imagen ---
|
|
||||||
# El nombre de la imagen en el registro.
|
|
||||||
repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend
|
repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-backend
|
||||||
# El Dockerfile a usar.
|
|
||||||
dockerfile: Backend/GestionIntegral.Api/Dockerfile
|
dockerfile: Backend/GestionIntegral.Api/Dockerfile
|
||||||
# Las etiquetas que le pondremos a la imagen.
|
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${{DRONE_COMMIT_SHA:0:8}} # Etiqueta con el hash corto del commit
|
- ${{DRONE_COMMIT_SHA:0:8}}
|
||||||
|
|
||||||
# --- PASO 2: CONSTRUIR LA IMAGEN DEL FRONTEND ---
|
|
||||||
- name: build-and-publish-frontend
|
- name: build-and-publish-frontend
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
# La configuración del registro es la misma
|
|
||||||
registry:
|
registry:
|
||||||
from_secret: REGISTRY_URL
|
from_secret: REGISTRY_URL
|
||||||
username:
|
username:
|
||||||
from_secret: GITEA_USER
|
from_secret: GITEA_USER
|
||||||
password:
|
password:
|
||||||
from_secret: ACTIONS_PAT
|
from_secret: ACTIONS_PAT
|
||||||
|
|
||||||
# --- Configuración de la Imagen ---
|
|
||||||
repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-frontend
|
repo: ${{DRONE_REPO_OWNER}}/${{DRONE_REPO_NAME}}-frontend
|
||||||
dockerfile: Frontend/Dockerfile
|
dockerfile: Frontend/Dockerfile
|
||||||
# Las etiquetas para la imagen del frontend.
|
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${{DRONE_COMMIT_SHA:0:8}}
|
- ${{DRONE_COMMIT_SHA:0:8}}
|
||||||
# Este paso depende del anterior para no ejecutarse en paralelo
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- build-and-publish-backend
|
- build-and-publish-backend
|
||||||
|
|
||||||
# --- PASO 3: DESPLEGAR LA APLICACIÓN ---
|
|
||||||
- name: deploy-to-production
|
- name: deploy-to-production
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
@@ -72,28 +50,24 @@ steps:
|
|||||||
from_secret: PROD_SERVER_USER
|
from_secret: PROD_SERVER_USER
|
||||||
key:
|
key:
|
||||||
from_secret: PROD_SERVER_SSH_KEY
|
from_secret: PROD_SERVER_SSH_KEY
|
||||||
|
environment:
|
||||||
# --- Comandos a ejecutar en el servidor de producción ---
|
SA_PASSWORD:
|
||||||
script:
|
from_secret: DB_SA_PASSWORD_SECRET
|
||||||
# Navegamos a la carpeta donde está el docker-compose.yml de la aplicación
|
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:
|
||||||
- cd /opt/gestion-integral
|
- cd /opt/gestion-integral
|
||||||
|
- export DB_SA_PASSWORD=$SA_PASSWORD
|
||||||
# Exportamos los secretos que necesita el docker-compose.yml
|
- export JWT_KEY=$JWT_KEY
|
||||||
- export DB_SA_PASSWORD=$${DB_SA_PASSWORD_SECRET} # Nota los $$ para escapar
|
- docker login $REGISTRY -u $GITEA_USER -p $GITEA_PAT
|
||||||
- export JWT_KEY=$${JWT_KEY_SECRET}
|
|
||||||
|
|
||||||
# Login al registro de Gitea DENTRO del servidor de producción
|
|
||||||
- docker login $${REGISTRY_URL_SECRET} -u $${GITEA_USER_SECRET} -p $${ACTIONS_PAT_SECRET}
|
|
||||||
|
|
||||||
# Descargamos las nuevas versiones de las imágenes
|
|
||||||
- docker compose pull
|
- docker compose pull
|
||||||
|
|
||||||
# Levantamos el stack con los cambios
|
|
||||||
- docker compose up -d
|
- docker compose up -d
|
||||||
|
|
||||||
# Limpiamos imágenes viejas que ya no se usan
|
|
||||||
- docker image prune -af
|
- docker image prune -af
|
||||||
|
|
||||||
# Este paso depende de que las dos imágenes se hayan construido
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- build-and-publish-frontend
|
- build-and-publish-frontend
|
||||||
Reference in New Issue
Block a user