2022-02-16 17:56:18 +00:00
|
|
|
job "mysql-server" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
type = "service"
|
2022-09-26 23:40:25 +00:00
|
|
|
priority = 80
|
2022-02-16 17:56:18 +00:00
|
|
|
|
|
|
|
group "mysql-server" {
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
restart {
|
|
|
|
attempts = 10
|
|
|
|
interval = "5m"
|
|
|
|
delay = "25s"
|
|
|
|
mode = "delay"
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
2022-11-21 00:24:00 +00:00
|
|
|
|
2022-02-16 17:56:18 +00:00
|
|
|
port "db" {
|
2023-06-20 16:44:21 +00:00
|
|
|
static = 3306
|
2023-03-02 19:00:45 +00:00
|
|
|
}
|
2023-05-09 20:20:36 +00:00
|
|
|
|
2023-06-20 16:44:21 +00:00
|
|
|
port "tls" {}
|
2022-02-16 17:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
volume "mysql-data" {
|
|
|
|
type = "host"
|
|
|
|
read_only = false
|
|
|
|
source = "mysql-data"
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
name = "mysql-server"
|
2022-11-21 00:24:00 +00:00
|
|
|
provider = "nomad"
|
2022-02-16 17:56:18 +00:00
|
|
|
port = "db"
|
|
|
|
}
|
|
|
|
|
2023-05-09 20:20:36 +00:00
|
|
|
service {
|
|
|
|
name = "mysql-tls"
|
|
|
|
provider = "nomad"
|
|
|
|
port = "tls"
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:56:18 +00:00
|
|
|
task "mysql-server" {
|
|
|
|
driver = "docker"
|
|
|
|
|
2022-07-25 22:51:41 +00:00
|
|
|
config {
|
2022-11-10 19:15:58 +00:00
|
|
|
image = "mariadb:10"
|
2022-07-25 22:51:41 +00:00
|
|
|
ports = ["db"]
|
2022-11-12 00:21:47 +00:00
|
|
|
args = ["--innodb-buffer-pool-size=1G"]
|
2022-07-25 22:51:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 17:56:18 +00:00
|
|
|
volume_mount {
|
|
|
|
volume = "mysql-data"
|
|
|
|
destination = "/var/lib/mysql"
|
|
|
|
read_only = false
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
2022-02-17 22:03:42 +00:00
|
|
|
# Allow connections from any host
|
2022-02-16 17:56:18 +00:00
|
|
|
"MYSQL_ROOT_HOST" = "%"
|
|
|
|
}
|
|
|
|
|
2022-07-25 22:51:41 +00:00
|
|
|
template {
|
|
|
|
data = <<EOH
|
2023-05-03 21:16:47 +00:00
|
|
|
{{ with nomadVar "nomad/jobs/mysql-server" }}
|
2022-11-21 00:24:00 +00:00
|
|
|
MYSQL_ROOT_PASSWORD={{ .mysql_root_password }}
|
2022-07-25 22:51:41 +00:00
|
|
|
{{ end }}
|
|
|
|
EOH
|
2023-05-09 22:57:09 +00:00
|
|
|
destination = "${NOMAD_SECRETS_DIR}/db.env"
|
2022-07-25 22:51:41 +00:00
|
|
|
env = true
|
2022-02-16 17:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
2022-02-17 22:03:42 +00:00
|
|
|
cpu = 300
|
2023-07-19 16:37:23 +00:00
|
|
|
memory = 1536
|
2022-02-16 17:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-09 20:20:36 +00:00
|
|
|
|
|
|
|
task "stunnel" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
2024-06-26 20:27:41 +00:00
|
|
|
image = "iamthefij/stunnel:1.0.0"
|
2024-01-03 21:50:49 +00:00
|
|
|
args = ["${NOMAD_TASK_DIR}/stunnel.conf"]
|
2023-05-09 20:20:36 +00:00
|
|
|
ports = ["tls"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 100
|
|
|
|
memory = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
syslog = no
|
|
|
|
foreground = yes
|
|
|
|
delay = yes
|
|
|
|
|
|
|
|
[mysql_server]
|
|
|
|
accept = {{ env "NOMAD_PORT_tls" }}
|
|
|
|
connect = 127.0.0.1:3306
|
|
|
|
ciphers = PSK
|
|
|
|
PSKsecrets = {{ env "NOMAD_SECRETS_DIR" }}/stunnel_psk.txt
|
|
|
|
EOF
|
|
|
|
destination = "${NOMAD_TASK_DIR}/stunnel.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-08-29 19:48:48 +00:00
|
|
|
{{ range nomadVarList "secrets/mysql/allowed_psks" -}}
|
|
|
|
{{ with nomadVar .Path }}{{ .psk }}{{ end }}
|
|
|
|
{{ end -}}
|
2023-07-07 00:24:37 +00:00
|
|
|
EOF
|
2023-05-09 20:20:36 +00:00
|
|
|
destination = "${NOMAD_SECRETS_DIR}/stunnel_psk.txt"
|
|
|
|
}
|
|
|
|
}
|
2022-02-16 17:56:18 +00:00
|
|
|
}
|
|
|
|
}
|