Add support for automatic backups

This commit is contained in:
Daniel Berteaud 2023-10-27 15:52:33 +02:00
parent 93e119d767
commit 6e7f6aadd7
2 changed files with 67 additions and 3 deletions

View File

@ -30,13 +30,22 @@ job [[ .bgm.instance | toJSON ]] {
]
}
volume "boardgame-manager" {
volume "data" {
type = [[ .bgm.volumes.data.type | toJSON ]]
source = [[ .bgm.volumes.data.source | toJSON ]]
attachment_mode = "file-system"
access_mode = "single-node-writer"
}
[[ if and .bgm.backup.enabled (not (eq .bgm.backup.cron "")) -]]
volume "backup" {
type = [[ $c.volumes.backup.type | toJSON ]]
source = [[ $c.volumes.backup.source | toJSON ]]
attachment_mode = "file-system"
access_mode = "multi-node-multi-writer"
}
[[- end ]]
task "boardgame-manager" {
driver = [[ $c.nomad.driver | toJSON ]]
@ -51,12 +60,54 @@ job [[ .bgm.instance | toJSON ]] {
}
volume_mount {
volume = "boardgame-manager"
volume = "data"
destination = "/opt/bgm/databases"
}
[[ template "common/resources.tpl" .bgm.resources ]]
}
[[ if and .bgm.backup.enabled (not (eq .bgm.backup.cron "")) -]]
task "backup" {
driver = [[ $c.nomad.driver | toJSON ]]
lifecycle {
hook = "poststart"
sidecar = true
}
config {
image = [[ .bgm.backup.image | toJSON ]]
pids_limit = 50
readonly_rootfs = true
command = "supercronic"
args = [
"/secrets/backup.cron"
]
}
template {
data =<<_EOT
[[ .bgm.backup.cron ]] dump-sqlite /data/data.db /backup
_EOT
destination = "secrets/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.tpl" .bgm.backup.resources ]]
}
[[- end ]]
}
}

View File

@ -17,11 +17,24 @@ bgm:
env: {}
# Boardgame manager needs a volume to store its SQLite DB
# And an optional volume for backups of the DB
volumes:
data:
type: csi
source: boardgame-manager
source: bgm-data
backup:
type: csi
source: bgm-backup
# Public URL where the app will be exposed
public_url: https://bgm.example.org
backup:
enabled: false
image: '[[ .docker.repo ]][[ .docker.base_images.sqlite.image ]]'
cron: '15 19 * * *'
resources:
cpu: 10
memory: 32