boardgame-manager/boardgame-manager.nomad.hcl

105 lines
2.3 KiB
HCL
Raw Normal View History

2023-10-14 00:20:49 +02:00
[[ $c := merge .bgm . -]]
2024-01-26 22:30:40 +01:00
job "[[ .instance ]]" {
2023-10-14 00:20:49 +02:00
2024-01-26 22:30:40 +01:00
[[ template "common/job_start" $c ]]
2023-10-14 00:20:49 +02:00
group "boardgame-manager" {
2024-01-26 22:30:40 +01:00
2023-10-14 00:20:49 +02:00
network {
mode = "bridge"
}
service {
2024-01-26 22:30:40 +01:00
name = "[[ .instance ]][[ .consul.suffix ]]"
2023-10-14 00:20:49 +02:00
port = 8080
2023-12-21 22:13:43 +01:00
[[ template "common/connect" $c ]]
2023-10-14 00:20:49 +02:00
tags = [
2024-01-26 23:32:12 +01:00
[[ template "common/traefik_tags" $c ]]
2023-10-14 00:20:49 +02:00
]
}
2023-10-27 15:52:33 +02:00
volume "data" {
type = [[ .bgm.volumes.data.type | toJSON ]]
source = [[ .bgm.volumes.data.source | toJSON ]]
[[- if ne .bgm.volumes.data.type "host" ]]
2023-10-14 00:20:49 +02:00
attachment_mode = "file-system"
access_mode = "single-node-writer"
[[- end ]]
2023-10-14 00:20:49 +02:00
}
2023-10-27 15:52:33 +02:00
[[ 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" ]]
2023-10-27 15:52:33 +02:00
attachment_mode = "file-system"
access_mode = "multi-node-multi-writer"
[[- end ]]
2023-10-27 15:52:33 +02:00
}
[[- end ]]
2023-10-14 00:20:49 +02:00
task "boardgame-manager" {
2024-01-26 22:30:40 +01:00
driver = "[[ $c.nomad.driver ]]"
2023-10-14 00:20:49 +02:00
config {
2024-01-26 22:30:40 +01:00
image = "[[ .bgm.image ]]"
pids_limit = 100
2023-10-14 00:20:49 +02:00
readonly_rootfs = true
}
env {
2023-12-21 22:13:43 +01:00
[[ template "common/env" $c.env ]]
2023-10-14 00:20:49 +02:00
}
volume_mount {
2023-10-27 15:52:33 +02:00
volume = "data"
2023-10-14 00:20:49 +02:00
destination = "/opt/bgm/databases"
}
2024-01-26 22:30:40 +01:00
[[ template "common/resources" $c ]]
2023-10-14 00:20:49 +02:00
}
2023-10-27 15:52:33 +02:00
[[ if and .bgm.backup.enabled (not (eq .bgm.backup.cron "")) -]]
task "backup" {
2024-01-26 22:30:40 +01:00
driver = "[[ $c.nomad.driver ]]"
2023-10-27 15:52:33 +02:00
lifecycle {
hook = "poststart"
sidecar = true
}
config {
2024-01-26 22:30:40 +01:00
image = "[[ .bgm.backup.image ]]"
2023-10-27 15:52:33 +02:00
pids_limit = 50
readonly_rootfs = true
2024-01-26 22:30:40 +01:00
command = "minit"
2023-10-27 15:52:33 +02:00
}
2024-01-26 22:30:40 +01:00
env {
MINIT_MAIN = "dump-sqlite /data/data.db /backup"
MINIT_MAIN_NAME = "sqlite-dumper"
MINIT_MAIN_KIND = "cron"
MINIT_MAIN_CRON = "[[ .bgm.backup.cron ]]"
2023-10-27 15:52:33 +02:00
}
# 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"
}
2023-12-21 22:13:43 +01:00
[[ template "common/resources" .bgm.backup.resources ]]
2023-10-27 15:52:33 +02:00
}
[[- end ]]
2023-10-14 00:20:49 +02:00
}
}