job "weewx" {
  datacenters = ["alo"]

  meta {
    uuid = uuidv4()
  }

  group "weather" {
    network {
      port "http" {
      }
      port "osweather" {
        static = 20080
        to = 80
      }
    }

    task "backend" {
      driver = "docker"

      config {
        image = "gitea.v.paler.net/alo/weewx:latest"
        # to be able to receive UDP broadcast packets from the weatherlink
        network_mode = "host"
        volumes = [
          "/data/services/weewx/etc:/etc/weewx",
          "/data/services/weewx/html:/var/www/html",
        ]
      }

      resources {
        memory = 1500
      }
    }

    task "frontend" {
      driver = "docker"

      config {
        image = "pierrezemb/gostatic"

        ports = [ "http" ]

        args = [
          "-port=${NOMAD_PORT_http}",
          "-enable-health",
        ]

        volumes = [ "/data/services/weewx/html:/srv/http" ]
      }
    }

    task "osweather" {
      driver = "docker"

      config {
        image = "gitea.v.paler.net/alo/opensprinkler-weather:latest"

        ports = [ "osweather" ]
      }
    }

    service {
      name = "weather"
      port = "http"

      tags = [
        "traefik.enable=true",
        "traefik.http.routers.weather.entryPoints=websecure,web4proxy",
        "traefik.http.routers.weather.rule=Host(`weewx.v.paler.net`) || (Host(`alo.land`) && PathPrefix(`/weather`))",
        "traefik.http.routers.weather.priority=300",  # to override the longer rule for wordpress
      ]

      check {
        type = "http"
        path = "/health"
        interval = "10s"
        timeout = "2s"
      } 
    }

    service {
      name = "osweather"
      port = "osweather"
    }
  }
}
