2022-02-16 17:56:18 +00:00
|
|
|
variable "consul_address" {
|
|
|
|
type = string
|
|
|
|
description = "Full address of Consul instance to get catalog from"
|
|
|
|
default = "http://127.0.0.1:5400"
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "base_hostname" {
|
|
|
|
type = string
|
|
|
|
description = "Base hostname to serve content from"
|
|
|
|
default = "dev.homelab"
|
|
|
|
}
|
|
|
|
|
|
|
|
job "traefik" {
|
|
|
|
region = "global"
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
type = "service"
|
|
|
|
|
2022-02-27 22:49:00 +00:00
|
|
|
constraint {
|
|
|
|
attribute = "${node.class}"
|
|
|
|
value = "ingress"
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:56:18 +00:00
|
|
|
group "traefik" {
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
network {
|
|
|
|
port "web" {
|
|
|
|
static = 80
|
|
|
|
}
|
|
|
|
port "websecure" {
|
|
|
|
static = 443
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
name = "traefik"
|
|
|
|
port = "web"
|
|
|
|
|
|
|
|
check {
|
|
|
|
type = "http"
|
|
|
|
path = "/ping"
|
|
|
|
port = "web"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "2s"
|
|
|
|
}
|
|
|
|
|
|
|
|
connect {
|
|
|
|
native = true
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = [
|
|
|
|
"traefik.enable=true",
|
|
|
|
"traefik.http.routers.traefik_dashboard.entrypoints=web,websecure",
|
|
|
|
"traefik.http.routers.traefik_dashboard.rule=Host(`traefik.${var.base_hostname}`)",
|
|
|
|
"traefik.http.routers.traefik_dashboard.service=api@internal",
|
|
|
|
"traefik.http.routers.traefik_dashboard.tls=true",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
task "traefik" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "traefik:2.6"
|
|
|
|
args = [
|
|
|
|
"--log.level=DEBUG",
|
|
|
|
"--entryPoints.web.address=:80",
|
|
|
|
"--entryPoints.websecure.address=:443",
|
|
|
|
# "--entryPoints.websecure.tls=true",
|
2022-02-17 22:03:42 +00:00
|
|
|
"--entrypoints.web.http.redirections.entryPoint.to=websecure",
|
2022-02-16 17:56:18 +00:00
|
|
|
# "--entryPoints.admin.address=:8080",
|
|
|
|
"--accesslog=true",
|
|
|
|
"--api=true",
|
|
|
|
"--api.dashboard=true",
|
|
|
|
# "--metrics=true",
|
|
|
|
# "--metrics.prometheus=true",
|
|
|
|
# "--metrics.prometheus.entryPoint=admin",
|
|
|
|
# "--metrics.prometheus.manualrouting=true",
|
|
|
|
"--ping=true",
|
|
|
|
"--ping.entryPoint=web",
|
|
|
|
"--providers.consulcatalog=true",
|
|
|
|
"--providers.consulcatalog.connectaware=true",
|
|
|
|
"--providers.consulcatalog.connectbydefault=true",
|
|
|
|
"--providers.consulcatalog.exposedbydefault=false",
|
|
|
|
"--providers.consulcatalog.endpoint.address=${var.consul_address}",
|
|
|
|
"--providers.consulcatalog.servicename=traefik",
|
|
|
|
"--providers.consulcatalog.prefix=traefik",
|
2022-03-12 18:07:52 +00:00
|
|
|
"--providers.consulcatalog.defaultrule=Host(`{{normalize .Name}}.${var.base_hostname}`) || ({{hasKey .Labels \"subdomain\" }} && Host(`{{get .Labels \"subdomain\"}}.${var.base_hostname}`))",
|
2022-02-16 17:56:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
ports = ["web", "websecure"]
|
|
|
|
network_mode = "host"
|
|
|
|
|
|
|
|
volumes = []
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
2022-02-17 22:03:42 +00:00
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
2022-02-16 17:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|