diff --git a/terranix/containers/ingress-blowhole/default.nix b/terranix/containers/ingress-blowhole/default.nix new file mode 100644 index 0000000..1d8557e --- /dev/null +++ b/terranix/containers/ingress-blowhole/default.nix @@ -0,0 +1,21 @@ +{ elib, ... }: +let + inherit (elib) + nomadJob; + + flake_host = ""; + flake_rev = ""; + flake_ref = ""; + flake_sha = ""; +in +{ + resource."nomad_job"."ingress" = nomadJob { + jobspec = ./job.hcl; + + vars = { + flake_ref = "${flake_host}?rev=${flake_rev}&ref=${flake_ref}"; + flake_sha = flake_sha; + upstreams = "\${file(\"${./upstreams.conf}\")}"; + }; + }; +} diff --git a/terranix/containers/ingress-blowhole/job.hcl b/terranix/containers/ingress-blowhole/job.hcl new file mode 100644 index 0000000..0ed7010 --- /dev/null +++ b/terranix/containers/ingress-blowhole/job.hcl @@ -0,0 +1,284 @@ +variable "flake_ref" { + type = string +} + +variable "flake_sha" { + type = string +} + +variable "upstreams" { + type = string +} + +job "ingress" { + datacenters = [ "homelab-1" ] + type = "service" + + group "ingress" { + count = 1 + + constraint { + attribute = "${attr.unique.hostname}" + value = "blowhole" + } + + network { + mode = "bridge" + port "http" { + host_network = "mesh" + static = 80 + to = 80 + } + + port "https" { + host_network = "mesh" + static = 443 + to = 443 + } + + port "imap" { + host_network = "mesh" + static = 143 + to = 143 + } + } + + service { + name = "ingress-blowhole" + port = "80" + + check { + type = "http" + path = "/health" + name = "jellyfin" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "jellyfin.in.redalder.org" ] + } + } + + check { + type = "http" + path = "/" + name = "zigbee2mqtt" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "zigbee2mqtt.in.redalder.org" ] + } + } + + check { + type = "http" + path = "/" + name = "home-assistant" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "hass.in.redalder.org" ] + } + } + + # check { + # type = "http" + # path = "/" + # name = "syncthing" + # port = "http" + # interval = "5s" + # timeout = "5s" + # header { + # Host = [ "syncthing.in.redalder.org" ] + # } + # } + + check { + type = "http" + path = "/api/health" + name = "grafana" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "grafana.in.redalder.org" ] + } + } + + check { + type = "http" + path = "/health" + name = "influx" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "influx.in.redalder.org" ] + } + } + + check { + type = "http" + path = "/" + name = "mainsail" + port = "http" + interval = "5s" + timeout = "5s" + header { + Host = [ "mainsail.in.redalder.org" ] + } + } + + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "jellyfin" + local_bind_port = 8001 + } + + upstreams { + destination_name = "zigbee2mqtt" + local_bind_port = 8002 + } + + upstreams { + destination_name = "home-assistant" + local_bind_port = 8003 + } + + upstreams { + destination_name = "syncthing" + local_bind_port = 8004 + } + + upstreams { + destination_name = "dovecot-imap" + local_bind_port = 8005 + } + + upstreams { + destination_name = "grafana" + local_bind_port = 8006 + } + + upstreams { + destination_name = "influx" + local_bind_port = 8007 + } + + upstreams { + destination_name = "mainsail" + local_bind_port = 8008 + } + + upstreams { + destination_name = "matrix-synapse" + local_bind_port = 8009 + } + + upstreams { + destination_name = "matrix-mautrix-facebook" + local_bind_port = 8010 + } + } + } + + sidecar_task { + resources { + cpu = 75 + memory = 48 + } + + config { + memory_hard_limit = 96 + } + } + } + } + + task "nginx" { + driver = "docker" + + config { + nix_flake_ref = "${var.flake_ref}#nixngSystems.ingressBlowhole.config.system.build.toplevel" + nix_flake_sha = var.flake_sha + entrypoint = [ "init" ] + } + + resources { + cpu = 200 + memory = 32 + memory_max = 128 + } + + template { + data = <