version: "3.9"

services:
  game-server:
    build:
      context: .
      dockerfile: infrastructure/Dockerfile.server
      target: development
    command: ./bin/starfall-server --config /app/config/server.yaml
    ports:
      - "7777:7777/udp"
      - "8080:8080"
    environment:
      GAME_ENV: development
      LOG_LEVEL: debug
      DATABASE_URL: postgresql://starfall:starfall@database:5432/starfall
      REDIS_URL: redis://cache:6379/0
      MAX_PLAYERS: "16"
      TICK_RATE: "30"
    volumes:
      - ./config:/app/config:ro
      - ./assets:/app/assets:ro
      - server-logs:/app/logs
    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_started
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:8080/health"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 20s

  database:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: starfall
      POSTGRES_USER: starfall
      POSTGRES_PASSWORD: starfall
    volumes:
      - database-data:/var/lib/postgresql/data
      - ./infrastructure/sql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    ports:
      - "5432:5432"
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U starfall -d starfall"]
      interval: 10s
      timeout: 5s
      retries: 5

  cache:
    image: redis:7-alpine
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    volumes:
      - cache-data:/data
    ports:
      - "6379:6379"
    restart: unless-stopped

  telemetry:
    image: grafana/otel-lgtm:latest
    ports:
      - "3000:3000"
      - "4317:4317"
      - "4318:4318"
    volumes:
      - telemetry-data:/data
    profiles:
      - observability
    restart: unless-stopped

volumes:
  database-data:
  cache-data:
  server-logs:
  telemetry-data: