Update services template to support env and host volumes

Also adds sonarr as an example
This commit is contained in:
IamTheFij 2022-08-30 15:16:08 -07:00
parent 9c07141dd1
commit 92a60cbe3b
2 changed files with 57 additions and 2 deletions

View File

@ -6,6 +6,7 @@
# sticky_disk = bool # sticky_disk = bool
# args = json(list[str]) # args = json(list[str])
# resources = dict(cpu = int, mem = int) # resources = dict(cpu = int, mem = int)
# env = json(dict(str: any))
# templates = json(list(dict( # templates = json(list(dict(
# data = str, # data = str,
# dest = str, # dest = str,
@ -14,6 +15,11 @@
# left_delimiter = str, # left_delimiter = str,
# right_delimiter = str, # right_delimiter = str,
# ))) # )))
# host_volumes = json(list(dict(
# name = str,
# dest = str,
# read_only = bool,
# )))
# healthcheck = "/" # healthcheck = "/"
# mysql = bool # mysql = bool
# redis = bool # redis = bool
@ -45,6 +51,16 @@ job "[[.name]]" {
} }
[[ end ]] [[ end ]]
[[ with .host_volumes -]]
[[ range $v := . | parseJSON -]]
volume "[[ $v.name ]]" {
type = "host"
read_only = [[ default true $v.read_only ]]
source = "[[ $v.name ]]"
}
[[ end ]]
[[ end -]]
[[ if not (empty .service_port) ]] [[ if not (empty .service_port) ]]
service { service {
name = "[[.name | replace "_" "-"]]" name = "[[.name | replace "_" "-"]]"
@ -133,12 +149,22 @@ job "[[.name]]" {
[[ with .env -]] [[ with .env -]]
env = { env = {
[[ range $k, $v := . -]] [[ range $k, $v := . | parseJSON -]]
"[[$k]]" = "[[$v]]" "[[$k]]" = "[[$v]]"
[[ end -]] [[ end -]]
} }
[[ end -]] [[ end -]]
[[ with .host_volumes -]]
[[ range $v := . | parseJSON -]]
volume_mount {
volume = "[[ $v.name ]]"
destination = "[[ $v.dest ]]"
read_only = [[ default true $v.read_only ]]
}
[[ end ]]
[[ end -]]
[[ with .templates -]] [[ with .templates -]]
[[ range $t := . | parseJSON -]] [[ range $t := . | parseJSON -]]
template { template {

View File

@ -18,9 +18,38 @@ resource "nomad_job" "whoami" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { vars = {
"count" = "${2 * length(data.consul_service.nomad.service)}", "count" = 1,
# "count" = "${2 * length(data.consul_service.nomad.service)}",
} }
} }
jobspec = file("${path.module}/whoami.nomad") jobspec = file("${path.module}/whoami.nomad")
} }
module "sonarr" {
source = "./levant"
template_path = "service.nomad"
variables = {
name = "sonarr"
image = "linuxserver/sonarr"
service_port = 8989
ingress = true
env = jsonencode({
PGID = 100
PUID = 1001
})
host_volumes = jsonencode([
{
name = "media-write"
dest = "/srv/volumes/media-write"
read_only = false
},
{
name = "download"
dest = "/srv/volumes/download"
read_only = false
},
])
}
}