cluster/services/*: use consulAgent link

This commit is contained in:
Max Headroom 2024-07-17 02:53:36 +02:00
parent 52008b6f0a
commit 5616f4887a
6 changed files with 11 additions and 17 deletions

View file

@ -1,9 +1,7 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
consulCfg = config.services.consul.extraConfig; consul = config.links.consulAgent;
consulIpAddr = consulCfg.addresses.http or "127.0.0.1";
consulHttpAddr = "${consulIpAddr}:${toString (consulCfg.ports.http or 8500)}";
validTargets = lib.pipe config.systemd.services [ validTargets = lib.pipe config.systemd.services [
(lib.filterAttrs (name: value: value.chant.enable)) (lib.filterAttrs (name: value: value.chant.enable))
@ -75,10 +73,10 @@ in
RestartSec = 60; RestartSec = 60;
Restart = "always"; Restart = "always";
IPAddressDeny = [ "any" ]; IPAddressDeny = [ "any" ];
IPAddressAllow = [ consulIpAddr ]; IPAddressAllow = [ consul.ipv4 ];
}; };
environment = { environment = {
CONSUL_HTTP_ADDR = consulHttpAddr; CONSUL_HTTP_ADDR = consul.tuple;
}; };
}; };
} }

View file

@ -8,7 +8,7 @@ let
in in
{ {
services.nginx.virtualHosts.${frontendDomain} = depot.lib.nginx.vhosts.proxy "http://127.0.0.1:8500" // { services.nginx.virtualHosts.${frontendDomain} = depot.lib.nginx.vhosts.proxy config.links.consulAgent.url // {
listenAddresses = lib.singleton addr; listenAddresses = lib.singleton addr;
enableACME = false; enableACME = false;
useACMEHost = "internal.${domain}"; useACMEHost = "internal.${domain}";
@ -33,7 +33,7 @@ in
{ {
name = "Backend"; name = "Backend";
id = "service:consul-remote:backend"; id = "service:consul-remote:backend";
http = "http://127.0.0.1:8500/v1/status/leader"; http = "${config.links.consulAgent.url}/v1/status/leader";
interval = "30s"; interval = "30s";
} }
]; ];

View file

@ -1,9 +1,7 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
consulCfg = config.services.consul.extraConfig; consul = config.links.consulAgent;
consulIpAddr = consulCfg.addresses.http or "127.0.0.1";
consulHttpAddr = "${consulIpAddr}:${toString (consulCfg.ports.http or 8500)}";
kvRoot = "secrets/locksmith"; kvRoot = "secrets/locksmith";
kvValue = "recipient/${config.networking.hostName}"; kvValue = "recipient/${config.networking.hostName}";
@ -61,13 +59,13 @@ in
config.services.consul.package config.services.consul.package
]; ];
environment = { environment = {
CONSUL_HTTP_ADDR = consulHttpAddr; CONSUL_HTTP_ADDR = consul.tuple;
}; };
serviceConfig = { serviceConfig = {
PrivateTmp = true; PrivateTmp = true;
WorkingDirectory = "/tmp"; WorkingDirectory = "/tmp";
IPAddressDeny = [ "any" ]; IPAddressDeny = [ "any" ];
IPAddressAllow = [ consulIpAddr ]; IPAddressAllow = [ consul.ipv4 ];
LoadCredential = lib.mkForce []; LoadCredential = lib.mkForce [];
}; };
script = '' script = ''

View file

@ -41,7 +41,7 @@ in
softwareWatchdog = true; softwareWatchdog = true;
settings = { settings = {
consul = { consul = {
host = "127.0.0.1:8500"; host = config.links.consulAgent.tuple;
register_service = true; register_service = true;
}; };
bootstrap.dcs = { bootstrap.dcs = {

View file

@ -38,7 +38,7 @@ in
rpc_public_addr = links.garageRpc.tuple; rpc_public_addr = links.garageRpc.tuple;
rpc_secret_file = config.age.secrets.garageRpcSecret.path; rpc_secret_file = config.age.secrets.garageRpcSecret.path;
consul_discovery = { consul_discovery = {
consul_http_addr = "http://127.0.0.1:8500"; consul_http_addr = config.links.consulAgent.url;
service_name = "garage-discovery"; service_name = "garage-discovery";
}; };
s3_api = { s3_api = {

View file

@ -4,8 +4,6 @@ let
externalWays = lib.filterAttrs (_: cfg: !cfg.internal) cluster.config.ways; externalWays = 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;
consulHttpAddr = "${config.services.consul.extraConfig.addresses.http or "127.0.0.1"}:${toString (config.services.consul.extraConfig.ports.http or 8500)}";
in in
{ {
@ -63,7 +61,7 @@ in
user = "nginx"; user = "nginx";
group = "nginx"; group = "nginx";
settings = { settings = {
consul.address = "http://${consulHttpAddr}"; consul.address = config.links.consulAgent.url;
template = [ template = [
{ {
source = let source = let