services:
  postgres:
    image: postgres:16-alpine
    container_name: mostuki-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-directus}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-directus}
      POSTGRES_DB: ${POSTGRES_DB:-directus}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-directus}"]
      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:
      - "8055:8055"
    volumes:
      - directus_uploads:/directus/uploads
      - directus_extensions:/directus/extensions
    environment:
      KEY: "${DIRECTUS_SECRET:-mostuki-dev-key}"
      SECRET: "${DIRECTUS_SECRET:-mostuki-dev-secret}"
      ADMIN_EMAIL: "${DIRECTUS_ADMIN_EMAIL:-corentin.jog@gmail.com}"
      ADMIN_PASSWORD: "${DIRECTUS_ADMIN_PASSWORD:-changeme-please}"
      DB_CLIENT: "pg"
      DB_HOST: "postgres"
      DB_PORT: "5432"
      DB_DATABASE: "${POSTGRES_DB:-directus}"
      DB_USER: "${POSTGRES_USER:-directus}"
      DB_PASSWORD: "${POSTGRES_PASSWORD:-directus}"
      CACHE_ENABLED: "false"
      WEBSOCKETS_ENABLED: "true"
      PUBLIC_URL: "${DIRECTUS_PUBLIC_URL:-http://localhost:8055}"
      CORS_ENABLED: "true"
      CORS_ORIGIN: "http://localhost:4321"

  astro:
    build:
      context: .
      dockerfile: Dockerfile.dev
    container_name: mostuki-astro
    restart: unless-stopped
    depends_on:
      - directus
    ports:
      - "4321:4321"
    volumes:
      - ./src:/app/src
      - ./public:/app/public
      - ./astro.config.mjs:/app/astro.config.mjs
      - /app/node_modules
    environment:
      ASTRO_TELEMETRY_DISABLED: "1"
      DIRECTUS_URL: "http://directus:8055"
      DIRECTUS_TOKEN: "${DIRECTUS_TOKEN:-}"
      PUBLIC_SITE_URL: "${PUBLIC_SITE_URL:-http://localhost:4321}"

volumes:
  postgres_data:
  directus_uploads:
  directus_extensions:
