90 lines
3.0 KiB
HCL
90 lines
3.0 KiB
HCL
[[ $c := merge .diagrams . -]]
|
|
job [[ .instance | toJSON ]] {
|
|
|
|
[[ template "common/job_start.tpl" $c ]]
|
|
|
|
group "diagrams" {
|
|
network {
|
|
mode = "bridge"
|
|
}
|
|
|
|
service {
|
|
name = "[[ .instance ]][[ .consul.suffix ]]"
|
|
port = 8282
|
|
|
|
[[ template "common/connect.tpl" $c ]]
|
|
|
|
check {
|
|
type = "http"
|
|
path = "/health"
|
|
expose = true
|
|
interval = "1m"
|
|
timeout = "8s"
|
|
|
|
check_restart {
|
|
limit = 4
|
|
grace = "1m"
|
|
}
|
|
}
|
|
|
|
tags = [
|
|
"[[ $c.traefik.instance ]].enable=[[ $c.traefik.enabled ]]",
|
|
|
|
# Define a middleware to set custom CSP headers
|
|
"[[ $c.traefik.instance ]].http.middlewares.[[ .instance ]]-headers[[ .consul.suffix ]].headers.contentsecuritypolicy=[[ range $k, $v := $c.traefik.csp ]][[ $k ]] [[ $v ]];[[ end ]]",
|
|
|
|
[[- if not (regexp.Match "^/?$" (urlParse $c.public_url).Path) ]]
|
|
# Diagrams exposed by traefik on a subpath. Define a middleware to strip the prefix before passing the request to the backend
|
|
"[[ $c.traefik.instance ]].http.middlewares.[[ .instance ]]-prefix[[ .consul.suffix ]].stripprefix.prefixes=[[ (urlParse .diagrams.public_url).Path ]]",
|
|
[[- end ]]
|
|
|
|
# Main app router
|
|
"[[ $c.traefik.instance ]].http.routers.[[ .instance ]][[ .consul.suffix ]].rule=Host(`[[ (urlParse $c.public_url).Hostname ]]`)
|
|
[[- if not (regexp.Match "^/?$" (urlParse $c.public_url).Path) ]] && PathPrefix(`[[ (urlParse $c.public_url).Path ]]`)[[ end ]]",
|
|
"[[ $c.traefik.instance ]].http.routers.[[ .instance ]][[ .consul.suffix ]].entrypoints=[[ join $c.traefik.entrypoints "," ]]",
|
|
[[- if not (regexp.Match "^/?$" (urlParse $c.public_url).Path) ]]
|
|
"[[ $c.traefik.instance ]].http.routers.[[ .instance ]][[ .consul.suffix ]].middlewares=[[ .instance ]]-prefix[[ $c.consul.suffix ]],[[ .instance ]]-headers[[ .consul.suffix ]],[[ template "common/traefik_middlewares.tpl" $c.traefik ]]",
|
|
[[- else ]]
|
|
"[[ $c.traefik.instance ]].http.routers.[[ .instance ]][[ .consul.suffix ]].middlewares=[[ .instance ]]-headers[[ .consul.suffix ]],[[ template "common/traefik_middlewares.tpl" $c.traefik ]]",
|
|
[[- end ]]
|
|
]
|
|
}
|
|
|
|
task "diagrams" {
|
|
driver = [[ $c.nomad.driver | toJSON ]]
|
|
|
|
config {
|
|
image = [[ $c.image | toJSON ]]
|
|
pids_limit = 200
|
|
readonly_rootfs = true
|
|
volumes = [
|
|
"local/PreConfig.js:/opt/tomcat/webapps/draw/js/PreConfig.js",
|
|
"local/PostConfig.js:/opt/tomcat/webapps/draw/js/PostConfig.js"
|
|
]
|
|
}
|
|
|
|
env {
|
|
JAVA_OPTS = "-Djava.io.tmpdir=/local"
|
|
TOMCAT_ADDRESS = "127.0.0.1"
|
|
}
|
|
|
|
template {
|
|
data =<<_EOT
|
|
[[ template "diagrams/PreConfig.js.tpl" $c ]]
|
|
_EOT
|
|
destination = "local/PreConfig.js"
|
|
}
|
|
|
|
template {
|
|
data =<<_EOT
|
|
[[ template "diagrams/PostConfig.js.tpl" $c ]]
|
|
_EOT
|
|
destination = "local/PostConfig.js"
|
|
}
|
|
|
|
[[ template "common/file_env.tpl" $c.env ]]
|
|
[[ template "common/resources.tpl" $c.resources ]]
|
|
}
|
|
}
|
|
}
|