version: '3.7'

# Settings common for all MinIO containers
x-minio-common: &minio-common
  image: quay.io/minio/minio:RELEASE.2022-03-08T22-28-51Z
  command: server --console-address ":9001" http://minio{1...4}/data{1...2}
  expose:
    - 9000
    - 9001
  environment:
    MINIO_ROOT_USER: ${MINIO_ACCESS_KEY}
    MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY}
  restart: always
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
    interval: 30s
    timeout: 20s
    retries: 3

# Settings common for all DTP Base containers
x-base-common: &base-common
  image: dtp/base
  restart: always
  stop_signal: SIGINT
  env_file:
    - .env.docker
  environment:
    - NODE_ENV=production
  volumes:
    - /tmp/dtp:/tmp/dtp
  depends_on:
    - redis
    - mongodb
    - minio1
    - minio2
    - minio3
    - minio4

services:

  minio1:
    <<: *minio-common
    hostname: minio1
    volumes:
      - data1-1:/data1
      - data1-2:/data2

  minio2:
    <<: *minio-common
    hostname: minio2
    volumes:
      - data2-1:/data1
      - data2-2:/data2

  minio3:
    <<: *minio-common
    hostname: minio3
    volumes:
      - data3-1:/data1
      - data3-2:/data2

  minio4:
    <<: *minio-common
    hostname: minio4
    volumes:
      - data4-1:/data1
      - data4-2:/data2

  redis:
    image: redis:6.2-alpine
    hostname: redis
    restart: always
    expose:
      - 6379
    command: redis-server --save 20 1 --loglevel warning --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis_data:/data

  mongodb:
    image: mongo:latest
    hostname: mongodb
    restart: always
    expose:
      - 27017
    volumes:
      - mongodb_data:/data/db

  base-host-services:
    <<: *base-common
    hostname: base-host-services
    command: node app/workers/host-services.js
    environment:
      - DTP_HOST_CACHE_HOST=0.0.0.0
    expose:
      - "8000/udp"

  base-reeeper:
    <<: *base-common
    hostname: base-reeeper
    command: node app/workers/reeeper.js
    environment:
      - DTP_HOST_CACHE_HOST=base-host-services
    depends_on:
      - base-host-services

  # base-analytics:
  #   <<: *base-common
  #   hostname: base-analytics
  #   command: node app/workers/base-analytics.js
  #   environment:
  #     - DTP_HOST_CACHE_HOST=base-host-services

  # Base Crypto
  # Makes calls to a Cryptocurrency exchange API to fetch the current exchange
  # rate versus the US Dollar.
  # base-crypto:
  #   <<: *base-common
  #   hostname: base-crypto
  #   command: node app/workers/base-crypto.js
  #   environment:
  #     - DTP_HOST_CACHE_HOST=base-host-services

  # Base Newsletter Worker
  # Processes newsletter transmit jobs and their email jobs.
  base-newsletter:
    <<: *base-common
    hostname: base-newsletter
    command: node app/workers/newsletter.js
    environment:
      - DTP_HOST_CACHE_HOST=base-host-services
    depends_on:
      - base-host-services

  # Base Web Application
  # Provides the DTP Base Node.js web application
  base-app-001:
    <<: *base-common
    hostname: base-app-001
    command: node dtp-webapp.js
    environment:
      - DTP_HOST_CACHE_HOST=base-host-services
    expose:
      - 3000
    depends_on:
      - base-host-services
      - base-newsletter
      - base-reeeper

  # Nginx
  # Provides an HTTP front-end to MinIO and the DTP Base application components
  # running in their various containers in the stack.
  nginx:
    image: nginx:1.19.2-alpine
    hostname: nginx
    restart: always
    volumes:
      - ./docker/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "3000:3000"
      - "8000:8000"
      - "8001:8001"
      - "9000:9000"
      - "9001:9001"
    depends_on:
      - base-app-001
      - minio1
      - minio2
      - minio3
      - minio4
  
  dns-proxy-server:
    image: defreitas/dns-proxy-server
    hostname: dns.mageddo
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/resolv.conf:/etc/resolv.conf
    ports:
      - "5380:5380"
    depends_on:
      - nginx
      - base-app-001

## By default this config uses default local driver,
## For custom volumes replace with volume driver configuration.
volumes:
  mongodb_data:
  redis_data:
  data1-1:
  data1-2:
  data2-1:
  data2-2:
  data3-1:
  data3-2:
  data4-1:
  data4-2: