2022-02-28 20:07:34 +00:00
|
|
|
variable "config_data" {
|
|
|
|
type = string
|
|
|
|
description = "Plain text config file for blocky"
|
|
|
|
}
|
|
|
|
|
|
|
|
job "blocky" {
|
|
|
|
datacenters = ["dc1"]
|
2022-05-18 18:29:00 +00:00
|
|
|
type = "system"
|
2022-06-23 16:50:19 +00:00
|
|
|
priority = 100
|
|
|
|
|
|
|
|
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
|
|
|
|
# auto_revert = true
|
2022-06-23 16:50:19 +00:00
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
|
|
|
|
group "blocky" {
|
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "dns" {
|
|
|
|
static = "53"
|
|
|
|
}
|
|
|
|
|
2022-03-14 22:56:06 +00:00
|
|
|
port "api" {
|
2022-11-08 04:50:18 +00:00
|
|
|
# TODO: This may be broken. It seems we're exposing the loopback address which can't be reached
|
|
|
|
# host_network = "loopback"
|
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
|
|
|
|
servers = ["1.1.1.1", "1.0.0.1"]
|
|
|
|
}
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-03-13 17:13:19 +00:00
|
|
|
name = "blocky-dns"
|
2022-02-28 20:07:34 +00:00
|
|
|
port = "dns"
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-03-13 17:13:19 +00:00
|
|
|
name = "blocky-api"
|
2022-03-14 22:56:06 +00:00
|
|
|
port = "api"
|
|
|
|
|
|
|
|
meta {
|
|
|
|
metrics_addr = "${NOMAD_ADDR_api}"
|
|
|
|
}
|
|
|
|
|
2022-06-24 03:10:36 +00:00
|
|
|
tags = [
|
|
|
|
"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
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
2022-11-08 04:50:18 +00:00
|
|
|
local_service_port = 4000
|
2022-03-14 22:56:06 +00:00
|
|
|
|
|
|
|
expose {
|
|
|
|
path {
|
|
|
|
path = "/metrics"
|
|
|
|
protocol = "http"
|
|
|
|
local_path_port = 4000
|
|
|
|
listener_port = "api"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "redis"
|
|
|
|
local_bind_port = 6379
|
|
|
|
}
|
2022-11-12 00:21:17 +00:00
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 4040
|
|
|
|
}
|
2022-03-14 22:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
2022-07-27 18:22:02 +00:00
|
|
|
memory = 20
|
|
|
|
memory_max = 50
|
2022-03-14 22:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
check {
|
|
|
|
name = "api-health"
|
|
|
|
port = "api"
|
|
|
|
type = "http"
|
|
|
|
path = "/"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "3s"
|
|
|
|
}
|
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 {
|
|
|
|
image = "ghcr.io/0xerr0r/blocky"
|
2022-03-14 22:56:06 +00:00
|
|
|
ports = ["dns", "api"]
|
2022-02-28 20:07:34 +00:00
|
|
|
|
|
|
|
mount {
|
|
|
|
type = "bind"
|
|
|
|
target = "/app/config.yml"
|
|
|
|
source = "app/config.yml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
2022-07-25 22:51:16 +00:00
|
|
|
memory = 50
|
|
|
|
memory_max = 100
|
2022-02-28 20:07:34 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 00:21:17 +00:00
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-02-28 20:07:34 +00:00
|
|
|
template {
|
|
|
|
data = var.config_data
|
|
|
|
destination = "app/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
|
|
|
}
|
|
|
|
}
|
2022-11-12 00:21:17 +00:00
|
|
|
|
|
|
|
task "blocky-bootstrap" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = false
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "mariadb:10"
|
|
|
|
args = [
|
|
|
|
"/bin/bash",
|
|
|
|
"-c",
|
2023-02-27 19:52:25 +00:00
|
|
|
"/usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql || echo 'SQL Failed'",
|
2022-11-12 00:21:17 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
[client]
|
|
|
|
host={{ env "NOMAD_UPSTREAM_IP_mysql_server" }}
|
|
|
|
port={{ env "NOMAD_UPSTREAM_PORT_mysql_server" }}
|
|
|
|
user=root
|
2023-02-27 19:52:25 +00:00
|
|
|
{{ with service "vault" -}}{{ with secret "kv/data/mysql" }}
|
2022-11-12 00:21:17 +00:00
|
|
|
password={{ .Data.data.root_password }}
|
2023-02-27 19:52:25 +00:00
|
|
|
{{ end -}}{{ end -}}
|
2022-11-12 00:21:17 +00:00
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/my.cnf"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-02-27 19:52:25 +00:00
|
|
|
{{ with service "vault" -}}{{ with secret "kv/data/blocky" -}}
|
2022-11-12 00:21:17 +00:00
|
|
|
{{ if .Data.data.db_name -}}
|
|
|
|
{{ $db_name := .Data.data.db_name }}
|
|
|
|
CREATE DATABASE IF NOT EXISTS `{{ $db_name }}`;
|
|
|
|
CREATE USER IF NOT EXISTS '{{ .Data.data.db_user }}'@'%' IDENTIFIED BY '{{ .Data.data.db_pass }}';
|
|
|
|
GRANT ALL ON `{{ $db_name }}`.* to '{{ .Data.data.db_user }}'@'%';
|
|
|
|
{{ with secret "kv/data/grafana" -}}
|
|
|
|
-- Add grafana read_only user
|
|
|
|
CREATE USER IF NOT EXISTS '{{ .Data.data.db_user_ro }}'@'%' IDENTIFIED BY '{{ .Data.data.db_pass_ro }}';
|
|
|
|
GRANT SELECT ON `{{ $db_name }}`.* to '{{ .Data.data.db_user_ro }}'@'%';
|
|
|
|
{{ end -}}
|
|
|
|
{{ else -}}
|
|
|
|
SELECT 'NOOP';
|
|
|
|
{{ end -}}
|
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
|
|
|
}
|
|
|
|
}
|