cluster/services/ways: support internal services properly

This commit is contained in:
Max Headroom 2024-08-02 23:26:46 +02:00
parent 5d26d45916
commit e81aad5619
3 changed files with 35 additions and 13 deletions

View file

@ -11,6 +11,9 @@
}; };
dns.records = lib.mapAttrs' dns.records = lib.mapAttrs'
(_: cfg: lib.nameValuePair cfg.dnsRecord.name ({ ... }: { imports = [ cfg.dnsRecord.value ]; })) (_: cfg: lib.nameValuePair cfg.dnsRecord.name ({ ... }: {
imports = [ cfg.dnsRecord.value ];
root = cfg.domainSuffix;
}))
config.ways; config.ways;
} }

View file

@ -3,6 +3,8 @@
let let
externalWays = lib.filterAttrs (_: cfg: !cfg.internal) cluster.config.ways; externalWays = lib.filterAttrs (_: cfg: !cfg.internal) cluster.config.ways;
internalWays = lib.filterAttrs (_: cfg: cfg.internal) cluster.config.ways;
consulServiceWays = lib.filterAttrs (_: cfg: cfg.useConsul) cluster.config.ways; consulServiceWays = lib.filterAttrs (_: cfg: cfg.useConsul) cluster.config.ways;
in in
@ -14,6 +16,7 @@ in
imports = [ imports = [
cfg.extras cfg.extras
{ {
listenAddresses = lib.mkIf cfg.internal [ config.reflection.interfaces.vstub.addr ];
forceSSL = true; forceSSL = true;
enableACME = !cfg.internal && !cfg.wildcard; enableACME = !cfg.internal && !cfg.wildcard;
useACMEHost = lib.mkMerge [ useACMEHost = lib.mkMerge [
@ -84,18 +87,34 @@ in
}; };
}; };
consul.services.ways-proxy = { consul.services = {
unit = "nginx"; ways-proxy = {
mode = "external"; unit = "nginx";
definition = { mode = "external";
name = "ways-proxy"; definition = {
address = config.reflection.interfaces.primary.addrPublic; name = "ways-proxy";
port = 443; address = config.reflection.interfaces.primary.addrPublic;
checks = lib.singleton { port = 443;
interval = "60s"; checks = lib.singleton {
tcp = "127.0.0.1:80"; interval = "60s";
tcp = "127.0.0.1:80";
};
tags = lib.attrNames externalWays;
};
};
ways-proxy-internal = {
unit = "nginx";
mode = "external";
definition = {
name = "ways-proxy-internal";
address = config.reflection.interfaces.vstub.addr;
port = 443;
checks = lib.singleton {
interval = "60s";
tcp = "127.0.0.1:80";
};
tags = lib.attrNames internalWays;
}; };
tags = lib.attrNames externalWays;
}; };
}; };
} }

View file

@ -29,7 +29,7 @@ with lib;
description = "DNS record value for this Way."; description = "DNS record value for this Way.";
type = types.deferredModule; type = types.deferredModule;
default = { default = {
consulService = "${name}.ways-proxy"; consulService = "${name}.${if config.internal then "ways-proxy-internal" else "ways-proxy"}";
rewrite.type = lib.mkIf config.wildcard "regex"; rewrite.type = lib.mkIf config.wildcard "regex";
}; };
}; };