159 lines
3.1 KiB
HCL
159 lines
3.1 KiB
HCL
variable "config_data" {
|
|
type = string
|
|
description = "Plain text config file for blocky"
|
|
}
|
|
|
|
job "blocky" {
|
|
datacenters = ["dc1"]
|
|
type = "system"
|
|
priority = 100
|
|
|
|
update {
|
|
max_parallel = 1
|
|
# TODO: maybe switch to service job from system so we can use canary and autorollback
|
|
# auto_revert = true
|
|
}
|
|
|
|
group "blocky" {
|
|
|
|
network {
|
|
mode = "bridge"
|
|
|
|
port "dns" {
|
|
static = "53"
|
|
}
|
|
|
|
port "api" {
|
|
host_network = "wgoverlay"
|
|
to = "4000"
|
|
}
|
|
|
|
dns {
|
|
# Set expclicit DNS servers because tasks, by default, use this task
|
|
servers = ["1.1.1.1", "1.0.0.1"]
|
|
}
|
|
}
|
|
|
|
service {
|
|
name = "blocky-dns"
|
|
provider = "nomad"
|
|
port = "dns"
|
|
}
|
|
|
|
service {
|
|
name = "blocky-api"
|
|
provider = "nomad"
|
|
port = "api"
|
|
|
|
meta {
|
|
metrics_addr = "${NOMAD_ADDR_api}"
|
|
}
|
|
|
|
tags = [
|
|
"traefik.enable=true",
|
|
"traefik.http.routers.blocky-api.entryPoints=websecure",
|
|
]
|
|
|
|
check {
|
|
name = "api-health"
|
|
port = "api"
|
|
type = "http"
|
|
path = "/"
|
|
interval = "10s"
|
|
timeout = "3s"
|
|
}
|
|
}
|
|
|
|
task "blocky" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "ghcr.io/0xerr0r/blocky"
|
|
ports = ["dns", "api"]
|
|
|
|
mount {
|
|
type = "bind"
|
|
target = "/app/config.yml"
|
|
source = "app/config.yml"
|
|
}
|
|
}
|
|
|
|
resources {
|
|
cpu = 50
|
|
memory = 50
|
|
memory_max = 100
|
|
}
|
|
|
|
template {
|
|
data = var.config_data
|
|
destination = "app/config.yml"
|
|
splay = "1m"
|
|
|
|
wait {
|
|
min = "10s"
|
|
max = "20s"
|
|
}
|
|
}
|
|
}
|
|
|
|
task "blocky-bootstrap" {
|
|
driver = "docker"
|
|
|
|
lifecycle {
|
|
hook = "prestart"
|
|
sidecar = false
|
|
}
|
|
|
|
config {
|
|
image = "mariadb:10"
|
|
args = [
|
|
"/bin/bash",
|
|
"-c",
|
|
"/usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql || echo 'SQL Failed'",
|
|
]
|
|
}
|
|
|
|
template {
|
|
data = <<EOF
|
|
[client]
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "mysql-server" -}}
|
|
host={{ .Address }}
|
|
port={{ .Port }}
|
|
{{ end -}}
|
|
user=root
|
|
{{ with nomadVar "nomad/jobs" }}
|
|
password={{ .mysql_root_password }}
|
|
{{ end }}
|
|
EOF
|
|
destination = "$${NOMAD_SECRETS_DIR}/my.cnf"
|
|
}
|
|
|
|
template {
|
|
data = <<EOF
|
|
{{ with nomadVar "nomad/jobs/blocky" -}}
|
|
{{ if .db_name -}}
|
|
{{ $db_name := .db_name }}
|
|
CREATE DATABASE IF NOT EXISTS `{{ $db_name }}`;
|
|
CREATE USER IF NOT EXISTS '{{ .db_user }}'@'%' IDENTIFIED BY '{{ .db_pass }}';
|
|
GRANT ALL ON `{{ $db_name }}`.* to '{{ .db_user }}'@'%';
|
|
{{ with nomadVar "nomad/jobs" -}}
|
|
-- Add grafana read_only user
|
|
CREATE USER IF NOT EXISTS '{{ .db_user_ro }}'@'%' IDENTIFIED BY '{{ .db_pass_ro }}';
|
|
GRANT SELECT ON `{{ $db_name }}`.* to '{{ .db_user_ro }}'@'%';
|
|
{{ end -}}
|
|
{{ else -}}
|
|
SELECT 'NOOP';
|
|
{{ end -}}
|
|
{{ end -}}{{ end -}}
|
|
EOF
|
|
destination = "$${NOMAD_SECRETS_DIR}/bootstrap.sql"
|
|
}
|
|
|
|
resources {
|
|
cpu = 50
|
|
memory = 50
|
|
}
|
|
}
|
|
}
|
|
}
|