version: "3.8"

services:
  proxy:
    image: valian/docker-nginx-auto-ssl
    deploy:
      placement:
        constraints:
          - "node.labels.web==true"
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - ssl_data:/etc/resty-auto-ssl
    depends_on:
      - guppe
    env_file: '.env'
  guppe:
    image: datatitian/guppe
    deploy:
      mode: replicated
      replicas: 4
      placement:
        constraints:
          - "node.labels.web==true"
    restart: always
    env_file: '.env'
    environment:
      DB_URL: 'mongodb://mongodb:27017'
      PROXY_MODE: 1
    depends_on:
      - mongodb
    logging:
      driver: local
      options:
        max-size: '10m'
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8085"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 30s

  worker1:
    image: datatitian/guppe
    command: [ "node", "deliveryWorker.js" ]
    deploy:
      mode: replicated
      replicas: 25
      placement:
        constraints:
          - "node.labels.delivery==true"
    restart: always
    env_file: '.env'
    environment:
      DB_URL: 'mongodb://mongodb:27017'
    depends_on:
      - mongodb
    logging:
      driver: local
      options:
        max-size: '10m'

  mongodb:
    image: mongo:4.2
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - "node.labels.database==true"
    restart: always
    volumes:
      - mongo-data:/data/db
    logging:
      driver: local
      options:
        max-size: '10m'

volumes:
  mongo-data:
  ssl_data:
