variable "base_hostname" { type = string description = "Base hostname to serve content from" default = "dev.homelab" } job "traefik" { datacenters = ["dc1"] type = "service" priority = 100 constraint { attribute = "${node.class}" value = "ingress" } constraint { distinct_hosts = true } update { max_parallel = 1 # canary = 1 # auto_promote = true auto_revert = true } group "traefik" { count = 1 network { port "web" { static = 80 } port "websecure" { static = 443 } port "syslog" { static = 514 } } ephemeral_disk { migrate = true sticky = true } service { name = "traefik" provider = "nomad" port = "web" check { type = "http" path = "/ping" port = "web" interval = "10s" timeout = "2s" } tags = [ "traefik.enable=true", "traefik.http.routers.traefik.entryPoints=websecure", "traefik.http.routers.traefik.service=api@internal", ] } task "traefik" { driver = "docker" meta = { "diun.sort_tags" = "semver" "diun.watch_repo" = true "diun.include_tags" = "^[0-9]+\\.[0-9]+$" } config { image = "traefik:2.9" ports = ["web", "websecure"] network_mode = "host" mount { type = "bind" target = "/etc/traefik" source = "local/config" } mount { type = "bind" target = "/etc/traefik/usersfile" source = "secrets/usersfile" } } template { # Avoid conflict with TOML lists [[ ]] and Go templates {{ }} left_delimiter = "<<" right_delimiter = ">>" data = <><< .base_hostname >><< end >>" [entryPoints.metrics] address = ":8989" [entryPoints.syslogtcp] address = ":514" [entryPoints.syslogudp] address = ":514/udp" [api] dashboard = true [ping] entrypoint = "web" [metrics] [metrics.prometheus] entrypoint = "metrics" # manualRouting = true [providers.file] directory = "/etc/traefik/conf" watch = true [providers.nomad] exposedByDefault = false defaultRule = "Host(`{{normalize .Name}}.<< with nomadVar "nomad/jobs" >><< .base_hostname >><< end >>`)" [providers.nomad.endpoint] address = "http://<< env "attr.unique.network.ip-address" >>:4646" << if nomadVarExists "nomad/jobs/traefik" ->> [certificatesResolvers.letsEncrypt.acme] email = "<< with nomadVar "nomad/jobs/traefik" >><< .acme_email >><< end >>" # Store in /local because /secrets doesn't persist with ephemeral disk storage = "/local/acme.json" [certificatesResolvers.letsEncrypt.acme.dnsChallenge] provider = "cloudflare" resolvers = ["1.1.1.1:53", "8.8.8.8:53"] delayBeforeCheck = 0 <<- end >> EOH destination = "local/config/traefik.toml" } template { data = <