version: '3'

services:
    # openAger nodered
    nodered:
        build: 
          context: ./nodered
          args:
            - MOSQUITTO_PORT=${MOSQUITTO_PORT}
            - MQTT_URL=${MQTT_URL}
            - MYSQL_URL=${MYSQL_URL}
            - MYSQL_DATABASE=${MYSQL_DATABASE}
            - INFLUXDB_USER=${INFLUXDB_USER}
            - INFLUXDB_USER_PASSWORD=${INFLUXDB_USER_PASSWORD}
            - INFLUXDB_DB=${INFLUXDB_DB}
            - INFLUX_URL=${INFLUX_URL}
        ports:
            - '${NODE_PORT}:1880/tcp'
        volumes:
            - node-red:/data
        environment:
            - NODE_VIRTUAL_HOST
            - NODE_LETSENCRYPT_EMAIL
            - NODE_LETSENCRYPT_HOST
            - NODE_RED_CREDENTIAL_SECRET
            - NODE_RED_USER_AUTH
            - NODE_RED_ADMIN_AUTH
            - MQTT_URL
            - MOSQUITTO_PORT 
            - MYSQL_URL
            - MYSQL_DATABASE
            - TZ
            - INFLUXDB_USER
            - INFLUXDB_USER_PASSWORD
            - INFLUXDB_DB
            - INFLUX_URL
        restart: always
        networks:
            openager.local:

    # openAger mosquitto
    mosquitto:
        build: mosquitto/.
        ports:
            - '${MOSQUITTO_PORT}:1883/tcp'
            - '${MOSQUITTOS_PORT}:9001/tcp'
        volumes:
            - mosquitto_cfg:/mosquitto
            - mosquitto_data:/mosquitto/data
            - mosquitto_log:/mosquitto/log
        environment:
            - TZ
        restart: always    
        networks:
            openager.local:

    # openAger mariadb
    mariadb:
        build: ./mariadb
        volumes:
            - mariadb:/var/lib/mysql
        environment:
            - TZ
            - MYSQL_ROOT_PASSWORD
            - MYSQL_DATABASE
            - MYSQL_USER
            - MYSQL_PASSWORD
        restart: always
        networks:
            openager.local:

    # openAger phpMyAdmin
    phpmyadmin:
      image: phpmyadmin
      ports:
            - '${PHMMYADMIN_PORT}:80/tcp'
      environment:
            - PMA_HOST
      restart: always
      volumes:
          - phpmyadmin:/sessions
      networks:
            openager.local:

    # openAger influxDB 
    influxdb:
        build: ./influxdb
        volumes:
            - influxdb:/var/lib/influxdb
        environment:
            - TZ
            - INFLUXDB_ADMIN_USER
            - INFLUXDB_ADMIN_PASSWORD
            - INFLUXDB_USER
            - INFLUXDB_USER_PASSWORD
            - INFLUXDB_DB
        restart: always
        networks:
            openager.local:

    # openAger grafana
    grafana:
        build: ./grafana
        ports:
            - '${GRAFANA_PORT}:3000/tcp'
        volumes:
            - grafana:/etc/grafana
            - grafana-storage:/var/lib/grafana
        environment:
            - TZ
            - GRAFANA_VIRTUAL_HOST
            - GRAFANA_LETSENCRYPT_EMAIL
            - GRAFANA_LETSENCRYPT_HOST
        restart: always
        networks:
            openager.local:


# Volume definitions
volumes:
  node-red:
    driver: local
  mosquitto_cfg:
    driver: local
  mosquitto_log:
    driver: local
  mosquitto_data:
    driver: local
  mariadb:
    driver: local
  phpmyadmin:
    driver: local
  influxdb:
    driver: local
  grafana:
    driver: local  
  grafana-storage:
    driver: local

# Custom network so all services can communicate using a FQDN
networks:
    openager.local:
