services:
  starter-api:
    image: gitea.leonmorival.com/leon-morival/laravel-starter:latest
    container_name: starter-starter-api-1
    restart: unless-stopped
    depends_on:
      pgsql:
        condition: service_healthy
      redis:
        condition: service_started
      meilisearch:
        condition: service_started
    # ports: <--- Supprimé pour la sécurité, NPM s'en occupe
    #  - "8002:80"
    environment:
      APP_LOCALE: "fr"
      APP_ENV: "production"
      APP_KEY: "${APP_KEY}"
      APP_URL: "${APP_URL}"
      SERVER_NAME: ":80"
      APP_RUNTIME: "Laravel\\FrankenPHP\\Runtime" # <-- AJOUTÉ pour FrankenPHP
      APP_DEBUG: "${APP_DEBUG}"
      FILESYSTEM_DISK: "public"
      DB_CONNECTION: "pgsql"
      DB_HOST: "pgsql"
      DB_PORT: 5432
      DB_DATABASE: "${DB_DATABASE}"
      DB_USERNAME: "${DB_USERNAME}"
      DB_PASSWORD: "${DB_PASSWORD}"
      REDIS_HOST: "redis"
      REDIS_CLIENT: "predis"
      QUEUE_CONNECTION: "redis"
      SCOUT_DRIVER: "meilisearch"
      MEILISEARCH_HOST: "http://meilisearch:7700"
      MEILISEARCH_KEY: "${MEILISEARCH_KEY}"
    volumes:
      - storage-data:/var/www/html/storage/app
      - storage-public-data:/var/www/html/storage/app/public
    networks:
      - nginx
      - internal

  pgsql:
    image: postgres:15-alpine
    container_name: starter-pgsql-1
    restart: unless-stopped
    environment:
      POSTGRES_DB: "${DB_DATABASE}"
      POSTGRES_USER: "${DB_USERNAME}"
      POSTGRES_PASSWORD: "${DB_PASSWORD}"
    volumes:
      - pgsql-data:/var/lib/postgresql/data
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_DATABASE}" ]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - internal

  redis:
    image: redis:alpine
    container_name: starter-redis-1
    restart: unless-stopped
    volumes:
      - redis-data:/data
    networks:
      - internal

  horizon:
    image: gitea.leonmorival.com/leon-morival/laravel-starter:latest
    container_name: starter-horizon-1
    restart: unless-stopped
    depends_on:
      - redis
    environment:
      APP_ENV: "production"
      APP_KEY: "${APP_KEY}"
      DB_CONNECTION: "pgsql"
      DB_HOST: "pgsql"
      DB_PORT: 5432
      DB_DATABASE: "${DB_DATABASE}"
      DB_USERNAME: "${DB_USERNAME}"
      DB_PASSWORD: "${DB_PASSWORD}"
      REDIS_HOST: "redis"
      REDIS_CLIENT: "predis"
      QUEUE_CONNECTION: "redis"
    volumes:
      - storage-data:/var/www/html/storage/app
    command: "php artisan horizon"
    networks:
      - internal

  adminer:
    image: adminer:latest
    container_name: starter-adminer-1
    restart: unless-stopped
    environment:
      # Optionnel : définit PostgreSQL par défaut à la connexion
      ADMINER_DEFAULT_SERVER: pgsql
    networks:
      - internal
      - nginx

  meilisearch:
    image: getmeili/meilisearch:latest
    container_name: starter-meilisearch-1
    restart: unless-stopped
    environment:
      MEILI_NO_ANALYTICS: "true"
      MEILI_MASTER_KEY: "${MEILISEARCH_KEY}"
    volumes:
      - meilisearch-data:/meili_data
    networks:
      - internal
      - nginx

volumes:
  pgsql-data:
    external: true
    name: starter_pgsql_data
  redis-data:
    name: starter_redis_data
  storage-data:
  storage-public-data:
    name: starter_storage_public_data
  meilisearch-data:
    name: starter_meilisearch_data

networks:
  nginx:
    external: true
  internal:
    driver: bridge
