# Copyright (c) Facebook, Inc. and its affiliates.

# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

version: '3'

volumes:
  whatsappMedia:
    driver: local

services:
  waweb:
    image: docker.whatsapp.biz/web:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
    restart: unless-stopped
    command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
    ports:
      - ${EXTERNAL_WEBAPP_PORT:-9090}:443
    volumes:
      - whatsappMedia:/usr/local/wamedia
    env_file:
      - db.env
    environment:
      WA_APP_MULTICONNECT: 1
      # Needs to reflect port exposed above
      WEBAPP_EXTERNAL_PORTS: ${EXTERNAL_WEBAPP_PORT:-9090}
      # $EXTERNAL_HOSTNAME should reflect the current machine's hostname
      # accessible to other containers
      WEBAPP_HOSTNAME: "${EXTERNAL_HOSTNAME:?$EXTERNAL_HOSTNAME should reflect the current machine's hostname accessible to other containers}"
      # this is the version of the docker templates being used to run WhatsApp Business API
      WA_RUNNING_ENV_VERSION: v2.2.3
      ORCHESTRATION: DOCKER-COMPOSE
    cap_drop:
      - MKNOD
  wacore:
    image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
    restart: unless-stopped
    command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
    ports:
      - ${EXTERNAL_COREAPP_PORT0:-6250}:6250
      - ${EXTERNAL_COREAPP_PORT1:-6251}:6251
      - ${EXTERNAL_COREAPP_PORT2:-6252}:6252
      - ${EXTERNAL_COREAPP_PORT3:-6253}:6253
    volumes:
      - whatsappMedia:/usr/local/wamedia
    env_file:
      - db.env
    environment:
      WA_APP_MULTICONNECT: 1
      # Needs to reflect ports exposed above
      COREAPP_EXTERNAL_PORTS: ${EXTERNAL_COREAPP_PORT0:-6250},${EXTERNAL_COREAPP_PORT1:-6251},${EXTERNAL_COREAPP_PORT2:-6252},${EXTERNAL_COREAPP_PORT3:-6253}
      # $EXTERNAL_HOSTNAME should reflect the current machine's hostname
      # accessible to other containers
      COREAPP_HOSTNAME: "${EXTERNAL_HOSTNAME:?$EXTERNAL_HOSTNAME should reflect the current machine's hostname accessible to other containers}"
      # This is the version of the docker templates being used to run WhatsApp Business API
      WA_RUNNING_ENV_VERSION: v2.2.3
      ORCHESTRATION: DOCKER-COMPOSE
    cap_drop:
      - MKNOD
  master:
    image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
    restart: unless-stopped
    command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
    ports:
      # coreapp may have occupied ports 6250-6253 on the same host
      - ${EXTERNAL_MASTER_PORT0:-6254}:6250
      - ${EXTERNAL_MASTER_PORT1:-6255}:6251
      - ${EXTERNAL_MASTER_PORT2:-6256}:6252
      - ${EXTERNAL_MASTER_PORT3:-6257}:6253
    volumes:
      - whatsappMedia:/usr/local/wamedia
    env_file:
      - db.env
    environment:
      WA_APP_MULTICONNECT: 1
      WA_MASTER_NODE: 1
      # Represents external ports of this service (master)
      # Naming is due to legacy reasons
      COREAPP_EXTERNAL_PORTS: ${EXTERNAL_MASTER_PORT0:-6254},${EXTERNAL_MASTER_PORT1:-6255},${EXTERNAL_MASTER_PORT2:-6256},${EXTERNAL_MASTER_PORT3:-6257}
      # Represents hostname of the current machine where this service (master) is hosted on
      # Naming is due to legacy reasons
      # $EXTERNAL_HOSTNAME should reflect the current machine's hostname
      # accessible to other containers
      COREAPP_HOSTNAME: "${EXTERNAL_HOSTNAME:?$EXTERNAL_HOSTNAME should reflect the current machine's hostname accessible to other containers}"
      # this is the version of the docker templates being used to run WhatsApp Business API
      WA_RUNNING_ENV_VERSION: v2.2.3
      ORCHESTRATION: DOCKER-COMPOSE
    cap_drop:
      - MKNOD
