diff --git a/containers/reicio.nix b/containers/reicio.nix new file mode 100644 index 0000000..49d563e --- /dev/null +++ b/containers/reicio.nix @@ -0,0 +1,77 @@ +/* + * NixNG + * Copyright (c) 2021 GPL Magic_RB + * + * This file is free software: you may copy, redistribute and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +{ nglib, nixpkgs }: +nglib.makeSystem { + system = "x86_64-linux"; + name = "nixng-reicio"; + inherit nixpkgs; + config = ({ pkgs, ... }: + { + dumb-init = { + enable = true; + type.services = { }; + }; + + users.users."reicio" = { + uid = 1002; + home = "/var/empty"; + group = "reicio"; + description = "vmail user."; + }; + + users.groups."reicio" = { + gid = 1002; + }; + + init.services.reicio = + let + reicio = with pkgs; + rustPlatform.buildRustPackage { + pname = "reicio-web"; + version = "0.1.0"; + src = fetchgit { + url = "https://gitea.redalder.org/ThyW/reicio-web"; + sha256 = "sha256-zAflDChM1szzESocMuzag+Umheku+AOeCb+4TYznJII="; + }; + cargoSha256 = "sha256-LmeJxYS11OEWEnw7YIOyR1vCqgXOCpnM28Yo+kPSxPg="; + + postInstall = + '' + mkdir -p $out/share/reicio + cp -r quotes.json portraits templates $out/share/reicio + cat < $out/share/reicio/Rocket.toml + [global] + address = "0.0.0.0" + EOF + ''; + }; + in + { + shutdownOnExit = true; + enabled = true; + script = pkgs.writeShellScript "reicio-run" + '' + export PATH=${with pkgs; lib.makeBinPath [ runit busybox reicio ]} + + cd ${pkgs.lib.trace reicio.outPath reicio}/share/reicio + chpst -u reicio:reicio reicio-web + ''; + }; + }); +} diff --git a/flake.nix b/flake.nix index 9435431..13087f8 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,7 @@ syncthing = import ./containers/syncthing.nix base; zigbee2mqtt = import ./containers/zigbee2mqtt.nix base; home-assistant = import ./containers/home-assistant.nix base; + reicio = import ./containers/reicio.nix base; }; in { diff --git a/infrastructure/ingress/nomad.hcl b/infrastructure/ingress/nomad.hcl index 82f8cb4..01a1099 100644 --- a/infrastructure/ingress/nomad.hcl +++ b/infrastructure/ingress/nomad.hcl @@ -96,6 +96,16 @@ job "ingress" { mode = "local" } } + + upstreams { + destination_name = "reicio" + local_bind_port = 8000 + datacenter = "homelab-1" + + mesh_gateway { + mode = "local" + } + } } } } @@ -203,6 +213,10 @@ upstream website { server {{ env "NOMAD_UPSTREAM_ADDR_website" }}; } +upstream reicio { + server {{ env "NOMAD_UPSTREAM_ADDR_reicio" }}; +} + server { listen 443 ssl; @@ -256,6 +270,11 @@ server { proxy_pass http://nextcloud/; } + location /reicio/ { + include /local/headers.conf; + proxy_pass http://reicio/; + } + location / { include /local/headers.conf; proxy_pass http://website; diff --git a/infrastructure/reicio/reicio.hcl b/infrastructure/reicio/reicio.hcl new file mode 100644 index 0000000..a3b82dc --- /dev/null +++ b/infrastructure/reicio/reicio.hcl @@ -0,0 +1,44 @@ +job "reicio" { + datacenters = [ "homelab-1" ] + type = "service" + + group "reicio" { + count = 1 + + network { + mode = "bridge" + } + + service { + name = "reicio" + port = "8000" + + check { + type = "http" + address_mode = "alloc" + path = "/" + port = "8000" + interval = "2s" + timeout = "2s" + } + + connect { + sidecar_service {} + } + } + + task "reicio" { + driver = "docker" + + config { + image = "nixng-reicio:local" + memory_hard_limit = 32 + } + + resources { + cpu = 64 + memory = 16 + } + } + } +}