hoppscotch/hoppscotch.nomad.hcl

124 lines
4.0 KiB
HCL

job "[[ .instance ]]" {
[[- $c := merge .hoppscotch .hoppscotch . ]]
[[ template "common/job_start" $c ]]
group "hoppscotch" {
[[- $c = merge .hoppscotch . ]]
[[ template "common/group_start" $c ]]
network {
mode = "bridge"
[[- if conv.ToBool $c.metrics.enabled ]]
port "metrics" {}
[[- end ]]
}
service {
name = "[[ .instance ]][[ .consul.suffix ]]"
port = 8487
[[ template "common/service_meta" $c ]]
[[ template "common/connect" $c ]]
check {
type = "http"
path = "/ping"
expose = true
[[ template "common/check_settings" $c ]]
}
tags = [
[[ template "common/traefik_tags" merge $c.backend $c ]]
[[ template "common/traefik_tags" merge $c.frontend.admin $c.frontend $c ]]
[[ template "common/traefik_tags" merge $c.frontend $c ]]
]
}
[[ template "common/task.wait_for" $c ]]
[[ template "common/task.pgpooler" $c ]]
[[ template "common/task.metrics_proxy" $c ]]
task "frontend" {
[[- $d := merge $c.frontend $c ]]
driver = "[[ $d.nomad.driver ]]"
config {
[[ template "common/image" $d ]]
pids_limit = 100
[[ template "common/tmpfs" "/tmp" ]]
volumes = ["local/nginx.conf:/etc/nginx/conf.d/default.conf:ro"]
}
env {
WEB_DIR = "/local/web"
VITE_BASE_URL = "[[ .hoppscotch.public_url ]]"
VITE_SHORTCODE_BASE_URL = "[[ .hoppscotch.public_url ]]"
VITE_ADMIN_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/admin"
VITE_BACKEND_GQL_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/graphql"
VITE_BACKEND_WS_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" | regexp.Replace "^http" "ws" ]]/graphql"
VITE_BACKEND_API_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/v1"
}
[[ template "common/file_env" $d ]]
template {
data = <<_EOT
[[ template "hoppscotch/nginx.conf" $d ]]
_EOT
destination = "local/nginx.conf"
}
[[ template "common/resources" $d ]]
}
task "backend" {
[[ $d := merge $c.backend $c ]]
driver = "[[ $d.nomad.driver ]]"
config {
[[ template "common/image" $d ]]
pids_limit = 200
}
[[ template "common/vault.policies" $d ]]
env {
PORT = 3012
LISTEN_IP = "127.0.0.1"
PNPM_HOME = "/local"
VITE_BASE_URL = "[[ .hoppscotch.public_url ]]"
VITE_SHORTCODE_BASE_URL = "[[ .hoppscotch.public_url ]]"
VITE_ADMIN_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/admin"
VITE_BACKEND_GQL_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/graphql"
VITE_BACKEND_WS_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" | regexp.Replace "^http" "ws" ]]/graphql"
VITE_BACKEND_API_URL = "[[ .hoppscotch.public_url | regexp.Replace "/$" "" ]]/v1"
}
[[ template "common/file_env" $d ]]
template {
data = <<_EOT
HOPPSCOTCH_RUN_MIGRATIONS={{- if eq (env "NOMAD_ALLOC_INDEX") "0" }}true{{ else }}false{{ end }}
DATABASE_URL=postgresql://
[[- /* Connect to the database. If a connection pooler is configured, replace parameters to point on the pooler
Else, directly connect to the database */]]
[[- if ne $d.postgres.pooler.engine "none" -]]
[[ .instance ]]:{{ env "NOMAD_ALLOC_ID" }}@127.0.0.1:[[ $d.postgres.pooler.port ]]/[[ $d.postgres.database ]]?sslmode=disable
WAIT_FOR_TARGETS=127.0.0.1:[[ $d.postgres.pooler.port ]]
[[- else -]]
[[ $d.postgres.user ]]:[[ $d.postgres.password | regexp.Replace "\\.Data\\.password" "urlquery .Data.password" ]]@[[ $d.postgres.host ]]:[[ $d.postgres.port ]]/[[ $d.postgres.database ]]
WAIT_FOR_TARGETS=[[ $d.postgres.host ]]:[[ $d.postgres.port ]]
[[- end ]]
_EOT
destination = "secrets/.db.env"
uid = [[ 0 | add $d.docker.userns.uid_shift ]]
gid = [[ 0 | add $d.docker.userns.gid_shift ]]
env = true
}
[[ template "common/resources" $d ]]
}
}
}