version: '3.8'

services:
  # Redis: Rate Limit永続化用
  redis:
    image: redis:7-alpine
    container_name: ponshu-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes # AOF永続化有効化
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      interval: 10s
      timeout: 3s
      retries: 3
    networks:
      - ponshu-network

  # Proxy Server: Gemini API プロキシ
  proxy:
    build: .
    container_name: ponshu-proxy-server
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      - PORT=8080
      - GEMINI_API_KEY=${GEMINI_API_KEY}
      - PROXY_AUTH_TOKEN=${PROXY_AUTH_TOKEN}
      - DAILY_LIMIT=${DAILY_LIMIT:-50}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: [ "CMD-SHELL", "node -e \"require('http').get('http://localhost:8080/health', (r) => { if (r.statusCode !== 200) process.exit(1); }).on('error', () => process.exit(1))\"" ]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - ponshu-network

volumes:
  redis-data:
    driver: local

networks:
  ponshu-network:
    driver: bridge
