From 6110e78edf745c07f28cb33f86678c22ff58ae37 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Mon, 28 Feb 2022 12:07:34 -0800 Subject: [PATCH] Add blocky dns --- nomad/blocky/blocky.nomad | 74 +++++++++++++++++++++++++++++++++++++++ nomad/blocky/blocky.tf | 21 +++++++++++ nomad/blocky/config.yml | 21 +++++++++++ nomad/services.tf | 6 ++++ 4 files changed, 122 insertions(+) create mode 100644 nomad/blocky/blocky.nomad create mode 100644 nomad/blocky/blocky.tf create mode 100644 nomad/blocky/config.yml diff --git a/nomad/blocky/blocky.nomad b/nomad/blocky/blocky.nomad new file mode 100644 index 0000000..f1e10c3 --- /dev/null +++ b/nomad/blocky/blocky.nomad @@ -0,0 +1,74 @@ +variable "config_data" { + type = string + description = "Plain text config file for blocky" +} + +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + +job "blocky" { + datacenters = ["dc1"] + type = "service" + + group "blocky" { + count = 1 + + network { + mode = "bridge" + + port "dns" { + static = "53" + } + + port "web" { + to = "4000" + } + } + + service { + name = "dns" + port = "dns" + } + + service { + name = "web" + port = "web" + + tags = [ + "traefik.enable=true", + "traefik.consulcatalog.connect=false", + "traefik.http.routers.blocky.entrypoints=web,websecure", + "traefik.http.routers.blocky.rule=Host(`blocky.${var.base_hostname}`)", + "traefik.http.routers.blocky.tls=true", + ] + } + + task "main" { + driver = "docker" + + config { + image = "ghcr.io/0xerr0r/blocky" + ports = ["dns", "web"] + + mount { + type = "bind" + target = "/app/config.yml" + source = "app/config.yml" + } + } + + resources { + cpu = 50 + memory = 100 + } + + template { + data = var.config_data + destination = "app/config.yml" + } + } + } +} diff --git a/nomad/blocky/blocky.tf b/nomad/blocky/blocky.tf new file mode 100644 index 0000000..133aba1 --- /dev/null +++ b/nomad/blocky/blocky.tf @@ -0,0 +1,21 @@ +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + +locals { + config_data = file("${path.module}/config.yml") +} + +resource "nomad_job" "blocky" { + hcl2 { + enabled = true + vars = { + "config_data" = "${local.config_data}", + "base_hostname" = "${var.base_hostname}", + } + } + + jobspec = file("${path.module}/blocky.nomad") +} diff --git a/nomad/blocky/config.yml b/nomad/blocky/config.yml new file mode 100644 index 0000000..6f6c4a5 --- /dev/null +++ b/nomad/blocky/config.yml @@ -0,0 +1,21 @@ +upstream: + default: + - 1.1.1.1 + - 1.0.0.1 +blocking: + blackLists: + ads: + - https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + clientGroupsBlock: + default: + - ads + +customDNS: + customTTL: 1h + mapping: + # TODO: Use a variable for this + dev.homelab: 192.168.2.41 + +port: 53 +httpPort: 4000 + diff --git a/nomad/services.tf b/nomad/services.tf index 5270cb0..cb627ea 100644 --- a/nomad/services.tf +++ b/nomad/services.tf @@ -38,6 +38,12 @@ module "mysql-server" { base_hostname = var.base_hostname } +module "blocky" { + source = "./blocky" + + base_hostname = var.base_hostname +} + module "traefik" { source = "./traefik"