# Stack locale complète : base, cache, API, migrations, frontend. # # Démarrage : # cp .env.example .env # puis remplacer les mots de passe et JWT_SECRET # docker compose up -d --build # docker compose --profile seed run --rm seed # une seule fois : compte admin # # Ouvrir http://localhost:${FRONTEND_PORT:-8081}. L'API n'est pas publiée # directement : tout passe par le frontend, comme en production. # # Les mots de passe sont insérés dans les URL (DATABASE_URL, REDIS_URL) : ils # ne doivent contenir ni @ : / ? # ni %, sinon les encoder en %XX. x-backend-env: &backend-env DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}?sslmode=disable REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0 JWT_SECRET: ${JWT_SECRET:?JWT_SECRET est requis dans .env} GIN_MODE: release PORT: "8080" COOKIE_SECURE: "false" CORS_ORIGIN: http://localhost:${FRONTEND_PORT:-8081} ACCESS_TOKEN_TTL_MINUTES: ${ACCESS_TOKEN_TTL_MINUTES:-15} REFRESH_TOKEN_TTL_HOURS: ${REFRESH_TOKEN_TTL_HOURS:-168} ADMIN_NUMBER: ${ADMIN_NUMBER:-1} MEDIA_STORAGE_DRIVER: local MEDIA_MAX_UPLOAD_MB: ${MEDIA_MAX_UPLOAD_MB:-10} MEDIA_LOCAL_DIR: /app/uploads MEDIA_LOCAL_BASE_URL: http://localhost:${FRONTEND_PORT:-8081}/uploads VERIFICATION_UPLOAD_DIR: /app/verification-uploads services: postgres: image: postgres:16-alpine container_name: platform-postgres restart: unless-stopped environment: POSTGRES_USER: ${DB_USER} POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_NAME} ports: - "${DB_PORT:-5432}:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] interval: 5s timeout: 5s retries: 5 redis: image: redis:7-alpine container_name: platform-redis restart: unless-stopped command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD}"] ports: - "${REDIS_PORT:-6379}:6379" volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"] interval: 5s timeout: 5s retries: 5 # Applique backend/migrations une fois, avant l'API. Idempotent : on peut # relancer `docker compose up` sans risque. migrate: image: migrate/migrate:v4.18.1 container_name: platform-migrate restart: "no" volumes: - ./backend/migrations:/migrations:ro command: - -path=/migrations - -database=postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}?sslmode=disable - up depends_on: postgres: condition: service_healthy backend: build: context: ./backend dockerfile: Dockerfile image: platform-backend:local container_name: platform-backend restart: unless-stopped environment: <<: *backend-env volumes: - uploads:/app/uploads - verification_uploads:/app/verification-uploads depends_on: migrate: condition: service_completed_successfully redis: condition: service_healthy healthcheck: # 127.0.0.1, not localhost: busybox wget tries ::1 first (see # /etc/hosts in the image) and doesn't fall back to IPv4 when nginx/ # the app only listens on 0.0.0.0, so "localhost" here reports # unhealthy even though the service is actually fine. test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/health"] interval: 10s timeout: 5s retries: 5 # Crée le compte admin initial. Non idempotent : à lancer une seule fois, # via `docker compose --profile seed run --rm seed`. seed: image: platform-backend:local profiles: ["seed"] restart: "no" entrypoint: ["/app/seed"] environment: <<: *backend-env SEED_ADMIN_USERNAME: ${SEED_ADMIN_USERNAME:-admin} SEED_ADMIN_PASSWORD: ${SEED_ADMIN_PASSWORD:?SEED_ADMIN_PASSWORD est requis pour le seed} depends_on: migrate: condition: service_completed_successfully frontend: build: context: ./frontend dockerfile: Dockerfile image: platform-frontend:local container_name: platform-frontend restart: unless-stopped ports: - "${FRONTEND_PORT:-8081}:8080" volumes: # Remplace la config de production : ici nginx relaie /api et /uploads # au service "backend" (voir frontend/nginx.compose.conf). - ./frontend/nginx.compose.conf:/etc/nginx/conf.d/default.conf:ro depends_on: backend: condition: service_healthy healthcheck: # 127.0.0.1, not localhost: busybox wget tries ::1 first and doesn't # fall back to IPv4 when nginx only listens on 0.0.0.0 (see backend's # healthcheck comment above for the full explanation). test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/healthz"] interval: 10s timeout: 5s retries: 5 volumes: postgres_data: redis_data: uploads: verification_uploads: