version: '3.2'

services:
  # Starts the PostgreSQL database for watchers
  watcher-db:
    restart: unless-stopped
    image: postgres:14-alpine
    environment:
      - POSTGRES_USER=vdbm
      - POSTGRES_MULTIPLE_DATABASES=azimuth-watcher,azimuth-watcher-job-queue,censures-watcher,censures-watcher-job-queue,claims-watcher,claims-watcher-job-queue,conditional-star-release-watcher,conditional-star-release-watcher-job-queue,delegated-sending-watcher,delegated-sending-watcher-job-queue,ecliptic-watcher,ecliptic-watcher-job-queue,linear-star-release-watcher,linear-star-release-watcher-job-queue,polls-watcher,polls-watcher-job-queue
      - POSTGRES_EXTENSION=azimuth-watcher-job-queue:pgcrypto,censures-watcher-job-queue:pgcrypto,claims-watcher-job-queue:pgcrypto,conditional-star-release-watcher-job-queue:pgcrypto,delegated-sending-watcher-job-queue:pgcrypto,ecliptic-watcher-job-queue:pgcrypto,linear-star-release-watcher-job-queue:pgcrypto,polls-watcher-job-queue:pgcrypto,
      - POSTGRES_PASSWORD=password
    volumes:
      - ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh
      - watcher_db_data:/var/lib/postgresql/data
    ports:
      - "0.0.0.0:15432:5432"
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "5432"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 10s

  # Starts the azimuth-watcher server
  azimuth-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/azimuth-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/azimuth-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/azimuth-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/azimuth-watcher/start-server.sh
    ports:
      - "3001"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3001"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the censures-watcher server
  censures-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/censures-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/censures-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/censures-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/censures-watcher/start-server.sh
    ports:
      - "3002"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3002"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the claims-watcher server
  claims-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/claims-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/claims-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/claims-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/claims-watcher/start-server.sh
    ports:
      - "3003"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3003"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the conditional-star-release-watcher server
  conditional-star-release-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/conditional-star-release-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/conditional-star-release-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/conditional-star-release-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/conditional-star-release-watcher/start-server.sh
    ports:
      - "3004"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3004"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the delegated-sending-watcher server
  delegated-sending-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/delegated-sending-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/delegated-sending-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/delegated-sending-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/delegated-sending-watcher/start-server.sh
    ports:
      - "3005"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3005"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the ecliptic-watcher server
  ecliptic-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/ecliptic-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/ecliptic-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/ecliptic-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/ecliptic-watcher/start-server.sh
    ports:
      - "3006"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3006"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the linear-star-release-watcher server
  linear-star-release-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/linear-star-release-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/linear-star-release-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/linear-star-release-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/linear-star-release-watcher/start-server.sh
    ports:
      - "3007"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3007"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the polls-watcher server
  polls-watcher-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      watcher-db:
        condition: service_healthy
    env_file:
      - ../config/watcher-azimuth/watcher-params.env
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
      CERC_IPLD_ETH_RPC: ${CERC_IPLD_ETH_RPC}
      CERC_IPLD_ETH_GQL: ${CERC_IPLD_ETH_GQL}
    working_dir: /app/packages/polls-watcher
    command: "./start-server.sh"
    volumes:
      - ../config/watcher-azimuth/watcher-config-template.toml:/app/packages/polls-watcher/environments/watcher-config-template.toml
      - ../config/watcher-azimuth/merge-toml.js:/app/packages/polls-watcher/merge-toml.js
      - ../config/watcher-azimuth/start-server.sh:/app/packages/polls-watcher/start-server.sh
    ports:
      - "3008"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "3008"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # Starts the gateway-server for proxying queries
  gateway-server:
    image: cerc/watcher-azimuth:local
    restart: unless-stopped
    depends_on:
      azimuth-watcher-server:
        condition: service_healthy
      censures-watcher-server:
        condition: service_healthy
      claims-watcher-server:
        condition: service_healthy
      conditional-star-release-watcher-server:
        condition: service_healthy
      delegated-sending-watcher-server:
        condition: service_healthy
      ecliptic-watcher-server:
        condition: service_healthy
      linear-star-release-watcher-server:
        condition: service_healthy
      polls-watcher-server:
        condition: service_healthy
    environment:
      CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
    working_dir: /app/packages/gateway-server
    command: "yarn server"
    volumes:
      - ../config/watcher-azimuth/gateway-watchers.json:/app/packages/gateway-server/dist/watchers.json
    ports:
      - "0.0.0.0:4000:4000"
    healthcheck:
      test: ["CMD", "nc", "-vz", "localhost", "4000"]
      interval: 20s
      timeout: 5s
      retries: 15
      start_period: 5s
    extra_hosts:
      - "host.docker.internal:host-gateway"

volumes:
  watcher_db_data:
