diff --git a/blocky/blocky.nomad b/blocky/blocky.nomad new file mode 100644 index 0000000..f1e10c3 --- /dev/null +++ b/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/blocky/blocky.tf b/blocky/blocky.tf new file mode 100644 index 0000000..133aba1 --- /dev/null +++ b/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/blocky/config.yml b/blocky/config.yml new file mode 100644 index 0000000..6f6c4a5 --- /dev/null +++ b/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/services.tf b/services.tf index 5270cb0..cb627ea 100644 --- a/services.tf +++ b/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"