version: '3'

services:

  zigbee_home_2:
    container_name: zigbee_home_2
    logging:
      driver: "json-file"
      options:
        max-size: "5m"
        max-file: "3"
    networks:
      - backend
    image: koenkk/zigbee2mqtt:1.33.2
    restart: always
    volumes:
      - ./zigbee_home_2:/app/data
      - ./zigbee_home_2/configuration_home_2.yaml:/app/data/configuration.yaml
    devices:
      - /dev/ttyUSB-zigbee_home_2:/dev/ttyACM0
    environment:
      - UID=1000
      - GID=1000
      - TZ=Europe/Stockholm
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.services.zighome-service.loadBalancer.server.port=8080"
      - "traefik.http.routers.zighome-secure.entrypoints=web-secure"
      - "traefik.http.routers.zighome-secure.rule=Host(`zig2.${DOMAIN}`)"
      - "traefik.http.routers.zighome-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.zighome-secure.middlewares=chain-authelia@file"
      - "traefik.http.routers.zighome-secure.tls=true"

  zigbee2mqtt:
    container_name: zigbee2mqtt
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    image: koenkk/zigbee2mqtt:1.33.2
    restart: always
    volumes:
      - ${DIR}/zigbee2matt:/app/data
      - ./zigbee2mqtt/configuration.yaml:/app/data/configuration.yaml
      - ${DIR}/zigbee2mqtt_node_log:/root/.npm
    devices:
      - /dev/ttyACM1:/dev/ttyACM0
    environment:
      - UID=1000
      - GID=1000
      - TZ=Europe/Stockholm
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.services.zig1-service.loadBalancer.server.port=8081"
      - "traefik.http.routers.zig1-secure.entrypoints=web-secure"
      - "traefik.http.routers.zig1-secure.rule=Host(`zig1.${DOMAIN}`)"
      - "traefik.http.routers.zig1-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.zig1-secure.middlewares=chain-authelia@file"
      - "traefik.http.routers.zig1-secure.tls=true"


  influx:
    image: influxdb:2.6
    container_name: influxdb
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    restart: always
    ports:
      - "8087:8086"
    volumes:
      #  - ${DIR}/influx-data:/var/lib/influxdb
      - ${DIR}/influx_2-data:/var/lib/influxdb2
      #- ${DIR}/influx-data/influxdb.conf:/root/influxdb/influxdb.conf:ro
    environment:
      - INFLUXDB_DB=db0
      - INFLUXDB_ADMIN_USER=${INFLUX_ADMIN}
      - INFLUXDB_ADMIN_PASSWORD=${INFLUX_ADMIN_PASSWORD}
      - INFLUXD_LOG_LEVEL=INFO
      #- DOCKER_INFLUXDB_INIT_MODE=upgrade
      #- DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUX_ADMIN_PASSWORD}
      #- DOCKER_INFLUXDB_INIT_USERNAME=${INFLUX_ADMIN}
      #- DOCKER_INFLUXDB_INIT_ORG=milvert
      #- DOCKER_INFLUXDB_INIT_BUCKET=MilvertBucket
      #- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=MilvertAuth
      #- DOCKER_INFLUXDB_INIT_UPGRADE_V1_CONFIG=/root/influxdb/influxdb.conf
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.services.influx-service.loadBalancer.server.port=8086"
      #- "traefik.http.routers.influx.entryPoints=influx"
      - "traefik.http.routers.influx-secure.rule=host(`influx.${DOMAIN}`)"
      - "traefik.http.routers.influx-secure.entryPoints=web-secure"
      - "traefik.http.routers.influx-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.influx-secure.tls=true"
      - "traefik.http.routers.influx-secure.middlewares=chain-no-auth@file"
      #- "traefik.http.middlewares.webpg-mid.ipwhitelist.sourcerange=127.0.0.1/32, 10.0.0.1/24"
      # - "traefik.http.routers.influx-secure.middlewares=localNetwork@file"

  telegraf:
    image: telegraf:1.25
    container_name: telegraf
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    ports:
      - "8081:8081"
    volumes:
      - ./telegraf:/etc/telegraf
      - /var/run/docker.sock:/var/run/docker.sock:ro
    depends_on:
      - influx
    environment:
      - INFLUXDB_URL=http://influxdb:8086
      - INFLUXDB_USERNAME=${INFLUX_ADMIN}
      - INFLUXDB_PASSWORD=${INFLUX_ADMIN_PASSWORD}
    labels:
      - diun.enable=true
      - "traefik.enable=false"
      - "traefik.http.services.telegraf-service.loadBalancer.server.port=8081"
      - "traefik.http.routers.telegraf-secure.entryPoints=influx"
      - "traefik.http.routers.telegraf-secure.rule=host(`telegraf.${DOMAIN}`)"
      #- "traefik.http.routers.influx-secure.middlewares=localNetwork@file"

  gitea:
    image: gitea/gitea:1.17
    container_name: gitea
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    restart: always
    environment:
      - USER_UID=1001
      - USER_GID=1005
    volumes:
      #- /var/lib/gitea:/data
      - ${DIR}/gitea:/data
      - /home/git/.ssh:/data/git/.ssh
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "127.0.0.1:2222:22"
      - "3000:3000"
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.services.gitea-service.loadbalancer.server.port=3000"
      - "traefik.http.routers.gitea-secure.entrypoints=web-secure"
      - "traefik.http.routers.gitea-secure.rule=Host(`gitea.${DOMAIN}`)"
      - "traefik.http.routers.gitea-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.gitea-secure.tls=true"
      - "traefik.http.routers.gitea-secure.middlewares=chain-no-auth@file"


  mqtt:
    # image: eclipse-mosquitto:1.6.13
    image: eclipse-mosquitto:2.0.17
    container_name: mqtt
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    restart: always
    ports:
      - "1883:1883"
      - "9003:9001"
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Stockholm
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
      - ${DIR}/mqtt/data:/mqtt/data
      - ${DIR}/mqtt/log:/mqtt/log
    labels:
      - "traefik.enable=false"
      - diun.enable=true
      #- "traefik.http.routers.mqtt.entrypoints=mqtt_http"
      #- "traefik.http.routers.mqtt.rule=Host(`mqtt.${DOMAIN}`)"
      #- "traefik.http.routers.mqtt.tls.certresolver=milvert_dns"
      #- "traefik.http.routers.mqtt.tls=false"
      #- "traefik.http.services.mqtt_http.loadBalancer.server.port=9001"
      #- "traefik.http.routers.mqtt.middlewares=localNetwork@file"
      #- "traefik.tcp.routers.mqtt_tcp.entrypoints=mqtt_stcp"
      #- "traefik.tcp.routers.mqtt_tcp.rule=HostSNI(`mqtt.milvert.com`)"
      #- "traefik.tcp.routers.mqtt_tcp.tls=true"
      #- "traefik.tcp.routers.mqtt_tcp.tls.certresolver=milvert_dns"
      #- "traefik.tcp.routers.mqtt_tcp.service=mqtt_tcp"
      #- "traefik.tcp.services.mqtt_tcp.loadBalancer.server.port=1883"

  mqtt_landet:
    image: eclipse-mosquitto:2.0.9
    container_name: mqtt_landet
    logging:
      options:
        max-size: "10m"
        max-file: "5"
    networks:
      - backend
    restart: always
    ports:
      - "1884:1884"
      - "9002:9002"
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=${TZ}
    labels:
      - diun.enable=true
    volumes:
      - ./mosquitto/mosquitto_landet.conf:/mosquitto/config/mosquitto.conf
      - ${DIR}/mqtt_landet/data:/mosquitto/data
      - ${DIR}/mqtt_landet/log:/mosquitto/log

  diun:
    image: ghcr.io/crazy-max/diun:4
    container_name: diun
    networks:
      - backend
    volumes:
      - ${DIR}/diun:/data
      - "./diun/diun.yml:/diun.yml:ro"
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - TZ=${TZ}
      - LOG_LEVEL=info
    restart: unless-stopped
    labels:
      - diun.enable=true

  ddns-updater:
    image: qmcgaw/ddns-updater:256
    container_name: ddns-updater
    restart: always
    networks:
      - backend
    ports:
      - 8000:8000/tcp
    volumes:
      - ${DIR}/ddns-updater:/updater/data
    environment:
      PUID: 1000
      PGID: 1004
      TZ: ${TZ}
      PERIOD: 1h
      UPDATE_COOLDOWN_PERIOD: 5m
      PUBLICIP_DNS_TIMEOUT: 3s
      HTTP_TIMEOUT: 10s
      # Web UI
      LISTENING_PORT: 8000
      # Backup
      BACKUP_PERIOD: 96h # 0 to disable
      BACKUP_DIRECTORY: /updater/data/backups
      # Other
      LOG_LEVEL: info
      SHOUTRRR_ADDRESSES: $TGRAM_SHOUTRRR_ADDRESS
    labels:
      - diun.enable=true

  pihole:
    image: pihole/pihole:2023.03.1
    container_name: pihole
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8001:80"
    dns:
      - 127.0.0.1
      - 9.9.9.9
    environment:
      - TZ=${TZ}
      - WEBPASSWORD=${PIHOLE_PW}
      - ServerIP=10.0.201
      - PIHOLE_DNS_=127.0.0.1;9.9.9.9;149.112.112.112;1.1.1.1
      - DNSSEC='true'
      - VIRTUAL_HOST=pihole.milvert.com # Same as port traefik config
      - WEBTHEME=default-dark
      - PIHOLE_DOMAIN=milvert.com
    volumes:
      - ${DIR}/pihole/etc:/etc/pihole
      - ${DIR}/pihole/dns:/etc/dnsmasq.d
    restart: unless-stopped
    networks:
      backend:
    labels:
      - diun.enable=true
      - "traefik.enable=true"
      - "traefik.http.middlewares.pihole-admin.addprefix.prefix=/admin"
      - "traefik.http.services.pihole.loadbalancer.server.port=80"
      - "traefik.http.routers.pihole-secure.middlewares=localNetwork@file"
      - "traefik.http.routers.pihole-secure.entrypoints=web-secure"
      - "traefik.http.routers.pihole-secure.rule=Host(`pihole.${DOMAIN}`)"
      - "traefik.http.routers.pihole-secure.tls.certresolver=milvert_dns"
      - "traefik.http.routers.pihole-secure.tls=true"
      - "traefik.http.routers.pihole-secure.middlewares=chain-no-auth@file"

networks:
  frontend:
    external: true
  backend:
    external: false
