version: "3.2"

volumes:
  database:
    driver: local
  files:
    driver: local

services:
  # The VILLASweb frontend
  frontend:
    image: registry.git.rwth-aachen.de/acs/public/villas/web:demo-v0.1
    build:
      context: frontend
    restart: always

  # The VILLASweb backend
  backend:
    image: registry.git.rwth-aachen.de/acs/public/villas/web-backend:demo-v0.1
    build:
      context: backend
    environment:
      NODE_ENV: dotenv
      DATABASE_URL: mongodb://database:27017/
      AMQP_ENDPOINT: "amqp://villas:s3c0sim4!@broker/%2F"
      LOG_LEVEL: info
      LOG_FILE: villasweb-backend_log.txt
      DEFAULT_ADMIN: "true"
    command: [
      "wait-for", "broker:5672", "--",
      "wait-for", "database:27017", "--",
      "npm", "start"
    ]
    volumes:
      - files:/usr/src/app/public/
    depends_on:
      - broker
      - database
    restart: always

  # A single reverse proxy for all our services
  nginx:
    image: nginx:1.17.4-alpine
    volumes:
     - ./etc/nginx/:/etc/nginx/conf.d/
    ports:
     - 80:80
    depends_on:
     - backend
     - frontend
     - relay
     - doc
    restart: always

  # The MongoDB database for the VILLASweb backend
  database:
    image: mongo:3.4.23
    volumes:
      - database:/data/db
    restart: always

  # VILLASnode, the gateway between UDP and WebSocket traffic
  node:
    image: registry.git.rwth-aachen.de/acs/public/villas/node:demo-v0.1
    privileged: true
    command: node /etc/villas/node/demo.conf
    volumes:
      - ./etc/villas/node:/etc/villas/node
      - ./data:/data
    ports:
      - "8080:80"
      - "12000-12010:12000-12010/udp"
      - "12000-12010:12000-12010/tcp"
    restart: always

  # A relay for websocket nodes
  relay:
    image: registry.git.rwth-aachen.de/acs/public/villas/node:demo-v0.1
    restart: always
    command: relay

  # Web Interface for MongoDB
  mongo-express:
    image: mongo-express:0.49.0
    environment:
      ME_CONFIG_MONGODB_SERVER: database
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: mongo-admin
      ME_CONFIG_SITE_BASEURL: /mongo-express/
    depends_on:
      - database
    restart: always

  # AMQP broker for VILLAScontroller
  broker:
    build:
      context: .
      dockerfile: Dockerfile.broker
    image: registry.git.rwth-aachen.de/acs/public/villas/demo/broker:demo-v0.1
    environment:
      RABBITMQ_DEFAULT_USER: "villas"
      RABBITMQ_DEFAULT_PASS: "s3c0sim4!"
    ports:
      - "8083:15672"
      - "5672:5672"
      - "1883:1883"
    restart: always

  # A VILLAScontroller for creating some dummy simulators
  controller:
    build:
      context: controller
    image: registry.git.rwth-aachen.de/acs/public/villas/controller:demo-v0.1
    command: [
      "wait-for", "broker:5672", "--",
      "villas-ctl", "-b", "amqp://villas:s3c0sim4!@broker/%2F", "daemon"
    ]
    volumes:
      - ./etc/villas/controller:/etc/villas/controller
    depends_on:
      - broker
    restart: always

  # VILLAS Documentation
  doc:
    build:
      context: doc
    image: registry.git.rwth-aachen.de/acs/public/villas/demo/documentation
    restart: always
