traefik/traefik.nomad.hcl

172 lines
4.3 KiB
HCL
Raw Permalink Normal View History

2024-01-19 22:35:23 +01:00
job "[[ .instance ]]" {
2023-10-08 18:10:14 +02:00
2024-04-09 10:27:46 +02:00
[[ template "common/job_start" . ]]
group "traefik" {
2024-04-09 10:27:46 +02:00
[[ $c := merge .traefik . ]]
[[ template "common/group_start" $c ]]
network {
mode = "bridge"
2023-08-21 16:05:28 +02:00
2024-01-19 22:35:23 +01:00
[[- range $name, $def := $c.entrypoints ]]
2023-10-16 14:01:16 +02:00
[[- if or (not (has $def "enabled")) ($def.enabled) ]]
port "[[ $name ]]" {
2023-10-16 14:01:16 +02:00
[[- if has $def "static" ]]
static = [[ $def.static ]]
2023-10-16 14:01:16 +02:00
[[- end ]]
[[- if has $def "to" ]]
to = [[ $def.to ]]
2023-10-16 14:01:16 +02:00
[[- end ]]
}
2023-10-16 14:01:16 +02:00
[[- end ]]
[[- end ]]
2024-03-27 13:15:53 +01:00
[[- if conv.ToBool $c.prometheus.enabled ]]
port "metrics" {}
[[- end ]]
}
service {
2024-01-19 22:35:23 +01:00
name = "[[ .instance ]]-sidecar[[ .consul.suffix ]]"
port = "https"
2023-12-21 23:27:52 +01:00
[[ template "common/connect" $c ]]
}
service {
2024-01-19 22:35:23 +01:00
name = "[[ .instance ]][[ .consul.suffix ]]"
port = "https"
task = "traefik"
2024-03-25 13:24:01 +01:00
[[ template "common/service_meta" $c ]]
# Traefik supports native Consul service mesh
connect {
native = true
}
tags = [
2024-01-28 23:54:36 +01:00
[[- $a := merge $c.api $c ]]
"[[ .instance ]].http.routers.[[ .instance ]]-api.rule=(Host(`[[ ($c.public_url | urlParse).Hostname ]]`) || HostRegexp(`(.+\\.)?[[ .instance ]].service.[[ .consul.domain ]]`)) && (PathPrefix(`/api`) || PathPrefix(`[[ (.traefik.public_url | urlParse).Path ]]`))",
2023-12-21 23:27:52 +01:00
"[[ .instance ]].http.routers.[[ .instance ]]-api.service=api@internal",
2024-01-28 23:54:36 +01:00
[[ template "common/traefik_tags" $a ]]
2024-01-28 23:54:36 +01:00
[[- $p := merge $c.ping $c ]]
2023-12-21 23:27:52 +01:00
"[[ .instance ]].http.routers.[[ .instance ]]-ping.rule=(Host(`[[ (.traefik.public_url | urlParse).Hostname ]]`) || HostRegexp(`(.+\\.)?[[ .instance ]].service.[[ .consul.domain ]]`)) && Path(`/ping`) && Method(`GET`)",
"[[ .instance ]].http.routers.[[ .instance ]]-ping.service=ping@internal",
2024-01-28 23:54:36 +01:00
[[ template "common/traefik_tags" $p ]]
2023-08-21 16:05:28 +02:00
"traefik-${NOMAD_ALLOC_INDEX}"
]
}
2024-03-27 13:15:53 +01:00
[[- template "common/task.metrics_proxy" $c ]]
task "traefik" {
2024-01-19 22:35:23 +01:00
driver = "[[ $c.nomad.driver ]]"
user = 5443
2024-04-29 22:27:31 +02:00
[[ template "common/vault.policies" $c ]]
config {
2024-04-29 22:27:31 +02:00
image = "[[ .traefik.image]]"
readonly_rootfs = true
pids_limit = 300
command = "traefik"
args = [
2023-10-18 09:31:43 +02:00
"--configfile=/secrets/traefik.yml"
]
}
# Main traefik configuration
template {
data =<<_EOF
2024-03-27 13:15:53 +01:00
[[ template "traefik/traefik.yml.tpl" $c ]]
_EOF
2023-10-18 09:31:43 +02:00
destination = "secrets/traefik.yml"
perms = "0400"
uid = 105443
gid = 100000
}
2023-08-29 23:19:28 +02:00
# Dynamic file configuration
2024-01-28 23:17:09 +01:00
[[- range $file := coll.Slice "basicauth" "lemonldap" "certificates" "ip" "performance" "security" "proxy" ]]
template {
data =<<_EOF
2023-08-21 16:05:28 +02:00
[[ tmpl.Exec (printf "traefik/config/%s.yml.tpl" $file) $ ]]
_EOF
destination = "secrets/config/[[ $file ]].yml"
2023-08-21 16:05:28 +02:00
change_mode = "noop"
perms = "0400"
uid = 105443
gid = 100000
}
[[ end -]]
2024-01-19 22:35:23 +01:00
[[ template "common/resources" $c ]]
}
2023-10-08 18:10:14 +02:00
[[- if .lemonldap.enabled ]]
[[- $c = merge .lemonldap . ]]
# LL::NG handler for sso
2024-01-04 11:27:27 +01:00
task "lemonldap-ng-handler" {
2024-01-19 22:35:23 +01:00
driver = "[[ $c.nomad.driver ]]"
2023-10-08 18:10:14 +02:00
config {
2024-01-19 22:35:23 +01:00
image = "[[ .lemonldap.image ]]"
2023-10-08 18:10:14 +02:00
volumes = [
"secrets/lemonldap-ng.ini:/etc/lemonldap-ng/lemonldap-ng.ini:ro",
]
# Add a tmpfs to store config and session cache
[[ template "common/tmpfs" dict "size" "10000000" "target" "/tmp" ]]
2023-10-08 18:10:14 +02:00
}
lifecycle {
hook = "prestart"
sidecar = true
}
2024-01-04 11:27:27 +01:00
env {
LLNG_SOCKET_PROTO = "http"
LLNG_LISTEN = "127.0.0.1:8183"
SOURCE_SERVER = "traefik"
2024-01-19 22:35:23 +01:00
MINIT_UNIT_DIR = "/local/minit.d"
2024-01-04 11:27:27 +01:00
}
2024-01-19 22:35:23 +01:00
[[ template "common/file_env" $c ]]
2023-10-08 18:10:14 +02:00
vault {
2023-12-21 23:27:52 +01:00
policies = ["[[ .instance ]][[ .consul.suffix ]]"]
2023-10-08 18:10:14 +02:00
env = false
disable_file = true
}
template {
data =<<_EOT
[[ template "traefik/lemonldap-ng.ini.tpl" . ]]
_EOT
2023-10-08 18:10:14 +02:00
destination = "secrets/lemonldap-ng.ini"
perms = "0400"
uid = 100048
gid = 100048
}
2024-01-04 11:27:27 +01:00
template {
data =<<_EOT
2024-01-19 22:35:23 +01:00
[[ template "traefik/minit.yml.tpl" . ]]
2024-01-04 11:27:27 +01:00
_EOT
2024-01-19 22:35:23 +01:00
destination = "local/minit.d/lemonldap-ng.yml"
2024-01-04 11:27:27 +01:00
}
2024-01-19 22:35:23 +01:00
[[ template "common/resources" $c ]]
2023-10-08 18:10:14 +02:00
}
[[- end ]]
}
}
# vim: syntax=hcl