name: hexahost-gamecloud-dev

services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-gamecloud}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-gamecloud}
      POSTGRES_DB: ${POSTGRES_DB:-gamecloud}
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-gamecloud} -d ${POSTGRES_DB:-gamecloud}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    networks:
      - gamecloud-internal

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    ports:
      - "${REDIS_PORT:-6379}:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - gamecloud-internal

  minio:
    image: minio/minio:latest
    restart: unless-stopped
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY:-minioadmin}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:-minioadmin}
    ports:
      - "${MINIO_API_PORT:-9000}:9000"
      - "${MINIO_CONSOLE_PORT:-9001}:9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 15s
    networks:
      - gamecloud-internal

  minio-init:
    image: minio/mc:latest
    depends_on:
      minio:
        condition: service_healthy
    entrypoint: >
      /bin/sh -c "
      mc alias set local http://minio:9000 $${MINIO_ROOT_USER:-minioadmin} $${MINIO_ROOT_PASSWORD:-minioadmin};
      mc mb --ignore-existing local/$${S3_BUCKET:-gamecloud};
      exit 0;
      "
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY:-minioadmin}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:-minioadmin}
      S3_BUCKET: ${S3_BUCKET:-gamecloud}
    networks:
      - gamecloud-internal

  mailpit:
    image: axllent/mailpit:latest
    restart: unless-stopped
    ports:
      - "${SMTP_PORT:-1025}:1025"
      - "${MAILPIT_UI_PORT:-8025}:8025"
    networks:
      - gamecloud-internal

  api:
    build:
      context: ../..
      dockerfile: apps/api/Dockerfile
    restart: unless-stopped
    env_file:
      - ../../.env
    environment:
      DATABASE_URL: ${DATABASE_URL:-postgresql://gamecloud:gamecloud@postgres:5432/gamecloud}
      REDIS_URL: ${REDIS_URL:-redis://redis:6379}
    ports:
      - "${API_PORT:-3001}:3001"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:3001/api/v1/health/live"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - gamecloud-internal
      - traefik-network

  worker:
    build:
      context: ../..
      dockerfile: apps/worker/Dockerfile
    restart: unless-stopped
    env_file:
      - ../../.env
    environment:
      DATABASE_URL: ${DATABASE_URL:-postgresql://gamecloud:gamecloud@postgres:5432/gamecloud}
      REDIS_URL: ${REDIS_URL:-redis://redis:6379}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - gamecloud-internal

  web:
    build:
      context: ../..
      dockerfile: apps/web/Dockerfile
    restart: unless-stopped
    env_file:
      - ../../.env
    environment:
      API_URL: ${API_URL:-http://api:3001}
    ports:
      - "${WEB_PORT:-3000}:3000"
    depends_on:
      api:
        condition: service_healthy
    networks:
      - gamecloud-internal
      - traefik-network

volumes:
  postgres_data:
  minio_data:

networks:
  gamecloud-internal:
    driver: bridge
  traefik-network:
    external: true
    name: ${TRAEFIK_NETWORK:-traefik-network}
