cluster/services/attic: make HA

This commit is contained in:
Max Headroom 2024-08-02 22:46:45 +02:00
parent 1fe6324c37
commit 5d26d45916
5 changed files with 85 additions and 28 deletions

View file

@ -1,11 +1,13 @@
age-encryption.org/v1 age-encryption.org/v1
-> ssh-ed25519 NO562A mLMev+YA6zSxAWIIlwseZk8Skl4hfNNsWQPmLV7DxTo -> ssh-ed25519 d3WGuA ZLjCSe5wrN6abvvRmQjE+VXtRr+avP/CLPD7djXNr0M
AEi55ZXzyYbZyludcP5Yywx7QDgFODh6z8+M2nxMAl4 g8i9ambJGL2Q+ZLB6c6MxV9BryAgX4qZctJ9qByJ4n8
-> ssh-ed25519 5/zT0w 91baPvXx4UdmyYCCIqc1M+Cb7pqdSx3/cgmfuexeUgY -> ssh-ed25519 P/nEqQ zSGcZuufOAnTkPr74ZjwyISdLlfxBxqgmyWivxq1/Uo
kePQp8flAsXPMLxJiQPoJuHEPPI+FzaSF+VL9U9jhwI gArusBfIfsZ5/gwMYHLzDHTbgVGWDttbi0IAhvclRO4
-> ssh-ed25519 d3WGuA U8Q68hN+5fI4xto/lpCiVyts00ezCzftfLvFFew7aiY -> ssh-ed25519 YIaSKQ J4Fy0VSjdMPRgzysQptIUKiRR0TAgu0q1BYhtIpGkWU
B4wv05Y2gpl5qjV1Rbc6JSJk3coN6TFMB5FspwzLnlI kKzmF3OUbGU40d33R15nMraUDZiFRoz9Z00XjjSk9Jw
-> :0eX-grease -> ssh-ed25519 NO562A BNQV8JodzTiNs/V+rFQxcsrhKJ3nRIFtWk6VxHzCRio
ghW6iCUZj0e04I8Ba3CHzg ZyauAdOrPbADSDdBQoB+39MB2r7Ro4d0XwZIjf2z9Jo
--- aHnzzTi1WxtHXGcQO1hNgmy04wyyObmYBcSq5fmbnAg -> ssh-ed25519 5/zT0w hdMuyOmNKTlMKPn4w9VQFVXZkJNm1XSPAZ/Zip5WW04
Ñdï<EFBFBD>ÎÁŽ#¹<>¬sä®nƒŒó¤ž§F#5IZ<49><5A>¯áË2wb®×¨âÑÞüËoœkm÷ÒåN&"¤ü0LeÑzI jx—µzxF€´>ršúEq´Ý¤¥Anx¿šB!@‰ÕŸÆò2r©:ïm5í-Xl5çAåðÌSV¿R3`Ð艨{ÿò<C3BF>ï©#ÍJgHÖ‡ÊÉg wcnur+BRQPqKzpV3vl7pn1VIGRK3GxQEUaQIefrZuI4
--- 5AdxXgFmDm2w012QjpJ3gqlbfvkPm8fkEJjm8kV18G0
f§äIT¼-ÿY!ŒÍ,Vu<56>Â9õÿöBFrœŠ´½4ù™BÕÝ/®UäH˜¸ž #ƒˆç ÄÝÕº†®UóQ¢ÿŽx$G{ÅŠMà2¡^/˜§¥Éè?12É¿t1©¿í¸&[}nêDAÛlýÑ ýˆ8uG®éZŽ×b ¯èàîåd:@ÿ!Õþ jîƒÚáÈNµrâlA³~

View file

@ -1,10 +1,16 @@
{ config, cluster, depot, ... }: { config, cluster, depot, lib, ... }:
with depot.lib.nginx; with depot.lib.nginx;
{ {
links.garageNixStoreInternalRedirect = { links = {
protocol = "http"; atticNixStoreInternalRedirect.protocol = "http";
path = "/nix-store"; garageNixStoreInternalRedirect.protocol = "http";
}; };
security.acme.certs."cache.${depot.lib.meta.domain}" = {
dnsProvider = "exec";
webroot = lib.mkForce null;
};
services.nginx.upstreams = { services.nginx.upstreams = {
nar-serve.extraConfig = '' nar-serve.extraConfig = ''
random; random;
@ -12,10 +18,10 @@ with depot.lib.nginx;
server ${config.links.nar-serve-nixos-org.tuple} fail_timeout=0; server ${config.links.nar-serve-nixos-org.tuple} fail_timeout=0;
''; '';
nix-store.servers = { nix-store.servers = {
"${config.links.atticServer.tuple}" = { "${config.links.garageNixStoreInternalRedirect.tuple}" = {
fail_timeout = 0; fail_timeout = 0;
}; };
"${config.links.garageNixStoreInternalRedirect.tuple}" = { "${config.links.atticNixStoreInternalRedirect.tuple}" = {
fail_timeout = 0; fail_timeout = 0;
}; };
}; };
@ -28,7 +34,7 @@ with depot.lib.nginx;
locations = { locations = {
"= /".return = "302 /404"; "= /".return = "302 /404";
"/" = { "/" = {
proxyPass = "http://nix-store/nix-store$request_uri"; proxyPass = "http://nix-store";
extraConfig = '' extraConfig = ''
proxy_next_upstream error http_500 http_502 http_404; proxy_next_upstream error http_500 http_502 http_404;
''; '';
@ -56,13 +62,29 @@ with depot.lib.nginx;
inherit (config.links.garageNixStoreInternalRedirect) port; inherit (config.links.garageNixStoreInternalRedirect) port;
} }
]; ];
locations."~ ^${config.links.garageNixStoreInternalRedirect.path}/(.*)" = { locations."/" = {
proxyPass = with cluster.config.links.garageWeb; "${protocol}://nix-store.${hostname}/$1"; proxyPass = with cluster.config.links.garageWeb; "${protocol}://nix-store.${hostname}";
recommendedProxySettings = false; recommendedProxySettings = false;
extraConfig = '' extraConfig = ''
proxy_set_header Host "nix-store.${cluster.config.links.garageWeb.hostname}"; proxy_set_header Host "nix-store.${cluster.config.links.garageWeb.hostname}";
''; '';
}; };
}; };
"attic-nix-store.internal.${depot.lib.meta.domain}" = {
serverName = "127.0.0.1";
listen = [
{
addr = "127.0.0.1";
inherit (config.links.atticNixStoreInternalRedirect) port;
}
];
locations."/" = {
proxyPass = "https://cache-api.${depot.lib.meta.domain}/nix-store$request_uri";
recommendedProxySettings = false;
extraConfig = ''
proxy_set_header Host "cache-api.${depot.lib.meta.domain}";
'';
};
};
}; };
} }

View file

@ -3,15 +3,23 @@
{ {
services.attic = { services.attic = {
nodes = { nodes = {
server = [ "VEGAS" ]; monolith = [ "VEGAS" "prophet" ];
server = [ "VEGAS" "grail" "prophet" ];
}; };
nixos = { nixos = {
monolith = [
./server.nix
];
server = [ server = [
./server.nix ./server.nix
./binary-cache.nix ./binary-cache.nix
./nar-serve.nix ./nar-serve.nix
]; ];
}; };
meshLinks.server = {
name = "attic";
link.protocol = "http";
};
secrets = let secrets = let
inherit (config.services.attic) nodes; inherit (config.services.attic) nodes;
in { in {
@ -41,7 +49,13 @@
(node: depot.hours.${node}.interfaces.primary.addrPublic) (node: depot.hours.${node}.interfaces.primary.addrPublic)
config.services.attic.nodes.server; config.services.attic.nodes.server;
in { in {
cache-api.target = serverAddrs;
cache.target = serverAddrs; cache.target = serverAddrs;
}; };
ways.cache-api = {
consulService = "atticd";
extras.extraConfig = ''
client_max_body_size 4G;
'';
};
} }

View file

@ -2,6 +2,10 @@
let let
inherit (cluster.config.services.attic) secrets; inherit (cluster.config.services.attic) secrets;
link = cluster.config.hostLinks.${config.networking.hostName}.attic;
isMonolith = lib.elem config.networking.hostName cluster.config.services.attic.nodes.monolith;
in in
{ {
@ -9,8 +13,6 @@ in
depot.inputs.attic.nixosModules.atticd depot.inputs.attic.nixosModules.atticd
]; ];
links.atticServer.protocol = "http";
services.locksmith.waitForSecrets.atticd = [ "garage-attic" ]; services.locksmith.waitForSecrets.atticd = [ "garage-attic" ];
services.atticd = { services.atticd = {
@ -18,9 +20,10 @@ in
package = depot.inputs.attic.packages.attic-server; package = depot.inputs.attic.packages.attic-server;
credentialsFile = secrets.serverToken.path; credentialsFile = secrets.serverToken.path;
mode = if isMonolith then "monolithic" else "api-server";
settings = { settings = {
listen = config.links.atticServer.tuple; listen = link.tuple;
chunking = { chunking = {
nar-size-threshold = 0; nar-size-threshold = 0;
@ -59,8 +62,13 @@ in
systemd.services.atticd = { systemd.services.atticd = {
after = [ "postgresql.service" ]; after = [ "postgresql.service" ];
distributed = lib.mkIf isMonolith {
enable = true;
registerService = "atticd";
};
serviceConfig = { serviceConfig = {
DynamicUser = lib.mkForce false; DynamicUser = lib.mkForce false;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" "AF_NETLINK" ];
}; };
environment = { environment = {
AWS_SHARED_CREDENTIALS_FILE = "/run/locksmith/garage-attic"; AWS_SHARED_CREDENTIALS_FILE = "/run/locksmith/garage-attic";
@ -68,9 +76,20 @@ in
}; };
}; };
services.nginx.virtualHosts."cache-api.${depot.lib.meta.domain}" = depot.lib.nginx.vhosts.proxy config.links.atticServer.url // { consul.services.atticd = {
extraConfig = '' mode = if isMonolith then "manual" else "direct";
client_max_body_size 4G; definition = {
''; name = "atticd";
address = link.ipv4;
inherit (link) port;
checks = [
{
name = "Attic Server";
id = "service:atticd:backend";
interval = "5s";
http = link.url;
}
];
};
}; };
} }