From 084c85e436de18936afae51a7f05aa2669df23c3 Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Thu, 15 Jun 2023 23:06:47 +0200 Subject: [PATCH] Add terranix config for ingress-toothpick container Signed-off-by: Magic_RB --- .../containers/ingress-toothpick/default.nix | 29 ++ terranix/containers/ingress-toothpick/job.hcl | 259 +++++++++++++ .../ingress-toothpick/upstreams.conf | 340 ++++++++++++++++++ 3 files changed, 628 insertions(+) create mode 100644 terranix/containers/ingress-toothpick/default.nix create mode 100644 terranix/containers/ingress-toothpick/job.hcl create mode 100644 terranix/containers/ingress-toothpick/upstreams.conf diff --git a/terranix/containers/ingress-toothpick/default.nix b/terranix/containers/ingress-toothpick/default.nix new file mode 100644 index 0000000..d947245 --- /dev/null +++ b/terranix/containers/ingress-toothpick/default.nix @@ -0,0 +1,29 @@ +{ elib, secret, ... }: +let + inherit (elib) + nfsVolume + nomadJob; + + flake_host = ""; + flake_rev = ""; + flake_ref = ""; + flake_sha = ""; +in +{ + resource."nomad_volume"."ingress-letsencrypt" = nfsVolume { + volume_name = "ingress-letsencrypt"; + access_mode = "single-node-writer"; + server = secret.network.ips.blowhole.ip; + share = "/var/nfs/ingress-letsencrypt"; + mount_flags = [ "nolock" "hard" ]; + }; + + 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-toothpick/job.hcl b/terranix/containers/ingress-toothpick/job.hcl new file mode 100644 index 0000000..7481a84 --- /dev/null +++ b/terranix/containers/ingress-toothpick/job.hcl @@ -0,0 +1,259 @@ +variable "flake_ref" { + type = string +} + +variable "flake_sha" { + type = string +} + +variable "upstreams" { + type = string +} + +job "ingress" { + datacenters = [ "do-1" ] + region = "do-1" + type = "service" + + group "ingress" { + count = 1 + + constraint { + attribute = "${attr.unique.hostname}" + value = "toothpick" + } + + volume "ingress-letsencrypt" { + type = "csi" + source = "ingress-letsencrypt" + read_only = false + + attachment_mode = "file-system" + access_mode = "single-node-writer" + } + + network { + mode = "bridge" + port "http" { + static = 80 + to = 80 + host_network = "public" + } + + port "http-matrix" { + static = 8448 + to = 8448 + host_network = "public" + } + + port "https" { + static = 443 + to = 443 + host_network = "public" + } + + port "minecraft" { + static = 25565 + to = 25565 + host_network = "public" + } + } + + service { + name = "ingress-toothpick" + port = "http" + + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "gitea" + local_bind_port = 3000 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "hydra" + local_bind_port = 8666 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "nextcloud" + local_bind_port = 8777 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "website" + local_bind_port = 8080 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "minecraft" + local_bind_port = 2666 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "reicio" + local_bind_port = 8000 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "matrix-synapse" + local_bind_port = 6167 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "matrix-synapse-client" + local_bind_port = 6168 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "matrix-synapse-federation-receiver" + local_bind_port = 6169 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + + upstreams { + destination_name = "matrix-synapse-sync" + local_bind_port = 6170 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } + } + } + } + } + + task "nginx" { + driver = "docker" + + volume_mount { + volume = "ingress-letsencrypt" + destination = "/etc/letsencrypt" + read_only = false + } + + config { + nix_flake_ref = "${var.flake_ref}#nixngSystems.ingressToothpick.config.system.build.toplevel" + nix_flake_sha = var.flake_sha + entrypoint = [ "init" ] + } + + resources { + cpu = 200 + memory = 128 + } + + template { + data = <