# Stack de PRODUCTION Mostuki Photo.
#
# Difference avec docker-compose.yml (dev) :
#  - Astro est BUILDE (Dockerfile multi-stage) au lieu de tourner en mode dev
#  - les ports sont bindes sur 127.0.0.1 : seul le reverse-proxy de l'hote y accede,
#    rien n'est expose directement sur internet
#  - aucun secret n'a de valeur par defaut : les vars DOIVENT etre fournies (.env)
#
# Lancement : docker compose -f docker-compose.prod.yml up -d --build
# Le reverse-proxy de l'hote (Traefik/nginx) route ton domaine vers 127.0.0.1:4321
# (site) et un sous-domaine admin vers 127.0.0.1:8055 (Directus) si besoin.

services:
  postgres:
    image: postgres:16-alpine
    container_name: mostuki-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER requis}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD requis}
      POSTGRES_DB: ${POSTGRES_DB:?POSTGRES_DB requis}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
      interval: 5s
      timeout: 5s
      retries: 5

  directus:
    image: directus/directus:11
    container_name: mostuki-directus
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "127.0.0.1:8055:8055"
    volumes:
      - directus_uploads:/directus/uploads
      - directus_extensions:/directus/extensions
    environment:
      KEY: ${DIRECTUS_KEY:?DIRECTUS_KEY requis}
      SECRET: ${DIRECTUS_SECRET:?DIRECTUS_SECRET requis}
      ADMIN_EMAIL: ${DIRECTUS_ADMIN_EMAIL:?DIRECTUS_ADMIN_EMAIL requis}
      ADMIN_PASSWORD: ${DIRECTUS_ADMIN_PASSWORD:?DIRECTUS_ADMIN_PASSWORD requis}
      DB_CLIENT: "pg"
      DB_HOST: "postgres"
      DB_PORT: "5432"
      DB_DATABASE: ${POSTGRES_DB}
      DB_USER: ${POSTGRES_USER}
      DB_PASSWORD: ${POSTGRES_PASSWORD}
      CACHE_ENABLED: "false"
      WEBSOCKETS_ENABLED: "true"
      PUBLIC_URL: ${DIRECTUS_PUBLIC_URL:?DIRECTUS_PUBLIC_URL requis}
      CORS_ENABLED: "true"
      CORS_ORIGIN: ${PUBLIC_SITE_URL:?PUBLIC_SITE_URL requis}

  astro:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: mostuki-astro
    restart: unless-stopped
    depends_on:
      - directus
    ports:
      - "127.0.0.1:4321:4321"
    environment:
      ASTRO_TELEMETRY_DISABLED: "1"
      # Astro parle a Directus par le reseau interne Docker (pas par le domaine public)
      DIRECTUS_URL: "http://directus:8055"
      DIRECTUS_TOKEN: ${DIRECTUS_TOKEN:?DIRECTUS_TOKEN requis}
      PUBLIC_SITE_URL: ${PUBLIC_SITE_URL}

volumes:
  postgres_data:
  directus_uploads:
  directus_extensions:
