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 9ce1350b5f
commit 3bab881118
2 changed files with 57 additions and 2 deletions

View File

@ -6,6 +6,7 @@
# sticky_disk = bool
# args = json(list[str])
# resources = dict(cpu = int, mem = int)
# env = json(dict(str: any))
# templates = json(list(dict(
# data = str,
# dest = str,
@ -14,6 +15,11 @@
# left_delimiter = str,
# right_delimiter = str,
# )))
# host_volumes = json(list(dict(
# name = str,
# dest = str,
# read_only = bool,
# )))
# healthcheck = "/"
# mysql = bool
# redis = bool
@ -45,6 +51,16 @@ job "[[.name]]" {
}
[[ 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) ]]
service {
name = "[[.name | replace "_" "-"]]"
@ -133,12 +149,22 @@ job "[[.name]]" {
[[ with .env -]]
env = {
[[ range $k, $v := . -]]
[[ range $k, $v := . | parseJSON -]]
"[[$k]]" = "[[$v]]"
[[ 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 -]]
[[ range $t := . | parseJSON -]]
template {

View File

@ -18,9 +18,38 @@ resource "nomad_job" "whoami" {
hcl2 {
enabled = true
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")
}
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
},
])
}
}