2022-05-18 21:23:28 +00:00
|
|
|
variable "nextcloud_backup" {
|
|
|
|
type = string
|
|
|
|
description = "HCL config for Restic Scheduler jobs"
|
|
|
|
}
|
|
|
|
|
|
|
|
job "backup" {
|
|
|
|
datacenters = ["dc1"]
|
2022-06-23 16:49:57 +00:00
|
|
|
type = "system"
|
2022-05-18 21:23:28 +00:00
|
|
|
|
2022-06-23 16:49:57 +00:00
|
|
|
constraint {
|
|
|
|
attribute = "${node.unique.name}"
|
|
|
|
# Only node with a backup job so far
|
|
|
|
value = "n2"
|
|
|
|
}
|
|
|
|
|
|
|
|
group "backup" {
|
2022-05-18 21:23:28 +00:00
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "metrics" {
|
|
|
|
to = 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 16:49:57 +00:00
|
|
|
volume "all-volumes" {
|
2022-05-18 21:23:28 +00:00
|
|
|
type = "host"
|
|
|
|
read_only = true
|
2022-06-23 16:49:57 +00:00
|
|
|
source = "all-volumes"
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
port = "metrics"
|
|
|
|
|
|
|
|
# Add connect to mysql
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
local_service_port = 8080
|
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 6060
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
protocol = "tcp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meta {
|
|
|
|
metrics_addr = "${NOMAD_ADDR_metrics}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "backup" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
volume_mount {
|
2022-06-23 16:49:57 +00:00
|
|
|
volume = "all-volumes"
|
|
|
|
destination = "/data"
|
2022-05-18 21:23:28 +00:00
|
|
|
read_only = true
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "iamthefij/resticscheduler"
|
|
|
|
ports = ["metrics"]
|
|
|
|
args = [
|
2022-06-23 16:49:57 +00:00
|
|
|
"/jobs/node-jobs.hcl",
|
2022-05-18 21:23:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
mount {
|
|
|
|
type = "bind"
|
|
|
|
target = "/jobs"
|
|
|
|
source = "jobs"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
|
|
|
"MYSQL_HOST" = "${NOMAD_UPSTREAM_IP_mysql_server}"
|
|
|
|
"MYSQL_PORT" = "${NOMAD_UPSTREAM_PORT_mysql_server}"
|
|
|
|
# TODO: Add user with access to all databases or variables for each user
|
|
|
|
"MYSQL_DATABASE" = "nextcloud"
|
|
|
|
"MYSQL_USER" = "nextcloud"
|
|
|
|
"MYSQL_PASSWORD" = "nextcloud"
|
|
|
|
|
|
|
|
# TODO: Something from vault
|
|
|
|
"BACKUP_PASSPHRASE" = "secretpass"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
2022-06-23 16:49:57 +00:00
|
|
|
data = <<EOF
|
|
|
|
# Current node is {{ env "node.unique.name" }}
|
|
|
|
{{ range service "nextcloud" }}
|
|
|
|
# Nextcloud .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") }}
|
|
|
|
${var.nextcloud_backup}
|
|
|
|
{{ end }}{{ end }}
|
|
|
|
EOF
|
|
|
|
destination = "jobs/node-jobs.hcl"
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|