boardgame-manager/boardgame-manager.nomad.hcl

105 lines
2.3 KiB
HCL

[[ $c := merge .bgm . -]]
job "[[ .instance ]]" {
[[ template "common/job_start" $c ]]
group "boardgame-manager" {
network {
mode = "bridge"
}
service {
name = "[[ .instance ]][[ .consul.suffix ]]"
port = 8080
[[ template "common/connect" $c ]]
tags = [
[[ template "common/traefik_tags" $c ]]
]
}
volume "data" {
type = [[ .bgm.volumes.data.type | toJSON ]]
source = [[ .bgm.volumes.data.source | toJSON ]]
[[- if ne .bgm.volumes.data.type "host" ]]
attachment_mode = "file-system"
access_mode = "single-node-writer"
[[- end ]]
}
[[ if and .bgm.backup.enabled (not (eq .bgm.backup.cron "")) -]]
volume "backup" {
type = [[ .bgm.volumes.backup.type | toJSON ]]
source = [[ .bgm.volumes.backup.source | toJSON ]]
[[- if ne .bgm.volumes.backup.type "host" ]]
attachment_mode = "file-system"
access_mode = "multi-node-multi-writer"
[[- end ]]
}
[[- end ]]
task "boardgame-manager" {
driver = "[[ $c.nomad.driver ]]"
config {
image = "[[ .bgm.image ]]"
pids_limit = 100
readonly_rootfs = true
}
env {
[[ template "common/env" $c.env ]]
}
volume_mount {
volume = "data"
destination = "/opt/bgm/databases"
}
[[ template "common/resources" $c ]]
}
[[ if and .bgm.backup.enabled (not (eq .bgm.backup.cron "")) -]]
task "backup" {
driver = "[[ $c.nomad.driver ]]"
lifecycle {
hook = "poststart"
sidecar = true
}
config {
image = "[[ .bgm.backup.image ]]"
pids_limit = 50
readonly_rootfs = true
command = "minit"
}
env {
MINIT_MAIN = "dump-sqlite /data/data.db /backup"
MINIT_MAIN_NAME = "sqlite-dumper"
MINIT_MAIN_KIND = "cron"
MINIT_MAIN_CRON = "[[ .bgm.backup.cron ]]"
}
# Mount the data volume readonly so we can read the DB
volume_mount {
volume = "data"
destination = "/data"
read_only = true
}
# Mount the backup volume
volume_mount {
volume = "backup"
destination = "/backup"
}
[[ template "common/resources" .bgm.backup.resources ]]
}
[[- end ]]
}
}