124 lines
2.1 KiB
HCL
124 lines
2.1 KiB
HCL
job "mysql-server" {
|
|
datacenters = ["dc1"]
|
|
type = "service"
|
|
priority = 80
|
|
|
|
update {
|
|
auto_revert = true
|
|
}
|
|
|
|
group "mysql-server" {
|
|
count = 1
|
|
|
|
restart {
|
|
attempts = 10
|
|
interval = "5m"
|
|
delay = "25s"
|
|
mode = "delay"
|
|
}
|
|
|
|
network {
|
|
mode = "bridge"
|
|
|
|
port "db" {
|
|
static = 3306
|
|
}
|
|
|
|
port "tls" {}
|
|
}
|
|
|
|
volume "mysql-data" {
|
|
type = "host"
|
|
read_only = false
|
|
source = "mysql-data"
|
|
}
|
|
|
|
service {
|
|
name = "mysql-server"
|
|
provider = "nomad"
|
|
port = "db"
|
|
}
|
|
|
|
service {
|
|
name = "mysql-tls"
|
|
provider = "nomad"
|
|
port = "tls"
|
|
}
|
|
|
|
task "mysql-server" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "mariadb:10"
|
|
ports = ["db"]
|
|
args = ["--innodb-buffer-pool-size=1G"]
|
|
}
|
|
|
|
volume_mount {
|
|
volume = "mysql-data"
|
|
destination = "/var/lib/mysql"
|
|
read_only = false
|
|
}
|
|
|
|
env = {
|
|
# Allow connections from any host
|
|
"MYSQL_ROOT_HOST" = "%"
|
|
}
|
|
|
|
template {
|
|
data = <<EOH
|
|
{{ with nomadVar "nomad/jobs/mysql-server" }}
|
|
MYSQL_ROOT_PASSWORD={{ .mysql_root_password }}
|
|
{{ end }}
|
|
EOH
|
|
destination = "${NOMAD_SECRETS_DIR}/db.env"
|
|
env = true
|
|
}
|
|
|
|
resources {
|
|
cpu = 300
|
|
memory = 1600
|
|
}
|
|
}
|
|
|
|
task "stunnel" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "iamthefij/stunnel:1.0.0"
|
|
args = ["${NOMAD_TASK_DIR}/stunnel.conf"]
|
|
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
|
|
{{ range nomadVarList "secrets/mysql/allowed_psks" -}}
|
|
{{ with nomadVar .Path }}{{ .psk }}{{ end }}
|
|
{{ end -}}
|
|
EOF
|
|
destination = "${NOMAD_SECRETS_DIR}/stunnel_psk.txt"
|
|
}
|
|
}
|
|
}
|
|
}
|