From 1e67b634a610bf5225c1e86173b40f9c8bb5ca36 Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Thu, 15 Jun 2023 23:04:46 +0200 Subject: [PATCH] Add terranix config for website container Signed-off-by: Magic_RB --- terranix/containers/website/default.nix | 15 +++++ terranix/containers/website/job.hcl | 74 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 terranix/containers/website/default.nix create mode 100644 terranix/containers/website/job.hcl diff --git a/terranix/containers/website/default.nix b/terranix/containers/website/default.nix new file mode 100644 index 0000000..2909566 --- /dev/null +++ b/terranix/containers/website/default.nix @@ -0,0 +1,15 @@ +{ pkgs, elib, vars, ... }: +let + inherit (elib) + nfsVolume + nomadJob; +in +{ + resource."nomad_job"."website" = nomadJob { + jobspec = ./job.hcl; + vars = { + flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; + flake_sha = vars.flake_sha; + }; + }; +} diff --git a/terranix/containers/website/job.hcl b/terranix/containers/website/job.hcl new file mode 100644 index 0000000..728e235 --- /dev/null +++ b/terranix/containers/website/job.hcl @@ -0,0 +1,74 @@ +variable "flake_ref" { + type = string +} + +variable "flake_sha" { + type = string +} + +job "website" { + datacenters = [ "homelab-1" ] + type = "service" + + constraint { + attribute = "${attr.unique.hostname}" + value = "blowhole" + } + + group "website" { + count = 2 + + update { + max_parallel = 1 + } + + network { + mode = "bridge" + } + + service { + name = "website" + port = "80" + + check { + type = "http" + address_mode = "alloc" + path = "/" + port = "80" + interval = "10s" + timeout = "10s" + } + + connect { + sidecar_service {} + + sidecar_task { + resources { + cpu = 75 + memory = 48 + } + + config { + memory_hard_limit = 96 + } + } + } + } + + task "apache" { + driver = "docker" + + config { + nix_flake_ref = "${var.flake_ref}#nixngSystems.website.config.system.build.toplevel" + nix_flake_sha = var.flake_sha + entrypoint = [ "init" ] + } + + resources { + cpu = 128 + memory = 32 + memory_max = 64 + } + } + } +}