version: "3.8"

services:
  # =========================
  # Mediasoup & Redis
  # =========================
  mediasoup:
    image: call29/mediasoup:1.0.0.0
    container_name: mediasoup
    network_mode: host
    environment:
      - DOMAIN=socket.call29.com
      - MEDIASOUP_LISTEN_IP=0.0.0.0
      - MEDIASOUP_ANNOUNCED_IP=socket.call29.com
      - PROTOO_LISTEN_PORT=4443
      - MEDIASOUP_MIN_PORT=40000
      - MEDIASOUP_MAX_PORT=49999
      - MEDIASOUP_PORT=40000
      - DEBUG=mediasoup-demo-server:INFO* mediasoup-demo-server:WARN* mediasoup-demo-server:ERROR*
      - INTERACTIVE=false
      - MEDIASOUP_USE_WEBRTC_SERVER=true
      - REDIS_URL=host.docker.internal:6379
    volumes:
      - ./mediasoup/lib:/app/lib
    depends_on:
      - redis
    restart: unless-stopped
    healthcheck:
      test:
        [
          "CMD",
          "node",
          "-e",
          "require('net').createConnection(3001, 'localhost').on('error', () => process.exit(1)).on('connect', () => process.exit(0))"
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  redis:
    image: call29/redis:7-alpine
    container_name: redis-server
    network_mode: host
    restart: unless-stopped

  # =========================
  # Management + Mongo + Mongo Express
  # =========================
  management-service:
    image: call29/management:1.0.0.0
    container_name: management
    network_mode: host
    restart: unless-stopped
    environment:
      - PORT=8080
      - REDIS_URL=host.docker.internal:6379
      - JWT_SECRET=5a041dc10908dad36ff6addfbf408b60d7801b8086eef9c67accacc0ece8b73df87e94b638f3cc05afcb5ffa68b831dbd23ca5b0d65938e29e02d9b721af9d4e
      - SESSION_SECRET=b62c6766ec2ca87f13f14ecd6fa47f9ae78b3944d554817e83708487d31bac0c43d6ec03bf498bcc512b160beb3d865b43ea48a9d6026ff53b415de34df5d90d
      - GOOGLE_CLIENT_ID=873316172207-jqn51teth9q58qbtbp74t9tiqpehphjr.apps.googleusercontent.com
      - APPLE_CLIENT_ID=com.call29.web
      - BASE_BE_URL=https://api.call29.com
      - FRONTEND_URL=https://call29.com
      - ENV_MODE=PRODUCTION
      - TRANSCRIPT_API_KEY=nNbK1yFwJZ1kCjabaZIPqd1bPvQsNBSd8W9ciZma6g0S2iCuR87JhuYvc7X5RlaH
      - CLOUD_API_KEY=9mQ2f775EjKi9w7QT6fOsekli4XnyNtDfGNUTNWH5dTOgDDZX5k7kMtjupgUpW8m
      - NOTI_API_KEY=RmbYnEysqARe4pHR3ui1AgiPTZoFytVi1HyofhSo2v5gskvh0CTtgAhmhciLWfYy
      - CALL29_AI_API_KEY=sw25KNJTiELUFLw1kKg_WtvUrbya5kvrQJ_XNOqY-eY
      - CHAT_SERVICE_MONGODB_URI=mongodb://admin:password123@host.docker.internal:27017/chat_service?authSource=admin
      - MONGODB_URI=mongodb://admin:password123@host.docker.internal:27017/mediasoup?authSource=admin
      - SWAGGER_DEV_URI=https://api.call29.com
      - EMAIL_USER=call29.service@gmail.com
      - EMAIL_PASS=lvzq ijns cgjc tloi
    depends_on:
      - mongo
    volumes:
      - ./management:/app

  mongo:
    image: call29/mongo:4.4
    container_name: management-mongo
    network_mode: host
    restart: unless-stopped
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password123
      - MONGO_INITDB_DATABASE=mediasoup
    volumes:
      - ./management/mongo_data:/data/db
      - ./management/mongo-init:/docker-entrypoint-initdb.d:ro

  mongo-express:
    image: call29/mongo-express:1.0.2
    container_name: management-mongo-express
    network_mode: host
    restart: unless-stopped
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password123
      - ME_CONFIG_MONGODB_SERVER=host.docker.internal
      - ME_CONFIG_MONGODB_PORT=27017
      - ME_CONFIG_MONGODB_ENABLE_ADMIN=true
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=admin123
      - ME_CONFIG_MONGODB_AUTH_DATABASE=admin
    depends_on:
      - mongo

  # =========================
  # Chat Service
  # =========================
  chat-service:
    image: call29/chat:1.0.0.0
    container_name: chat
    network_mode: host
    environment:
      - NODE_ENV=production
      - PORT=8084
      - JWT_SECRET=5a041dc10908dad36ff6addfbf408b60d7801b8086eef9c67accacc0ece8b73df87e94b638f3cc05afcb5ffa68b831dbd23ca5b0d65938e29e02d9b721af9d4e
      - SESSION_SECRET=b62c6766ec2ca87f13f14ecd6fa47f9ae78b3944d554817e83708487d31bac0c43d6ec03bf498bcc512b160beb3d865b43ea48a9d6026ff53b415de34df5d90d
      - MONGODB_URI=mongodb://admin:password123@host.docker.internal:27017/chat_service?authSource=admin
      - MEDIASOUP_MONGODB_URI=mongodb://admin:password123@host.docker.internal:27017/mediasoup?authSource=admin
    restart: unless-stopped
    volumes:
      - ./chat/logs:/app/logs
    depends_on:
      - mongo

  # =========================
  # Recording Service + Nginx
  # =========================
  recording-service:
    image: call29/recording:1.0.0.0
    container_name: recording
    environment:
      - REDIS_URL=redis://host.docker.internal:6379
      - MEDIASOUP_SERVER=https://socket.call29.com
      - MY_IP=localhost
      - CALL29_API_URL=https://api.call29.com
      - RECORD_FILE_URL=https://records.call29.com
      - PORT=3002
    volumes:
      - ./recording/recordings:/app/recordings
    network_mode: host
    restart: unless-stopped
    depends_on:
      - redis

  recording-nginx:
    image: nginx:alpine
    container_name: recording-nginx
    ports:
      - "8083:80"
    volumes:
      - ./recording/recordings:/usr/share/nginx/html/recordings:ro
    restart: unless-stopped
    depends_on:
      - recording-service

  # =========================
  # Playback Listener
  # =========================
  playback-listener:
    image: call29/playback:1.0.0.0
    container_name: playback
    environment:
      - REDIS_URL=redis://host.docker.internal:6379
      - RECORD_URL=https://call29.com/meet/
      - NODE_ENV=production
      - RECORDINGS_PATH=/root/recording/recordings
      - LOG_PATH=/root/be/playback/logs
      - SOCKET_BASE_URL=https://socket.call29.com
      - API_BASE_URL=https://api.call29.com
      - RECORDS_BASE_URL=https://records.call29.com
      - RECORD_UPLOAD_URL=https://call29.com/embed/cloud/apps/call29_media/upload
      - RECORD_UPLOAD_KEY=9f4b3d2a7e1c5f0a6d8b2e3f0c9a4b7e
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./playback/recordings:/recordings
      - ./playback/logs:/logs
    network_mode: host
    restart: unless-stopped

  app:
    image: call29/web:1.0.0.0
    container_name: web
    ports:
      - "8081:443"   # HTTPS only
      - "8082:80"   # HTTP only
    restart: unless-stopped


