# Docker Compose for Production

services:
  # Redis
  redis:
    image: redis:7-alpine
    container_name: admister-redis-prod
    restart: unless-stopped
    command: redis-server --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
      interval: 10s
      timeout: 3s
      retries: 3
    networks:
      - admister-network

  # Backend API
  api:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: admister-api-prod
    restart: unless-stopped
    ports:
      - "3001:3001"
    environment:
      - NODE_ENV=production
      - PORT=3001
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=${REDIS_PASSWORD}
      - DATABASE_PATH=./database/admister.db
      - FRONTEND_URL=${FRONTEND_URL}
      - FACEBOOK_APP_ID=${FACEBOOK_APP_ID}
      - FACEBOOK_APP_SECRET=${FACEBOOK_APP_SECRET}
      - FACEBOOK_REDIRECT_URI=${FACEBOOK_REDIRECT_URI}
      - SESSION_SECRET=${SESSION_SECRET}
    volumes:
      - api-uploads:/app/uploads
      - api-database:/app/database
      - api-logs:/app/logs
    depends_on:
      redis:
        condition: service_healthy
    networks:
      - admister-network
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  # Frontend (Next.js)
  web:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: admister-web-prod
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
    depends_on:
      - api
    networks:
      - admister-network
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  # Nginx Reverse Proxy
  nginx:
    image: nginx:alpine
    container_name: admister-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/ssl:/etc/nginx/ssl:ro
      - nginx-cache:/var/cache/nginx
    depends_on:
      - web
      - api
    networks:
      - admister-network
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

networks:
  admister-network:
    driver: bridge

volumes:
  redis-data:
  api-uploads:
  api-database:
  api-logs:
  nginx-cache:
