The Simulacrum: Stage 5 #113

Merged
max merged 5 commits from pr-simulacrum-stage-5 into master 2024-08-16 20:54:11 +03:00
3 changed files with 72 additions and 0 deletions
Showing only changes of commit f4f35c3ae3 - Show all commits

View file

@ -3,11 +3,17 @@
{ {
imports = [ imports = [
./options ./options
./simulacrum/test-data.nix
]; ];
services.ways = { services.ways = {
nodes.host = config.services.websites.nodes.host; nodes.host = config.services.websites.nodes.host;
nixos.host = ./host.nix; nixos.host = ./host.nix;
simulacrum = {
enable = true;
deps = [ "nginx" "acme-client" "dns" "certificates" "consul" ];
settings = ./simulacrum/test.nix;
};
}; };
dns.records = lib.mapAttrs' dns.records = lib.mapAttrs'

View file

@ -0,0 +1,11 @@
{ config, lib, ... }:
{
ways = lib.mkIf config.simulacrum {
ways-test-simple = config.lib.forService "ways" {
target = "http://nowhere";
};
ways-test-consul = config.lib.forService "ways" {
consulService = "ways-test-service";
};
};
}

View file

@ -0,0 +1,55 @@
{ cluster, config, lib, ... }:
let
inherit (cluster._module.specialArgs.depot.lib.meta) domain;
in
{
nodes = lib.mkMerge [
{
nowhere = { pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 8080 ];
systemd.services.ways-simple-service = let
webroot = pkgs.writeTextDir "example.txt" "hello world";
in {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkgs.darkhttpd}/bin/darkhttpd ${webroot} --port 8080";
DynamicUser = true;
};
};
};
}
(lib.genAttrs cluster.config.services.ways.nodes.host (lib.const {
services.nginx.upstreams.nowhere.servers = {
"${(builtins.head config.nodes.nowhere.networking.interfaces.eth1.ipv4.addresses).address}:8080" = {};
};
consul.services.ways-test-service = {
unit = "consul";
mode = "external";
definition = {
name = "ways-test-service";
address = (builtins.head config.nodes.nowhere.networking.interfaces.eth1.ipv4.addresses).address;
port = 8080;
};
};
}))
];
testScript = ''
import json
nodeNames = json.loads('${builtins.toJSON cluster.config.services.ways.nodes.host}')
nodes = [ n for n in machines if n.name in nodeNames ]
start_all()
nowhere.wait_for_unit("multi-user.target")
for node in nodes:
node.wait_for_unit("multi-user.target")
with subtest("single-target service"):
nowhere.succeed("curl -f https://ways-test-simple.${domain}")
with subtest("consul-managed service"):
nowhere.succeed("curl -f https://ways-test-consul.${domain}")
'';
}