Avant : une seule image (Dockerfile.app) qui bundle AdonisJS + SPA static.
Après : deux images, deux deployments, deux workflows CI avec path filters
indépendants.
Architecture
- rubis-web (NodePort 30110, exposé via Traefik)
· nginx-alpine + SPA Vite dist + nginx.conf
· sert /assets/* (cache 1y immutable), / (try_files index.html SPA fallback)
· reverse-proxy /api/* → rubis-api.rubis.svc.cluster.local:3333
- rubis-api (ClusterIP, accessible uniquement depuis le cluster)
· AdonisJS V7 + workers BullMQ dans le même process
· init-container migrate (idempotent, depuis build/)
· /api/v1/health pour les probes K3s + healthcheck Docker
- rubis-redis (ClusterIP, inchangé)
Bénéfices
- Build/deploy indépendants : changement front ne reconstruit pas l'API,
changement API ne reconstruit pas le SPA
- nginx en frontal donne du gzip + cache long sur les assets fingerprintés
- API n'expose plus de surface publique (defense in depth)
- Routes plus simples : on retire le wildcard SPA fallback dans
start/routes.ts (nginx s'en charge), on retire @adonisjs/static aurait
été cohérent mais on le garde pour minimiser les diffs
Files
- Dockerfile.api (replaces Dockerfile.app, Node-only)
- Dockerfile.web (new, nginx)
- apps/web/nginx.conf (new)
- k3s/app/api.yml (replaces deployment.yml + service.yml, ClusterIP)
- k3s/app/web.yml (new, NodePort 30110)
- .gitea/workflows/deploy-{api,web}.yml (replaces deploy-app.yml)
- /api/v1/health route ajoutée
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
133 lines
3.6 KiB
YAML
133 lines
3.6 KiB
YAML
# Rubis API — AdonisJS V7 (Node 22). ClusterIP uniquement, accessible
|
|
# depuis nginx (rubis-web) via DNS K3s : rubis-api.rubis.svc.cluster.local
|
|
# Workers BullMQ tournent dans le même process (cf. start/queue.ts).
|
|
---
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: rubis-api
|
|
namespace: rubis
|
|
spec:
|
|
replicas: 1
|
|
strategy:
|
|
type: RollingUpdate
|
|
rollingUpdate:
|
|
maxSurge: 1
|
|
maxUnavailable: 0
|
|
selector:
|
|
matchLabels:
|
|
app: rubis-api
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: rubis-api
|
|
spec:
|
|
imagePullSecrets:
|
|
- name: gitea-registry
|
|
# Migrations : exécutées en init-container avant que le serveur démarre.
|
|
# Idempotent (ace migration:run skip ce qui est déjà appliqué).
|
|
# workingDir = build/ pour utiliser ace.js compilé (les .ts ne se chargent
|
|
# pas en runtime, devDeps absentes).
|
|
initContainers:
|
|
- name: migrate
|
|
image: git.arthurbarre.fr/ordinarthur/rubis-api:latest
|
|
imagePullPolicy: Always
|
|
workingDir: /app/apps/api/build
|
|
command: ['node', 'ace.js', 'migration:run', '--force']
|
|
envFrom:
|
|
- secretRef: { name: rubis-app-secrets }
|
|
- configMapRef: { name: rubis-api-config }
|
|
resources:
|
|
requests: { cpu: 50m, memory: 128Mi }
|
|
limits: { cpu: 500m, memory: 512Mi }
|
|
containers:
|
|
- name: api
|
|
image: git.arthurbarre.fr/ordinarthur/rubis-api:latest
|
|
imagePullPolicy: Always
|
|
ports:
|
|
- containerPort: 3333
|
|
name: http
|
|
envFrom:
|
|
- secretRef: { name: rubis-app-secrets }
|
|
- configMapRef: { name: rubis-api-config }
|
|
resources:
|
|
requests:
|
|
cpu: 100m
|
|
memory: 256Mi
|
|
limits:
|
|
cpu: 1000m
|
|
memory: 768Mi
|
|
startupProbe:
|
|
httpGet: { path: /api/v1/health, port: http }
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5
|
|
failureThreshold: 30
|
|
livenessProbe:
|
|
httpGet: { path: /api/v1/health, port: http }
|
|
periodSeconds: 30
|
|
timeoutSeconds: 5
|
|
failureThreshold: 3
|
|
readinessProbe:
|
|
httpGet: { path: /api/v1/health, port: http }
|
|
periodSeconds: 10
|
|
timeoutSeconds: 3
|
|
failureThreshold: 3
|
|
---
|
|
# ClusterIP — accessible uniquement depuis le cluster (par nginx rubis-web).
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: rubis-api
|
|
namespace: rubis
|
|
spec:
|
|
type: ClusterIP
|
|
selector:
|
|
app: rubis-api
|
|
ports:
|
|
- port: 3333
|
|
targetPort: http
|
|
name: http
|
|
---
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: rubis-api-config
|
|
namespace: rubis
|
|
data:
|
|
# Variables non-sensibles. Les secrets sont dans rubis-app-secrets.
|
|
TZ: 'Europe/Paris'
|
|
PORT: '3333'
|
|
HOST: '0.0.0.0'
|
|
NODE_ENV: 'production'
|
|
LOG_LEVEL: 'info'
|
|
APP_URL: 'https://app.rubis.arthurbarre.fr'
|
|
WEB_URL: 'https://app.rubis.arthurbarre.fr'
|
|
SESSION_DRIVER: 'cookie'
|
|
COOKIE_SECURE: 'true'
|
|
COOKIE_DOMAIN: 'app.rubis.arthurbarre.fr'
|
|
|
|
DB_CONNECTION: 'postgres'
|
|
PG_HOST: '10.10.10.3'
|
|
PG_PORT: '5432'
|
|
PG_USER: 'rubis'
|
|
PG_DB_NAME: 'rubis_prod'
|
|
|
|
REDIS_HOST: 'rubis-redis.rubis.svc.cluster.local'
|
|
REDIS_PORT: '6379'
|
|
LIMITER_STORE: 'redis'
|
|
|
|
DRIVE_DISK: 's3'
|
|
S3_ENDPOINT: 'http://minio.minio.svc.cluster.local:9000'
|
|
S3_REGION: 'fr-par'
|
|
S3_BUCKET: 'rubis-prod-invoices'
|
|
S3_FORCE_PATH_STYLE: 'true'
|
|
|
|
MAIL_DRIVER: 'resend'
|
|
MAIL_FROM_ADDRESS: 'rubis@arthurbarre.fr'
|
|
MAIL_FROM_NAME: "Rubis Sur l'Ongle"
|
|
|
|
OCR_PROVIDER: 'mistral'
|
|
|
|
ACCESS_TOKEN_TTL_MINUTES: '30'
|
|
REFRESH_TOKEN_TTL_DAYS: '30'
|