mirror of
https://github.com/siop-spelev/siop2.git
synced 2026-08-08 12:41:54 +00:00
build(r0.13): Dockerfiles api/web + compose Dokploy + runbook — R0 prêt à déployer
- image api : multi-stage (pnpm deploy --legacy --prod), client Prisma régénéré dans l'arborescence déployée, binaryTargets explicites (debian/arm64 openssl-3), entrypoint migrate deploy → seed optionnel (SEED_ON_START, compilé dist/seed) → API ; non-root, healthcheck /health - image web : nginx alpine, statique Vite, proxy /api résolu À LA REQUÊTE (resolver Docker + variable — nginx démarre sans l'API), fallback SPA, cache immuable /assets, healthcheck IPv4 (127.0.0.1) - infra/docker-compose.dokploy.yml : 5 services préfixés siop2-, secrets exigés, seul siop2-web rejoint dokploy-network (API jamais exposée) - runbook docs/06-production/runbook-dokploy.md : topologie, profils d'environnement, checklist première prod, rollback, répétition locale - répétition locale validée de bout en bout : migrate+seed au boot, parcours demo-login → /users/me à travers nginx conteneurisé, conteneurs healthy ; le double verrou ADR-002 (DEMO_MODE sans I_KNOW en production) a refusé de démarrer — observé en situation réelle - prisma passe en dépendance de production (migrations au boot) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
39
apps/api/Dockerfile
Normal file
39
apps/api/Dockerfile
Normal file
@@ -0,0 +1,39 @@
|
||||
# SIOP V2 — image API (NestJS + Prisma).
|
||||
# Contexte de build : RACINE du monorepo (docker build -f apps/api/Dockerfile .)
|
||||
# Étage 1 : dépendances + builds ; étage 2 : runtime minimal (node:24-slim).
|
||||
|
||||
FROM node:24-slim AS builder
|
||||
RUN corepack enable
|
||||
WORKDIR /repo
|
||||
|
||||
# Manifestes d'abord (cache de couche pour pnpm install)
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
COPY packages/shared/package.json packages/shared/package.json
|
||||
COPY apps/api/package.json apps/api/package.json
|
||||
RUN pnpm install --frozen-lockfile --filter @siop/api --filter @siop/shared
|
||||
|
||||
COPY packages/shared packages/shared
|
||||
COPY apps/api apps/api
|
||||
RUN pnpm --filter @siop/shared build \
|
||||
&& pnpm --filter @siop/api prisma:generate \
|
||||
&& pnpm --filter @siop/api build \
|
||||
&& pnpm --filter @siop/api deploy --legacy --prod /out
|
||||
# Client Prisma regénéré DANS l'arborescence déployée (node_modules à plat)
|
||||
RUN cd /out && ./node_modules/.bin/prisma generate \
|
||||
&& cp -r /repo/apps/api/dist /out/dist
|
||||
|
||||
FROM node:24-slim
|
||||
# openssl : requis par les moteurs Prisma
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends openssl ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
COPY --from=builder --chown=node:node /out /app
|
||||
COPY --chown=node:node apps/api/docker-entrypoint.sh ./docker-entrypoint.sh
|
||||
RUN chmod +x docker-entrypoint.sh
|
||||
USER node
|
||||
EXPOSE 3000
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
|
||||
CMD node -e "fetch('http://localhost:3000/health').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
15
apps/api/docker-entrypoint.sh
Normal file
15
apps/api/docker-entrypoint.sh
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# SIOP V2 — démarrage du conteneur API :
|
||||
# 1. migrations Prisma (idempotentes — la base est toujours à jour du code) ;
|
||||
# 2. seed optionnel (SEED_ON_START=true : dev/démo — idempotent, jamais
|
||||
# destructif : il n'écrase ni matrice existante ni mot de passe) ;
|
||||
# 3. API. Le double verrou DEMO_MODE (ADR-002) est vérifié au boot.
|
||||
set -e
|
||||
|
||||
./node_modules/.bin/prisma migrate deploy
|
||||
|
||||
if [ "$SEED_ON_START" = "true" ]; then
|
||||
node dist/seed/seed.js
|
||||
fi
|
||||
|
||||
exec node dist/main.js
|
||||
@@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"description": "SIOP V2 — API NestJS (auth fermée par défaut, matrice de permissions en base, démo-login ADR-002)",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"build": "nest build && tsc -p tsconfig.seed.json",
|
||||
"dev": "nest start --watch",
|
||||
"start": "node dist/main.js",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
@@ -29,6 +29,7 @@
|
||||
"dotenv": "^16.4.5",
|
||||
"ioredis": "^5.4.0",
|
||||
"minio": "^8.0.0",
|
||||
"prisma": "^6.8.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"zod": "^4.0.0"
|
||||
@@ -41,7 +42,6 @@
|
||||
"@types/node": "^24.0.0",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"jest": "^29.7.0",
|
||||
"prisma": "^6.8.0",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.3.0",
|
||||
"tsx": "^4.19.0",
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
// Cibles explicites : poste de dev (native) + conteneur node:24-slim
|
||||
// (OpenSSL 3) en x64 (serveur partenaire) et arm64 (répétition locale).
|
||||
binaryTargets = ["native", "debian-openssl-3.0.x", "linux-arm64-openssl-3.0.x"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
|
||||
9
apps/api/tsconfig.seed.json
Normal file
9
apps/api/tsconfig.seed.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/seed",
|
||||
"rootDir": "prisma",
|
||||
"incremental": false
|
||||
},
|
||||
"include": ["prisma/seed.ts"]
|
||||
}
|
||||
25
apps/web/Dockerfile
Normal file
25
apps/web/Dockerfile
Normal file
@@ -0,0 +1,25 @@
|
||||
# SIOP V2 — image web (React statique derrière nginx).
|
||||
# Contexte de build : RACINE du monorepo (docker build -f apps/web/Dockerfile .)
|
||||
|
||||
FROM node:24-slim AS builder
|
||||
RUN corepack enable
|
||||
WORKDIR /repo
|
||||
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
COPY packages/shared/package.json packages/shared/package.json
|
||||
COPY apps/web/package.json apps/web/package.json
|
||||
RUN pnpm install --frozen-lockfile --filter @siop/web --filter @siop/shared
|
||||
|
||||
COPY packages/shared packages/shared
|
||||
COPY apps/web apps/web
|
||||
RUN pnpm --filter @siop/shared build && pnpm --filter @siop/web build
|
||||
|
||||
FROM nginx:1.29-alpine
|
||||
# Cible du proxy /api — surchargée par le compose (réseau interne)
|
||||
ENV API_UPSTREAM=siop2-api:3000
|
||||
COPY apps/web/nginx/default.conf.template /etc/nginx/templates/default.conf.template
|
||||
COPY --from=builder /repo/apps/web/dist /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
# 127.0.0.1 et non localhost : busybox wget tente ::1 alors que nginx écoute en IPv4
|
||||
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
|
||||
CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1
|
||||
36
apps/web/nginx/default.conf.template
Normal file
36
apps/web/nginx/default.conf.template
Normal file
@@ -0,0 +1,36 @@
|
||||
# SIOP V2 — nginx du conteneur web : statique + proxy /api → API interne.
|
||||
# ${API_UPSTREAM} est substitué au démarrage (envsubst intégré à l'image nginx) ;
|
||||
# même topologie que le proxy Vite en dev : /api est RETIRÉ avant transmission.
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# DNS Docker interrogé À LA REQUÊTE (et pas une fois au boot) : nginx
|
||||
# démarre et sert le statique même si l'API n'est pas encore résolvable.
|
||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||
set $api_upstream http://${API_UPSTREAM};
|
||||
|
||||
location /api/ {
|
||||
rewrite ^/api/(.*)$ /$1 break;
|
||||
proxy_pass $api_upstream;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Assets fingerprintés par Vite : cache long immuable
|
||||
location /assets/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# SPA : toute route applicative sert index.html (jamais mis en cache)
|
||||
location / {
|
||||
add_header Cache-Control "no-cache";
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user