x-logging: &logging
  logging:
    driver: 'json-file'
    options:
      max-size: '25mb'
      max-file: '3'

x-restart-policy: &restart_policy
  restart: unless-stopped

services:
  data-master:
    <<: [*restart_policy, *logging]
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.data-master:${AIR_VERSION:-latest}
    # when hostname changes, AIR_POSTGRESQL_URI variable default value in config.ts must also change
    hostname: 'air.data-master.server'
    shm_size: 2g
    environment:
      - AIR_POSTGRESQL_PASSWORD
    volumes:
      - ./volumes/data-master/binalyze-air/data:/binalyze-air/data:rw
      - ./volumes/data-master/binalyze-air/log:/binalyze-air/log:rw

  nats:
    <<: [*restart_policy, *logging]
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.nats:${AIR_VERSION:-latest}
    # when hostname changes, AIR_NATS_URI variable default value in config.ts must also change
    hostname: 'air.nats.server'
    environment:
      - AIR_NATS_PASSWORD
    ports:
      - 4222:4222

  redis:
    <<: [*restart_policy, *logging]
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.redis:${AIR_VERSION:-latest}
    # when hostname changes, AIR_REDIS_URI variable default value in config.ts must also change
    hostname: 'air.redis.server'

  app:
    depends_on:
      - nats
      - redis
      - data-master
    <<: [*restart_policy, *logging]
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.console:${AIR_VERSION:-latest}
    hostname: 'air.console.service'
    environment:
      - AIR_POSTGRESQL_URI
      - AIR_NATS_PASSWORD
    volumes:
      - ./volumes/web/config:/binalyze-air/private/server:rw
      - ./volumes/app/binalyze-air/logs:/binalyze-air/logs:rw
      - ./volumes/app/binalyze-air/backups:/binalyze-air/backups:rw
      - ./volumes/app/binalyze-air/config:/binalyze-air/config:rw
      - ./volumes/app/binalyze-air/data:/binalyze-air/data:rw

  web:
    <<: [*restart_policy, *logging]
    depends_on:
      - app
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.web:${AIR_VERSION:-latest}
    hostname: 'air.web.server'
    ports:
      - 80:8080
      - 443:8443
      - 8443:8444
    volumes:
      - ./volumes/web/config:/config:ro
    cap_drop:
      - ALL
    sysctls:
      net.ipv4.ip_local_port_range: "10240 65535"

  tornado:
    depends_on:
      - web
    <<: [*restart_policy, *logging]
    image: ${CONTAINER_REGISTRY:-cr.binalyze.com/binalyze}/air.tornado:${AIR_VERSION:-latest}
    hostname: 'air.tornado.server'
    volumes:
      - ./volumes/tornado/config:/tornado/config:rw
      - ./volumes/tornado/data:/tornado/data:rw
