# TK-MP-Project Synology Container Manager 전용 설정
# Synology NAS 환경에 최적화된 Docker Compose 설정

services:
  # PostgreSQL 데이터베이스 (Synology 최적화)
  postgres:
    image: postgres:15-alpine
    container_name: tk-mp-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: tk_mp_bom
      POSTGRES_USER: tkmp_user
      POSTGRES_PASSWORD: tkmp_password_2025
      POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C"
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./database/init:/docker-entrypoint-initdb.d
    networks:
      - tk-mp-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U tkmp_user -d tk_mp_bom"]
      interval: 60s  # Synology에서는 더 긴 간격
      timeout: 15s
      retries: 5
      start_period: 120s  # 초기 시작 시간 더 길게

  # Redis (Synology 최적화)
  redis:
    image: redis:7-alpine
    container_name: tk-mp-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - tk-mp-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 60s
      timeout: 15s
      retries: 5
      start_period: 60s

  # 백엔드 FastAPI 서비스 (Synology 최적화)
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: tk-mp-backend
    restart: unless-stopped
    ports:
      - "18000:8000"
    environment:
      - DATABASE_URL=postgresql://tkmp_user:tkmp_password_2025@postgres:5432/tk_mp_bom
      - REDIS_URL=redis://redis:6379
      - ENVIRONMENT=production
      - DEBUG=false
      - PYTHONPATH=/app
      # DB 마이그레이션용 환경변수
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=tk_mp_bom
      - DB_USER=tkmp_user
      - DB_PASSWORD=tkmp_password_2025
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - tk-mp-network
    volumes:
      - ./backend/uploads:/app/uploads
    healthcheck:
      test: ["CMD-SHELL", "python -c 'import requests; requests.get(\"http://localhost:8000/health\", timeout=10)'"]
      interval: 60s
      timeout: 20s
      retries: 5
      start_period: 180s  # Synology에서는 더 긴 시작 시간

  # 프론트엔드 React + Nginx 서비스 (Synology 최적화)
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: tk-mp-frontend
    restart: unless-stopped
    ports:
      - "13000:80"
    depends_on:
      - backend
    networks:
      - tk-mp-network
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:80 || exit 1"]
      interval: 60s
      timeout: 15s
      retries: 5
      start_period: 120s

networks:
  tk-mp-network:
    driver: bridge
    name: tk-mp-network

volumes:
  postgres_data:
    name: tk-mp-postgres-data
  redis_data:
    name: tk-mp-redis-data
