mariadb/mariadb.nomad.hcl

218 lines
4.3 KiB
HCL
Raw Permalink Normal View History

2024-01-19 23:31:41 +01:00
job "[[ .instance ]]" {
2024-01-31 14:06:09 +01:00
[[- $c := merge .mariadb.server .mariadb . ]]
2023-12-21 22:47:19 +01:00
[[ template "common/job_start" $c ]]
2023-10-25 23:00:31 +02:00
group "server" {
network {
mode = "bridge"
}
2024-01-19 23:31:41 +01:00
[[ template "common/volumes" $c ]]
2023-10-25 23:00:31 +02:00
service {
2024-01-31 14:06:09 +01:00
name = "[[ .instance ]][[ .consul.suffix ]]"
2023-10-25 23:00:31 +02:00
port = 3306
2024-05-12 22:03:09 +02:00
[[ template "common/service_meta" $c ]]
2023-12-21 22:47:19 +01:00
[[ template "common/connect" $c ]]
2023-10-25 23:00:31 +02:00
check {
name = "alive"
type = "script"
task = "mariadb"
command = "mysqladmin"
args = [
"ping"
]
timeout = "10s"
interval = "5s"
}
tags = [
2024-01-31 14:06:09 +01:00
[[ template "common/traefik_tags" $c ]]
2023-10-25 23:00:31 +02:00
]
}
# Run mysql_upgrade
2023-10-25 23:08:38 +02:00
task "upgrade" {
2024-01-19 23:31:41 +01:00
driver = "[[ $c.nomad.driver ]]"
2023-10-25 23:00:31 +02:00
lifecycle {
hook = "poststart"
}
config {
2024-01-31 14:06:09 +01:00
image = "[[ .mariadb.server.image ]]"
2023-10-25 23:08:38 +02:00
pids_limit = 100
2024-01-31 14:06:09 +01:00
command = "/local/mysql_upgrade.sh"
2023-10-25 23:00:31 +02:00
}
2024-01-19 23:31:41 +01:00
[[ template "common/vault.policies" $c ]]
2023-10-25 23:00:31 +02:00
template {
data = <<_EOT
[client]
user = root
2023-10-25 23:08:38 +02:00
host = 127.0.0.1
2024-01-31 14:06:09 +01:00
password = {{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}{{ .Data.data.root_pwd }}{{ end }}
2023-10-25 23:00:31 +02:00
_EOT
destination = "secrets/.my.cnf"
2023-10-25 23:00:31 +02:00
uid = 100100
gid = 100101
perms = 640
}
template {
data = <<_EOT
[[ template "mariadb/mysql_upgrade.sh.tpl" $c ]]
_EOT
destination = "local/mysql_upgrade.sh"
perms = 755
}
2023-10-25 23:08:38 +02:00
volume_mount {
2024-01-19 23:31:41 +01:00
volume = "data"
2023-10-25 23:08:38 +02:00
destination = "/data"
}
2023-10-25 23:00:31 +02:00
resources {
cpu = 10
memory = 32
memory_max = 64
}
}
task "mariadb" {
2024-01-19 23:31:41 +01:00
driver = "[[ $c.nomad.driver ]]"
2023-10-25 23:00:31 +02:00
leader = true
kill_timeout = "5m"
config {
2024-01-19 23:31:41 +01:00
image = "[[ .mariadb.server.image ]]"
2023-10-25 23:00:31 +02:00
volumes = [
"secrets/:/etc/my.cnf.d",
"secrets/my.conf:/var/lib/mysql/.my.cnf:ro",
]
pids_limit = 300
#readonly_rootfs = true
}
2024-01-19 23:31:41 +01:00
[[ template "common/vault.policies" $c ]]
2023-10-25 23:00:31 +02:00
env {
MYSQL_CONF_11_bind-address = "127.0.0.1"
2023-12-21 22:47:19 +01:00
[[ template "common/env" $c.env ]]
2023-10-25 23:00:31 +02:00
}
template {
data = <<_EOT
2024-01-31 14:06:09 +01:00
{{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}
2023-10-25 23:00:31 +02:00
MYSQL_ROOT_PASSWORD={{ .Data.data.root_pwd }}
{{ end }}
_EOT
destination = "secrets/mariadb.env"
uid = 100000
gid = 100000
perms = 400
env = true
}
template {
data = <<_EOT
[client]
user = root
2024-01-31 14:06:09 +01:00
password = {{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}{{ .Data.data.root_pwd }}{{ end }}
2023-10-25 23:00:31 +02:00
_EOT
destination = "secrets/my.conf"
uid = 100100
gid = 100101
perms = 640
}
volume_mount {
2024-01-19 23:31:41 +01:00
volume = "data"
2023-10-25 23:00:31 +02:00
destination = "/data"
}
2024-01-19 23:31:41 +01:00
[[ template "common/resources" $c ]]
2023-10-25 23:00:31 +02:00
}
}
[[- if .mariadb.backup.dumps.enabled ]]
2024-01-19 23:31:41 +01:00
[[- $c := merge .mariadb.backup .mariadb . ]]
group "backup" {
2024-01-19 23:31:41 +01:00
network {
mode = "bridge"
}
2024-01-19 23:31:41 +01:00
[[ template "common/volumes" $c ]]
service {
2023-12-21 22:47:19 +01:00
name = "[[ .instance ]]-backup[[ $c.consul.suffix ]]"
[[ template "common/connect" $c ]]
}
2023-12-21 22:47:19 +01:00
[[ template "common/task.wait_for" $c ]]
task "backup" {
2024-01-19 23:31:41 +01:00
driver = "[[ $c.nomad.driver ]]"
config {
2024-01-19 23:31:41 +01:00
image = "[[ .mariadb.backup.image ]]"
pids_limit = 100
readonly_rootfs = true
2024-01-19 23:31:41 +01:00
command = "minit"
}
2024-01-19 23:31:41 +01:00
[[ template "common/vault.policies" $c ]]
env {
MINIT_UNIT_DIR = "/local/minit.d"
}
template {
data = <<_EOT
[client]
user = root
host = 127.0.0.1
2024-01-31 14:06:09 +01:00
password = {{ with secret "[[ .vault.root ]]kv/service/[[ .instance ]]" }}{{ .Data.data.root_pwd }}{{ end }}
_EOT
destination = "secrets/.my.cnf"
uid = 100000
gid = 100000
perms = 400
}
template {
data =<<_EOT
[[ template "mariadb/dump.sh.tpl" $c ]]
_EOT
destination = "local/dump.sh"
perms = 755
}
template {
data =<<_EOT
2024-01-19 23:31:41 +01:00
[[ template "mariadb/backup.minit.yml.tpl" $c ]]
_EOT
2024-01-19 23:31:41 +01:00
destination = "local/minit.d/backup.yml"
}
volume_mount {
volume = "backup"
destination = "/backup"
}
2024-01-19 23:31:41 +01:00
[[ template "common/resources" $c ]]
}
}
[[- end ]]
2023-10-25 23:00:31 +02:00
}