services:
  postgres:
    image: postgres:16-alpine
    container_name: ga-postgres
    environment:
      POSTGRES_DB: ga
      POSTGRES_USER: ga
      POSTGRES_PASSWORD: ga
      TZ: Asia/Seoul
    ports:
      - "5432:5432"
    volumes:
      - ga-postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ga -d ga"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: ga-redis
    ports:
      - "6379:6379"
    volumes:
      - ga-redis-data:/data

  api:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        MODULE: ga-api
    container_name: ga-api
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    environment:
      SPRING_PROFILES_ACTIVE: docker
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ga
      SPRING_DATASOURCE_USERNAME: ga
      SPRING_DATASOURCE_PASSWORD: ga
      SPRING_DATA_REDIS_HOST: redis
      JWT_SECRET: ${JWT_SECRET:-please-change-this-jwt-secret-must-be-256-bits}
      ENCRYPT_KEY: ${ENCRYPT_KEY:-please-change-this-32-byte-key!}
    ports:
      - "8082:8082"

  batch:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        MODULE: ga-batch
    container_name: ga-batch
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
      api:
        condition: service_started
    environment:
      SPRING_PROFILES_ACTIVE: docker
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ga
      SPRING_DATASOURCE_USERNAME: ga
      SPRING_DATASOURCE_PASSWORD: ga
      SPRING_DATA_REDIS_HOST: redis
      JWT_SECRET: ${JWT_SECRET:-please-change-this-jwt-secret-must-be-256-bits}
      ENCRYPT_KEY: ${ENCRYPT_KEY:-please-change-this-32-byte-key!}
    ports:
      - "8081:8081"

  frontend:
    build:
      context: ./ga-frontend
      dockerfile: Dockerfile
    container_name: ga-frontend
    depends_on:
      - api
    ports:
      - "3000:80"

volumes:
  ga-postgres-data:
  ga-redis-data:
