Compare commits
50 Commits
b66d00c92d
...
8101756638
| Author | SHA1 | Date | |
|---|---|---|---|
| 8101756638 | |||
| b33dd4f94f | |||
| ba9bef2364 | |||
| 856d7ac5c1 | |||
| d8dc41222c | |||
| a434640456 | |||
| fcc2b90f15 | |||
| 0d7614ef4c | |||
| ae54ef3fe5 | |||
| c361842a91 | |||
| de079d8bd4 | |||
| 401e61e0eb | |||
| 4b208793ce | |||
| d60dd8dc9f | |||
| 8156df9f90 | |||
| 55ca8bffa7 | |||
| 02265a46e7 | |||
| 767cd081dc | |||
| 97b6a9241f | |||
| b68ac1fed1 | |||
| 2e83c2e373 | |||
| 1e8d5fd308 | |||
| a1dfd0d089 | |||
| eff65921e6 | |||
| b3de8dba3a | |||
| f62fc4b507 | |||
| 66686fc548 | |||
| c0900e07e6 | |||
| a63b40471b | |||
| 12decefc1b | |||
| bb79ccf64c | |||
| b3e70a3988 | |||
| 55640c394f | |||
| 338cd8579f | |||
| 69620c5607 | |||
| 8ba18ed687 | |||
| 30570beaca | |||
| db10fa0254 | |||
| 1d664672b2 | |||
| 969c78a567 | |||
| 0b884197fb | |||
| 0d2c30ad94 | |||
| f1591bd572 | |||
| 24e4769f78 | |||
| 76d48cc310 | |||
| b072e31385 | |||
| 65be2bcbaa | |||
| 0fb3cb7aef | |||
| 541625bf66 | |||
| cbe313b59d |
82
.drone.yml
Normal file
82
.drone.yml
Normal file
@@ -0,0 +1,82 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Build y Deploy
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: build-and-publish-backend
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: host.docker.internal:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_COMMIT_SHA:0:8}
|
||||
dockerfile: Backend/GestionIntegral.Api/Dockerfile
|
||||
context: .
|
||||
username:
|
||||
from_secret: GITEA_USER
|
||||
password:
|
||||
from_secret: ACTIONS_PAT
|
||||
insecure: true
|
||||
|
||||
- name: build-and-publish-frontend
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: host.docker.internal: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
|
||||
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
|
||||
@@ -1,29 +1,37 @@
|
||||
# --- Etapa 1: Build ---
|
||||
# Usamos el SDK de .NET 9 (o el que corresponda) para compilar.
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# Copia solo los archivos de proyecto primero para cachear dependencias
|
||||
# Copiamos los archivos de proyecto (.sln y .csproj) y restauramos las dependencias.
|
||||
# Esto es una optimización de caché de Docker.
|
||||
COPY GestionIntegralWeb.sln .
|
||||
COPY Backend/GestionIntegral.Api/GestionIntegral.Api.csproj Backend/GestionIntegral.Api/
|
||||
|
||||
# Restaura dependencias
|
||||
# Restauramos los paquetes NuGet.
|
||||
RUN dotnet restore "GestionIntegralWeb.sln"
|
||||
|
||||
# Copia el resto del código
|
||||
# Copiamos todo el resto del código fuente.
|
||||
COPY . .
|
||||
|
||||
# Construye el proyecto
|
||||
# Nos movemos al directorio del proyecto y lo construimos en modo Release.
|
||||
WORKDIR "/src/Backend/GestionIntegral.Api"
|
||||
RUN dotnet build "GestionIntegral.Api.csproj" -c Release -o /app/build
|
||||
|
||||
# --- Etapa 2: Publish ---
|
||||
# Publicamos la aplicación, lo que genera los artefactos listos para producción.
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "GestionIntegral.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# --- Etapa 3: Final ---
|
||||
# Usamos la imagen de runtime de ASP.NET, que es mucho más ligera que el SDK.
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
|
||||
# El puerto en el que la API escuchará DENTRO del contenedor.
|
||||
# Usaremos 8080 para evitar conflictos si en el futuro corres algo en el puerto 80.
|
||||
EXPOSE 8080
|
||||
|
||||
# El comando para iniciar la API cuando el contenedor arranque.
|
||||
ENTRYPOINT ["dotnet", "GestionIntegral.Api.dll"]
|
||||
@@ -6,6 +6,7 @@
|
||||
}
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "",
|
||||
"Issuer": "GestionIntegralApi",
|
||||
"Audience": "GestionIntegralClient",
|
||||
"DurationInHours": 8
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
# --- Etapa 1: Build ---
|
||||
# Usamos una imagen de Node.js para construir los archivos estáticos de React.
|
||||
FROM node:20-alpine AS build
|
||||
WORKDIR /app
|
||||
|
||||
# Copia solo dependencias primero para cachear
|
||||
COPY Frontend/package.json Frontend/package-lock.json ./
|
||||
RUN npm install --frozen-lockfile
|
||||
# Copiamos los archivos de dependencias y las instalamos.
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copia el resto del código
|
||||
COPY Frontend/. .
|
||||
# Copiamos el resto del código del frontend.
|
||||
COPY . .
|
||||
|
||||
# Construye la aplicación
|
||||
# Ejecutamos el script de build de Vite, que genera la carpeta 'dist'.
|
||||
RUN npm run build
|
||||
|
||||
# --- Etapa 2: Serve ---
|
||||
# Usamos una imagen de Nginx súper ligera para servir los archivos estáticos.
|
||||
FROM nginx:stable-alpine
|
||||
COPY Frontend/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
WORKDIR /usr/share/nginx/html
|
||||
|
||||
# Eliminamos el index.html por defecto de Nginx.
|
||||
RUN rm -f index.html
|
||||
|
||||
# Copiamos los archivos construidos desde la etapa anterior a la carpeta que Nginx sirve.
|
||||
COPY --from=build /app/dist .
|
||||
|
||||
# Nginx por defecto escucha en el puerto 80, así que lo exponemos.
|
||||
EXPOSE 80
|
||||
|
||||
# Comando para iniciar Nginx. Esto asegura que se mantenga corriendo.
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user