2022-07-08 23:24:03 +00:00
|
|
|
# Vars
|
|
|
|
# name = string*
|
|
|
|
# image = string*
|
|
|
|
# service_port = int
|
|
|
|
# ingress = bool
|
2022-07-25 17:44:37 +00:00
|
|
|
# sticky_disk = bool
|
2022-07-08 23:24:03 +00:00
|
|
|
# args = json(list[str])
|
|
|
|
# resources = dict(cpu = int, mem = int)
|
2022-08-30 22:16:08 +00:00
|
|
|
# env = json(dict(str: any))
|
2022-07-08 23:24:03 +00:00
|
|
|
# templates = json(list(dict(
|
|
|
|
# data = str,
|
|
|
|
# dest = str,
|
|
|
|
# change_mode = str,
|
|
|
|
# change_signal = str,
|
|
|
|
# left_delimiter = str,
|
|
|
|
# right_delimiter = str,
|
|
|
|
# )))
|
2022-08-30 22:16:08 +00:00
|
|
|
# host_volumes = json(list(dict(
|
|
|
|
# name = str,
|
|
|
|
# dest = str,
|
|
|
|
# read_only = bool,
|
|
|
|
# )))
|
2022-07-08 23:24:03 +00:00
|
|
|
# healthcheck = "/"
|
2022-10-27 21:28:34 +00:00
|
|
|
# upstreams = json(list(dict(
|
|
|
|
# destination_name = str,
|
|
|
|
# local_bind_port = int
|
|
|
|
# )))
|
2022-07-08 23:24:03 +00:00
|
|
|
# mysql = bool
|
|
|
|
# redis = bool
|
2022-07-27 21:41:13 +00:00
|
|
|
# vault = bool
|
2022-07-08 23:24:03 +00:00
|
|
|
job "[[.name]]" {
|
|
|
|
region = "global"
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
type = "service"
|
|
|
|
|
|
|
|
group "[[.name]]" {
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ with .count ]]count = [[ . ]][[ end ]]
|
2022-07-08 23:24:03 +00:00
|
|
|
network {
|
|
|
|
mode = "bridge"
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ if not (empty .service_port) -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
port "main" {
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ if default false .ingress -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
host_network = "loopback"
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
|
|
|
to = [[ .service_port ]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 17:44:37 +00:00
|
|
|
[[ if default false .sticky_disk ]]
|
|
|
|
ephemeral_disk {
|
|
|
|
migrate = true
|
|
|
|
sticky = true
|
|
|
|
}
|
|
|
|
[[ end ]]
|
|
|
|
|
2022-08-30 22:16:08 +00:00
|
|
|
[[ with .host_volumes -]]
|
|
|
|
[[ range $v := . | parseJSON -]]
|
|
|
|
volume "[[ $v.name ]]" {
|
|
|
|
type = "host"
|
2022-09-04 21:26:19 +00:00
|
|
|
read_only = [[ $v.read_only ]]
|
2022-08-30 22:16:08 +00:00
|
|
|
source = "[[ $v.name ]]"
|
|
|
|
}
|
|
|
|
[[ end ]]
|
|
|
|
[[ end -]]
|
|
|
|
|
2022-07-08 23:24:03 +00:00
|
|
|
[[ if not (empty .service_port) ]]
|
|
|
|
service {
|
|
|
|
name = "[[.name | replace "_" "-"]]"
|
|
|
|
port = "main"
|
|
|
|
|
|
|
|
[[ if default false .ingress ]]
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
2022-07-27 21:41:42 +00:00
|
|
|
local_service_port = [[ .service_port ]]
|
|
|
|
[[ if default false .mysql -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 4040
|
|
|
|
}
|
|
|
|
[[ end -]]
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ if default false .redis -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
upstreams {
|
|
|
|
destination_name = "redis"
|
|
|
|
local_bind_port = 6379
|
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-10-27 21:28:34 +00:00
|
|
|
[[ with .upstreams -]]
|
|
|
|
[[range $u := . | parseJSON -]]
|
|
|
|
upstreams {
|
|
|
|
destination_name = "[[ $u.destination_name ]]"
|
|
|
|
local_bind_port = [[ $u.local_bind_port ]]
|
|
|
|
}
|
|
|
|
[[ end ]]
|
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
2022-07-25 23:35:30 +00:00
|
|
|
memory = 20
|
|
|
|
memory_max = 50
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[[ end ]]
|
|
|
|
|
2022-07-25 22:52:02 +00:00
|
|
|
[[ if not (eq .healthcheck "") -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
check {
|
|
|
|
type = "http"
|
|
|
|
path = "[[ or .healthcheck "/" ]]"
|
|
|
|
port = "main"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "10s"
|
|
|
|
}
|
2022-07-25 22:52:02 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
|
|
|
|
tags = [
|
|
|
|
[[ if default false .ingress -]]
|
|
|
|
"traefik.enable=true",
|
|
|
|
"traefik.http.routers.[[.name]].entryPoints=websecure",
|
2022-09-06 21:47:06 +00:00
|
|
|
[[ if not (empty .ingress_rule) -]]
|
|
|
|
"traefik.http.routers.[[.name]].rule=[[.ingress_rule]]",
|
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
[[ end -]]
|
|
|
|
]
|
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
|
|
|
|
task "[[.name]]" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "[[.image]]"
|
|
|
|
[[ if not (empty .service_port) -]]
|
|
|
|
ports = ["main"]
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
[[ if not (empty .args) -]]
|
|
|
|
args = ["[[ .args | parseJSON | join `", "` ]]"]
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ with .templates -]]
|
|
|
|
[[ range $t := . | parseJSON -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
mount {
|
|
|
|
type = "bind"
|
|
|
|
target = "[[ $t.dest ]]"
|
|
|
|
source = "local/[[ $t.dest ]]"
|
|
|
|
}
|
|
|
|
[[ end ]]
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-27 21:41:13 +00:00
|
|
|
[[ if default false .vault -]]
|
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
[[ end -]]
|
|
|
|
|
2022-07-08 23:24:03 +00:00
|
|
|
[[ with .env -]]
|
|
|
|
env = {
|
2022-08-30 22:16:08 +00:00
|
|
|
[[ range $k, $v := . | parseJSON -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
"[[$k]]" = "[[$v]]"
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
|
2022-08-30 22:16:08 +00:00
|
|
|
[[ with .host_volumes -]]
|
|
|
|
[[ range $v := . | parseJSON -]]
|
|
|
|
volume_mount {
|
|
|
|
volume = "[[ $v.name ]]"
|
|
|
|
destination = "[[ $v.dest ]]"
|
2022-09-04 21:26:19 +00:00
|
|
|
read_only = [[ $v.read_only ]]
|
2022-08-30 22:16:08 +00:00
|
|
|
}
|
|
|
|
[[ end ]]
|
|
|
|
[[ end -]]
|
|
|
|
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ with .templates -]]
|
|
|
|
[[ range $t := . | parseJSON -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
[[ $t.data ]]
|
|
|
|
EOF
|
|
|
|
destination = "local/[[ $t.dest ]]"
|
|
|
|
[[ with $t.left_delimiter ]]left_delimiter = "[[ . ]]"[[ end -]]
|
|
|
|
[[ with $t.right_delimiter ]]right_delimiter = "[[ . ]]"[[ end -]]
|
|
|
|
[[ with $t.change_mode ]]change_mode = "[[ . ]]"[[ end -]]
|
|
|
|
[[ with $t.change_signal ]]change_signal = "[[ . ]]"[[ end -]]
|
|
|
|
[[ with $t.env ]]env = [[ . ]][[ end ]]
|
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ with .resources -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
resources {
|
|
|
|
cpu = [[ .cpu ]]
|
|
|
|
memory = [[ .memory ]]
|
|
|
|
}
|
2022-07-27 21:41:42 +00:00
|
|
|
[[ end -]]
|
2022-07-08 23:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|