version: '3.8'

services:
  # Nginx 리버스 프록시
  nginx:
    build: ./nginx
    container_name: document-server-nginx
    ports:
      - "24100:80"
    volumes:
      - ./frontend:/usr/share/nginx/html
      - ./uploads:/usr/share/nginx/html/uploads
    depends_on:
      - backend
    networks:
      - document-network
    restart: unless-stopped

  # Backend API 서버
  backend:
    build: ./backend
    container_name: document-server-backend
    ports:
      - "24102:8000"
    volumes:
      - ./uploads:/app/uploads
      - ./backend/src:/app/src
    environment:
      - DATABASE_URL=postgresql+asyncpg://docuser:docpass@database:5432/document_db
      - SECRET_KEY=${SECRET_KEY:-production-secret-key-change-this}
      - ADMIN_EMAIL=${ADMIN_EMAIL:-admin@test.com}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}
      - DEBUG=false
    depends_on:
      - database
    networks:
      - document-network
    restart: unless-stopped

  # PostgreSQL 데이터베이스
  database:
    image: postgres:15-alpine
    container_name: document-server-db
    ports:
      - "24101:5432"
    environment:
      - POSTGRES_DB=document_db
      - POSTGRES_USER=docuser
      - POSTGRES_PASSWORD=docpass
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./database/init:/docker-entrypoint-initdb.d
    networks:
      - document-network
    restart: unless-stopped

  # Redis (캐싱 및 세션)
  redis:
    image: redis:7-alpine
    container_name: document-server-redis
    ports:
      - "24103:6379"
    volumes:
      - redis_data:/data
    networks:
      - document-network
    restart: unless-stopped
    command: redis-server --appendonly yes

volumes:
  postgres_data:
  redis_data:

networks:
  document-network:
    driver: bridge
