version: "3"

volumes:
  influxdb2-data:
  influxdb2-config:
  rabbitmq_data:

services:
  gateway:
    image: registry.forge.hefr.ch/team-raclette/project-softweng/gateway:latest
    container_name: gateway
    restart: unless-stopped
    ports:
      - "8080:8080"
    networks:
      - kb28_default
    environment:
      - INFLUXDB_TOKEN=$INFLUXDB_TOKEN
      - INFLUXDB_ORG=$INFLUXDB_ORG
      - INFLUXDB_BUCKET=$INFLUXDB_BUCKET
      - MQTT_USERNAME=$MQTT_USERNAME
      - MQTT_PASSWORD=$MQTT_PASSWORD
      - REST_USERNAME=$REST_USERNAME
      - REST_PASSWORD=$REST_PASSWORD

      - INFLUXDB_URL=http://influx.mse.kb28.ch:8086
      - CLIENT_ID=Gateway-SoftwEng
      - MQTT_URL=tcp://mqtt.mse.kb28.ch:1883
      - MEASUREMENT_NAME=THC
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.Gateway-http.entrypoints=http"
      - "traefik.http.routers.Gateway-http.rule=Host(`rest.mse.kb28.ch`)"
      - "traefik.http.middlewares.Gateway-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.Gateway-https.entrypoints=https"
      - "traefik.http.routers.Gateway-https.rule=Host(`rest.mse.kb28.ch`)"
      - "traefik.http.routers.Gateway-https.tls.certResolver=letsencrypt"
      - "traefik.http.services.Gateway-https.loadbalancer.server.port=8080"
  influxdb:
    image: influxdb:2
    container_name: influxdb
    hostname: influx
    restart: unless-stopped
    volumes:
      - influxdb2-data:/var/lib/influxdb2
      - influxdb2-config:/etc/influxdb2
    ports:
      - "8086:8086"
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=$INFLUXDB_USER
      - DOCKER_INFLUXDB_INIT_PASSWORD=$INFLUXDB_PASSWORD
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=$INFLUXDB_TOKEN
      - DOCKER_INFLUXDB_INIT_ORG=$INFLUXDB_ORG
      - DOCKER_INFLUXDB_INIT_BUCKET=$INFLUXDB_BUCKET
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.influx-http.entrypoints=http"
      - "traefik.http.routers.influx-http.rule=Host(`influx.mse.kb28.ch`)"
      - "traefik.http.middlewares.influx-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.influx-https.entrypoints=https"
      - "traefik.http.routers.influx-https.rule=Host(`influx.mse.kb28.ch`)"
      - "traefik.http.routers.influx-https.tls.certResolver=letsencrypt"
      - "traefik.http.services.influx-https.loadbalancer.server.port=8086"
  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: rabbitmq
    hostname: mqtt
    restart: unless-stopped
    ports:
      - "5672:5672"     # Management plugin TLS port
      - "15672:15672"   # Management plugin HTTP port
      - "1883:1883"     # MQTT port
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=$MQTT_USERNAME
      - RABBITMQ_DEFAULT_PASS=$MQTT_PASSWORD
    command:
      sh -c "rabbitmq-plugins enable rabbitmq_mqtt && rabbitmq-server"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mqtt-http.entrypoints=http"
      - "traefik.http.routers.mqtt-http.rule=Host(`mqtt.mse.kb28.ch`)"
      - "traefik.http.middlewares.mqtt-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.mqtt-https.entrypoints=https"
      - "traefik.http.routers.mqtt-https.rule=Host(`mqtt.mse.kb28.ch`)"
      - "traefik.http.routers.mqtt-https.tls.certResolver=letsencrypt"
      - "traefik.http.services.mqtt-https.loadbalancer.server.port=1883"
