2023-08-22 00:12:44 +02:00
job "unifi" {
2023-08-23 23:16:59 +02:00
datacenters = [ [ . nomad . datacenters | toJSON ] ]
2023-08-22 00:12:44 +02:00
2023-08-25 00:18:53 +02:00
group "unifi" {
2023-08-22 00:12:44 +02:00
network {
mode = "bridge"
port "stun" {}
}
2023-08-23 23:16:59 +02:00
service {
name = "unifi[[ .env.suffix ]]"
port = 8888
2023-08-22 00:12:44 +02:00
connect {
2023-08-23 23:16:59 +02:00
sidecar_service {
proxy {
[ [ - if has . proxy "service_name" ] ]
upstreams {
destination_name = [ [ . proxy . service_name | toJSON ] ]
local_bind_port = 3128
}
[ [ - end ] ]
2023-08-25 00:18:53 +02:00
upstreams {
destination_name = [ [ . mail . smtp_service_name | toJSON ] ]
local_bind_port = 25
}
2023-08-23 23:16:59 +02:00
}
}
2023-08-22 00:12:44 +02:00
sidecar_task {
[ [ template "common/resources.tpl" . envoy ] ]
}
}
tags = [
"[[ .env.traefik ]].enable = true " ,
2023-08-23 23:16:59 +02:00
"[[ .env.traefik ]].http.routers.unifi-inform[[ .env.suffix ]].rule = Host ( `
[ [ - ( urlParse . unifi . inform . public_url ) . Hostname - ] ]
` ) & & ( Path ( ` / inform ` ) | | PathPrefix ( ` / dl / firmware - cached ` ) ) " ,
2023-08-22 00:12:44 +02:00
"[[ .env.traefik ]].http.routers.unifi-inform[[ .env.suffix ]].entrypoints = [ [ join . unifi . inform . traefik . entrypoints "," ]]" ,
2023-08-23 23:16:59 +02:00
"[[ .env.traefik ]].http.routers.unifi-inform[[ .env.suffix ]].middlewares = [ [ join . unifi . inform . traefik . middlewares "," ]]" ,
"[[ .env.traefik ]].http.routers.unifi-controller[[ .env.suffix ]].rule = Host ( `
[ [ - ( urlParse . unifi . controller . public_url ) . Hostname - ] ] ` )
[ [ - if ne "" (urlParse .unifi.controller.public_url).Path ]] && PathPrefix(`[[ (urlParse .unifi.controller.public_url).Path ]]`)[[ end ]]" ,
"[[ .env.traefik ]].http.routers.unifi-controller[[ .env.suffix ]].entrypoints = [ [ join . unifi . controller . traefik . entrypoints "," ]]" ,
"[[ .env.traefik ]].http.routers.unifi-controller[[ .env.suffix ]].tls = true " ,
"[[ .env.traefik ]].http.routers.unifi-controller[[ .env.suffix ]].middlewares = [ [ join . unifi . controller . traefik . middlewares "," ]]" ,
"[[ .env.traefik ]].http.routers.unifi-portal[[ .env.suffix ]].rule = Host ( `
[ [ - ( urlParse . unifi . guest_portal . public_url ) . Hostname - ] ]
` ) & & PathPrefix ( ` / guest ` ) " ,
"[[ .env.traefik ]].http.routers.unifi-portal[[ .env.suffix ]].entrypoints = [ [ join . unifi . guest_portal . traefik . entrypoints "," ]]" ,
"[[ .env.traefik ]].http.routers.unifi-portal[[ .env.suffix ]].tls = true " ,
"[[ .env.traefik ]].http.routers.unifi-portal[[ .env.suffix ]].middlewares = [ [ join . unifi . guest_portal . traefik . middlewares "," ]]"
2023-08-22 00:12:44 +02:00
]
}
2023-08-23 23:16:59 +02:00
service {
name = "unifi-stun[[ .env.suffix ]]"
port = "stun"
2023-08-22 00:12:44 +02:00
tags = [
"[[ .env.traefik ]].enable = true " ,
2023-08-23 23:16:59 +02:00
"[[ .env.traefik ]].udp.routers.unifi-stun[[ .env.suffix ]].entrypoints = [ [ join . unifi . stun . traefik . entrypoints "," ]]" ,
"[[ .env.traefik ]].consulcatalog.connect = false "
2023-08-22 00:12:44 +02:00
]
}
2023-08-23 23:16:59 +02:00
service {
name = "unifi-mongo[[ .env.suffix ]]"
port = 27017
2023-08-22 00:12:44 +02:00
connect {
sidecar_service {}
sidecar_task {
[ [ template "common/resources.tpl" . envoy ] ]
}
}
2023-08-23 23:16:59 +02:00
check {
type = "script"
command = "sh"
args = [ "-c", "mongo --eval 'db.runCommand(\"ping\").ok'" ]
interval = "30s"
timeout = "5s"
task = "mongo"
}
2023-08-22 00:12:44 +02:00
}
2023-08-23 23:16:59 +02:00
volume "unifi-data" {
type = [ [ . unifi . controller . volume . type | toJSON ] ]
source = [ [ . unifi . controller . volume . source | toJSON ] ]
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
volume "unifi-mongo" {
type = [ [ . unifi . mongo . volume . type | toJSON ] ]
source = [ [ . unifi . mongo . volume . source | toJSON ] ]
access_mode = "single-node-writer"
attachment_mode = "file-system"
2023-08-22 00:12:44 +02:00
}
2023-08-23 23:16:59 +02:00
[ [ template "common/task.wait_for.tpl" dict
2023-08-22 00:12:44 +02:00
"ctx" .
"SERVICE_1" "unifi-mongo" ] ]
2023-08-23 23:16:59 +02:00
task "nginx" {
driver = [ [ . unifi . nginx . driver | toJSON ] ]
user = 8306
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
lifecycle {
hook = "poststart"
sidecar = "true"
}
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
config {
image = [ [ . unifi . nginx . image | toJSON ] ]
volumes = [ "local/nginx.conf:/etc/nginx/conf.d/default.conf" ]
}
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
template {
data = < < _EOF
[ [ template "unifi/nginx/nginx.conf.tpl" . ] ]
_EOF
destination = "local/nginx.conf"
}
[ [ template "common/resources.tpl" . unifi . nginx . resources ] ]
2023-08-22 00:12:44 +02:00
}
2023-08-25 00:18:53 +02:00
task "controller" {
2023-08-23 23:16:59 +02:00
leader = true
driver = [ [ . unifi . controller . driver | toJSON ] ]
config {
image = [ [ . unifi . controller . image | toJSON ] ]
volumes = [
"local/init-system.properties.sh:/entrypoint.d/10-init-system.properties.sh"
]
mount {
2023-08-24 11:08:39 +02:00
type = "tmpfs"
target = "/opt/unifi/run"
2023-08-23 23:16:59 +02:00
readonly = false
}
}
env {
JAVA_OPTS = "-Djava.awt.headless = true -Dlogback.configurationFile = / local / logback . xml
[[- if has .proxy "service_name" ]] -Dhttp.proxyHost = localhost -Dhttp.proxyPort = 3128 -Dhttps.proxyHost = localhost -Dhttps.proxyPort = 3128 -Dhttp.nonProxyHosts = [ [ join . proxy . no_proxy "|" ]][[ end ]]"
[ [ template "common/env.tpl" . unifi . controller . env ] ]
}
template {
data = < < _EOF
[ [ template "unifi/controller/system.properties.tpl" . ] ]
2023-08-22 00:12:44 +02:00
_EOF
2023-08-23 23:16:59 +02:00
destination = "secrets/system.properties"
}
template {
data = < < _EOF
[ [ template "unifi/controller/logback.xml.tpl" ] ]
_EOF
destination = "local/logback.xml"
}
template {
data = < < _EOF
[ [ template "unifi/controller/init-system.properties.sh.tpl" . ] ]
_EOF
destination = "local/init-system.properties.sh"
perms = "755"
}
volume_mount {
volume = "unifi-data"
destination = "/data"
}
[ [ template "common/resources.tpl" . unifi . controller . resources ] ]
2023-08-22 00:12:44 +02:00
}
2023-08-23 23:16:59 +02:00
task "mongo" {
driver = [ [ . unifi . mongo . driver | toJSON ] ]
2023-08-24 11:08:39 +02:00
user = 999
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
lifecycle {
hook = "prestart"
sidecar = "true"
}
config {
image = [ [ . unifi . mongo . image | toJSON ] ]
2023-08-24 11:08:39 +02:00
command = "mongod"
2023-08-23 23:16:59 +02:00
args = [
"--config" ,
"/local/mongod.conf"
]
}
template {
data = < < _EOF
[ [ template "unifi/mongo/mongod.conf.tpl" . ] ]
_EOF
destination = "local/mongod.conf"
}
2023-08-22 00:12:44 +02:00
2023-08-23 23:16:59 +02:00
volume_mount {
volume = "unifi-mongo"
2023-08-24 11:08:39 +02:00
destination = "/data/db"
2023-08-23 23:16:59 +02:00
}
[ [ template "common/resources.tpl" . unifi . mongo . resources ] ]
}
2023-08-22 00:12:44 +02:00
}
}