job "pihole" {
  region      = "global"
  datacenters = ["samfelag"]
  type        = "service"

  group "pihole" {
    count = 1

    volume "pihole" {
      type      = "host"
      read_only = false
      source    = "dns-pihole"
    }

    volume "dnsmasq" {
      type      = "host"
      read_only = false
      source    = "dns-dnsmasq"
    }

    restart {
      attempts = 5
      delay    = "15s"
    }

    network {
      port "dns" {
        static = 53
      }
      port "http" {
        to = 80
      }
    }

    task "pihole" {
      driver = "docker"

      volume_mount {
        volume      = "pihole"
        destination = "/etc/pihole"
        read_only   = false
      }

      volume_mount {
        volume      = "dnsmasq"
        destination = "/etc/dnsmasq.d"
        read_only   = false
      }

      env {
        TZ          = "Europe/Amsterdam"
        WEBPASSWORD = "elbonfeix"
        ServerIP    = "100.107.148.47"
      }

      config {
        image = "pihole/pihole:v5.7"
        ports = ["dns", "http"]
      }

      resources {
        cpu    = 100
        memory = 64
      }

      service {
        name = "pihole-gui"
        port = "http"
      }
    }
  }
}

