refactor(reverse-proxy): use route registry

This commit is contained in:
2026-08-23 23:44:22 -04:00
parent c267a2ec5c
commit 1dd9f33d34
8 changed files with 164 additions and 205 deletions

View File

@@ -202,7 +202,7 @@
{
modules.reverse-proxy = {
enable = true;
routes."budget.alexion.dev" = {
routes.test."budget.alexion.dev" = {
path = "/";
backend = "http://10.23.20.42:5006";
};
@@ -224,7 +224,7 @@
reverse-proxy-actualbudget-guest-route =
let
testConfig = self.nixosConfigurations.pikachu.config;
route = testConfig.modules.reverse-proxy.routes.actualbudget;
route = testConfig.registry.route.pikachu.actualbudget;
vhost = testConfig.containers.reverse-proxy.config.services.nginx.virtualHosts."budget.alexion.dev";
in
pkgs.runCommand "reverse-proxy-actualbudget-guest-route-check" { } ''
@@ -233,7 +233,6 @@
!(
route.host == "budget.alexion.dev"
&& route.backend == null
&& route.endpoint == "pikachu-actualbudget"
&& route.port == 5006
&& route.tls
&& route.aliases == [ ]
@@ -361,25 +360,25 @@
system = "x86_64-linux";
specialArgs.my = self.lib;
modules = [
./modules/reverse-proxy.nix
self.lib.registry.module
{
modules.reverse-proxy.routes.app = {
registry.route.routeHost.app = {
host = "worker.alexion.dev";
backend = "http://10.23.20.126:3923";
};
system.stateVersion = "26.11";
}
];
};
endpoints = self.lib.networkEndpoints.collectFleetEndpoints {
pikachu = self.nixosConfigurations.pikachu;
registry = self.lib.registry.collect {
hosts = {
inherit routeHost;
pikachu = self.nixosConfigurations.pikachu;
};
};
fleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes {
inherit routeHost;
pikachu = self.nixosConfigurations.pikachu;
} endpoints;
testConfig =
(self.nixosConfigurations.pikachu.extendModules {
specialArgs.reverseProxyFleetRoutes = fleetRoutes;
specialArgs.registry = registry;
}).config;
vhosts = testConfig.containers.reverse-proxy.config.services.nginx.virtualHosts;
in
@@ -387,8 +386,9 @@
${
lib.optionalString (
!(
fleetRoutes ? routeHost-app
&& fleetRoutes ? pikachu-actualbudget
registry.route ? routeHost
&& registry.route.routeHost ? app
&& registry.route.pikachu ? actualbudget
&& vhosts."worker.alexion.dev".locations."/".proxyPass == "http://10.23.20.126:3923"
&& vhosts."budget.alexion.dev".locations."/".proxyPass == "http://10.23.20.42:5006"
&& vhosts."files.alexion.dev".locations."/".proxyPass == "http://10.23.20.126:3923"
@@ -398,9 +398,9 @@
touch $out
'';
reverse-proxy-endpoint-backends =
reverse-proxy-address-backends =
let
endpointHost =
workerHost =
lib.nixosSystem {
system = "x86_64-linux";
specialArgs.my = self.lib;
@@ -408,22 +408,11 @@
self.lib.registry.module
{
registry.address.worker.self = "10.23.50.146";
system.stateVersion = "26.11";
}
];
};
routeHost =
lib.nixosSystem {
system = "x86_64-linux";
specialArgs.my = self.lib;
modules = [
./modules/reverse-proxy.nix
{
modules.reverse-proxy.routes.app = {
registry.route.worker.self = {
host = "worker.alexion.dev";
endpoint = "worker";
port = 8080;
};
system.stateVersion = "26.11";
}
];
};
@@ -454,36 +443,40 @@
}
];
};
endpoints = self.lib.networkEndpoints.collectFleetEndpoints {
worker = endpointHost;
pikachu = guestRouteHost;
registry = self.lib.registry.collect {
hosts = {
worker = workerHost;
pikachu = guestRouteHost;
};
};
fleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes {
inherit routeHost;
pikachu = guestRouteHost;
} endpoints;
testConfig =
(lib.nixosSystem {
system = "x86_64-linux";
specialArgs.my = self.lib;
specialArgs = {
my = self.lib;
inherit registry;
};
modules = [
./modules/reverse-proxy.nix
{
modules.reverse-proxy = {
enable = true;
routes = fleetRoutes;
routes = registry.route;
};
}
];
}).config;
vhosts = testConfig.services.nginx.virtualHosts;
workerFacts = self.lib.registry.lookup registry "worker" "self";
in
pkgs.runCommand "reverse-proxy-endpoint-backends-check" { } ''
pkgs.runCommand "reverse-proxy-address-backends-check" { } ''
${
lib.optionalString (
!(
vhosts."worker.alexion.dev".locations."/".proxyPass == "http://10.23.50.146:8080"
&& fleetRoutes."pikachu-files".endpoint == "pikachu-files"
workerFacts.address == "10.23.50.146"
&& workerFacts.route.host == "worker.alexion.dev"
&& vhosts."worker.alexion.dev".locations."/".proxyPass == "http://10.23.50.146:8080"
&& registry.route.pikachu.files.port == 3923
&& vhosts."files.alexion.dev".locations."/".proxyPass == "http://10.23.20.126:3923"
)
) "exit 1"
@@ -502,7 +495,7 @@
{
modules.reverse-proxy = {
enable = true;
routes.raichu-files = {
routes.raichu.files = {
host = "files.alexion.dev";
path = "/raichu";
backend = "http://10.23.20.10:3923";