2022-02-28 20:07:34 +00:00
|
|
|
variable "config_data" {
|
|
|
|
type = string
|
|
|
|
description = "Plain text config file for blocky"
|
|
|
|
}
|
|
|
|
|
|
|
|
job "blocky" {
|
|
|
|
datacenters = ["dc1"]
|
2024-05-30 18:41:40 +00:00
|
|
|
type = "service"
|
2022-06-23 16:50:19 +00:00
|
|
|
priority = 100
|
|
|
|
|
2024-05-30 18:41:40 +00:00
|
|
|
constraint {
|
|
|
|
distinct_hosts = true
|
|
|
|
}
|
|
|
|
|
2022-06-23 16:50:19 +00:00
|
|
|
update {
|
|
|
|
max_parallel = 1
|
2022-11-12 00:21:17 +00:00
|
|
|
# TODO: maybe switch to service job from system so we can use canary and autorollback
|
2024-05-30 18:41:40 +00:00
|
|
|
auto_revert = true
|
|
|
|
min_healthy_time = "60s"
|
|
|
|
healthy_deadline = "5m"
|
2022-06-23 16:50:19 +00:00
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
|
|
|
|
group "blocky" {
|
2024-05-30 18:41:40 +00:00
|
|
|
# TODO: This must be updated to match the nubmer of servers (possibly grabbed from TF)
|
|
|
|
# I am moving away from `system` jobs because of https://github.com/hashicorp/nomad/issues/12023
|
|
|
|
count = 3
|
2022-02-28 20:07:34 +00:00
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "dns" {
|
|
|
|
static = "53"
|
|
|
|
}
|
|
|
|
|
2022-03-14 22:56:06 +00:00
|
|
|
port "api" {
|
2023-08-24 19:36:47 +00:00
|
|
|
%{~ if use_wesher ~}
|
2023-03-24 23:32:37 +00:00
|
|
|
host_network = "wesher"
|
2023-08-24 19:36:47 +00:00
|
|
|
%{~ endif ~}
|
2022-02-28 20:07:34 +00:00
|
|
|
to = "4000"
|
|
|
|
}
|
2022-11-15 18:26:26 +00:00
|
|
|
|
|
|
|
dns {
|
|
|
|
# Set expclicit DNS servers because tasks, by default, use this task
|
2024-02-13 20:01:08 +00:00
|
|
|
servers = [
|
|
|
|
"192.168.2.1",
|
|
|
|
]
|
2022-11-15 18:26:26 +00:00
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-03-13 17:13:19 +00:00
|
|
|
name = "blocky-dns"
|
2022-11-21 00:24:00 +00:00
|
|
|
provider = "nomad"
|
2022-02-28 20:07:34 +00:00
|
|
|
port = "dns"
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-03-13 17:13:19 +00:00
|
|
|
name = "blocky-api"
|
2022-11-21 00:24:00 +00:00
|
|
|
provider = "nomad"
|
2022-03-14 22:56:06 +00:00
|
|
|
port = "api"
|
|
|
|
|
2022-06-24 03:10:36 +00:00
|
|
|
tags = [
|
2023-03-24 18:24:36 +00:00
|
|
|
"prometheus.scrape",
|
2022-06-24 03:10:36 +00:00
|
|
|
"traefik.enable=true",
|
2022-11-10 21:34:55 +00:00
|
|
|
"traefik.http.routers.blocky-api.entryPoints=websecure",
|
2022-06-24 03:10:36 +00:00
|
|
|
]
|
|
|
|
|
2022-03-14 22:56:06 +00:00
|
|
|
check {
|
|
|
|
name = "api-health"
|
|
|
|
port = "api"
|
|
|
|
type = "http"
|
|
|
|
path = "/"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "3s"
|
2024-05-30 18:41:40 +00:00
|
|
|
|
|
|
|
check_restart {
|
|
|
|
limit = 3
|
|
|
|
grace = "5m"
|
|
|
|
}
|
2022-03-14 22:56:06 +00:00
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 04:45:01 +00:00
|
|
|
task "blocky" {
|
2022-02-28 20:07:34 +00:00
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
2023-09-19 04:58:00 +00:00
|
|
|
image = "ghcr.io/0xerr0r/blocky:v0.22"
|
2023-08-24 19:36:47 +00:00
|
|
|
args = ["-c", "$${NOMAD_TASK_DIR}/config.yml"]
|
2022-03-14 22:56:06 +00:00
|
|
|
ports = ["dns", "api"]
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
2024-03-26 16:48:31 +00:00
|
|
|
memory = 75
|
|
|
|
memory_max = 150
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = var.config_data
|
2023-08-24 19:36:47 +00:00
|
|
|
destination = "$${NOMAD_TASK_DIR}/config.yml"
|
2022-09-05 19:57:13 +00:00
|
|
|
splay = "1m"
|
2022-11-28 06:46:25 +00:00
|
|
|
|
|
|
|
wait {
|
|
|
|
min = "10s"
|
|
|
|
max = "20s"
|
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
2023-03-27 22:20:50 +00:00
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
{{ range nomadServices }}
|
|
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") .Name -}}
|
|
|
|
{{ .Address }} {{ .Name }}.nomad
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
EOF
|
2023-08-24 19:36:47 +00:00
|
|
|
destination = "$${NOMAD_TASK_DIR}/nomad.hosts"
|
2023-03-27 22:20:50 +00:00
|
|
|
change_mode = "noop"
|
|
|
|
|
|
|
|
wait {
|
|
|
|
min = "10s"
|
|
|
|
max = "20s"
|
|
|
|
}
|
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
2022-11-12 00:21:17 +00:00
|
|
|
|
2023-05-09 20:20:36 +00:00
|
|
|
task "stunnel" {
|
2023-03-24 23:32:37 +00:00
|
|
|
driver = "docker"
|
|
|
|
|
2023-03-27 22:21:19 +00:00
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = true
|
|
|
|
}
|
|
|
|
|
2023-03-24 23:32:37 +00:00
|
|
|
config {
|
2024-01-03 21:50:49 +00:00
|
|
|
image = "iamthefij/stunnel:latest"
|
|
|
|
args = ["$${NOMAD_TASK_DIR}/stunnel.conf"]
|
2023-03-24 23:32:37 +00:00
|
|
|
ports = ["tls"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 20
|
|
|
|
memory = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
syslog = no
|
|
|
|
foreground = yes
|
|
|
|
delay = yes
|
|
|
|
|
2024-02-13 20:01:45 +00:00
|
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "mysql-tls" -}}
|
2023-05-09 20:20:36 +00:00
|
|
|
[mysql_client]
|
|
|
|
client = yes
|
|
|
|
accept = 127.0.0.1:3306
|
|
|
|
connect = {{ .Address }}:{{ .Port }}
|
|
|
|
PSKsecrets = {{ env "NOMAD_SECRETS_DIR" }}/mysql_stunnel_psk.txt
|
2024-02-13 20:01:45 +00:00
|
|
|
{{- end }}
|
2023-05-09 20:20:36 +00:00
|
|
|
|
2024-02-13 20:01:45 +00:00
|
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "redis-blocky" -}}
|
2023-03-24 23:32:37 +00:00
|
|
|
[redis_client]
|
|
|
|
client = yes
|
|
|
|
accept = 127.0.0.1:6379
|
|
|
|
connect = {{ .Address }}:{{ .Port }}
|
|
|
|
PSKsecrets = {{ env "NOMAD_SECRETS_DIR" }}/stunnel_psk.txt
|
2024-02-13 20:01:45 +00:00
|
|
|
{{- end }}
|
2023-03-24 23:32:37 +00:00
|
|
|
EOF
|
2023-08-24 19:36:47 +00:00
|
|
|
destination = "$${NOMAD_TASK_DIR}/stunnel.conf"
|
2023-03-24 23:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-08-29 19:48:48 +00:00
|
|
|
{{- with nomadVar "secrets/mysql/allowed_psks/blocky" }}{{ .psk }}{{ end -}}
|
2023-05-09 20:20:36 +00:00
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/mysql_stunnel_psk.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
{{- with nomadVar "nomad/jobs/blocky/blocky/stunnel" -}}{{ .redis_stunnel_psk }}{{ end -}}
|
2023-03-24 23:32:37 +00:00
|
|
|
EOF
|
2023-08-24 19:36:47 +00:00
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/stunnel_psk.txt"
|
2023-03-24 23:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-29 19:59:14 +00:00
|
|
|
task "mysql-bootstrap" {
|
2022-11-12 00:21:17 +00:00
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = false
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "mariadb:10"
|
|
|
|
args = [
|
2023-05-09 20:20:36 +00:00
|
|
|
"/usr/bin/timeout",
|
|
|
|
"2m",
|
2022-11-12 00:21:17 +00:00
|
|
|
"/bin/bash",
|
|
|
|
"-c",
|
2023-05-09 20:20:36 +00:00
|
|
|
"until /usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql; do sleep 10; done",
|
2022-11-12 00:21:17 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
[client]
|
2023-07-27 06:23:23 +00:00
|
|
|
host=127.0.0.1
|
|
|
|
port=3306
|
2022-11-12 00:21:17 +00:00
|
|
|
user=root
|
2023-08-29 19:48:48 +00:00
|
|
|
{{ with nomadVar "secrets/mysql" }}
|
2022-11-21 00:24:00 +00:00
|
|
|
password={{ .mysql_root_password }}
|
|
|
|
{{ end }}
|
2022-11-12 00:21:17 +00:00
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/my.cnf"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-03-24 16:56:56 +00:00
|
|
|
{{ with nomadVar "nomad/jobs/blocky" }}{{ if .db_name -}}
|
2022-11-21 00:24:00 +00:00
|
|
|
{{ $db_name := .db_name }}
|
2022-11-12 00:21:17 +00:00
|
|
|
CREATE DATABASE IF NOT EXISTS `{{ $db_name }}`;
|
2022-11-21 00:24:00 +00:00
|
|
|
CREATE USER IF NOT EXISTS '{{ .db_user }}'@'%' IDENTIFIED BY '{{ .db_pass }}';
|
|
|
|
GRANT ALL ON `{{ $db_name }}`.* to '{{ .db_user }}'@'%';
|
2023-03-24 16:56:56 +00:00
|
|
|
|
|
|
|
{{ with nomadService "grafana" }}{{ with nomadVar "nomad/jobs" -}}
|
|
|
|
-- Grant grafana read_only user access to db
|
2022-11-21 00:24:00 +00:00
|
|
|
GRANT SELECT ON `{{ $db_name }}`.* to '{{ .db_user_ro }}'@'%';
|
2023-03-24 16:56:56 +00:00
|
|
|
{{ end }}{{ end -}}
|
|
|
|
|
2022-11-12 00:21:17 +00:00
|
|
|
{{ else -}}
|
|
|
|
SELECT 'NOOP';
|
2023-02-27 19:52:25 +00:00
|
|
|
{{ end -}}{{ end -}}
|
2022-11-12 00:21:17 +00:00
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/bootstrap.sql"
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
}
|