traefik: routes from a watched file, no restart on a route change
All checks were successful
nixos / nixos (push) Successful in 21s
All checks were successful
nixos / nixos (push) Successful in 21s
The NixOS module writes the routes (dynamicConfigOptions) into the static configuration, so every route change restarted Traefik: about 15 seconds with every site down (08:24 and 09:14 today; the second broke czsk's image push). The routes now go to /etc/traefik/dynamic.toml, a copy activation replaces, and Traefik's file provider watches it; the static configuration stays the same. This deploy restarts Traefik once. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
677c7eb34a
commit
cb9db0ed73
1 changed files with 14 additions and 0 deletions
|
|
@ -54,10 +54,23 @@ in
|
|||
}
|
||||
'';
|
||||
|
||||
# The routes go to a file Traefik watches, not into its static
|
||||
# configuration: the NixOS module would otherwise write them into the
|
||||
# static file, and every route change would restart Traefik (about 15
|
||||
# seconds with every site down). mode makes /etc hold a copy, which
|
||||
# activation replaces, so the watch sees the change.
|
||||
environment.etc."traefik/dynamic.toml" = {
|
||||
source =
|
||||
(pkgs.formats.toml { }).generate "dynamic.toml"
|
||||
config.services.traefik.dynamicConfigOptions;
|
||||
mode = "0444";
|
||||
};
|
||||
|
||||
services.traefik = {
|
||||
enable = true;
|
||||
package = pkgs.traefik;
|
||||
environmentFiles = [ config.sops.templates."traefik.env".path ];
|
||||
dynamicConfigFile = "/etc/traefik/dynamic.toml";
|
||||
|
||||
staticConfigOptions = {
|
||||
api = {
|
||||
|
|
@ -81,6 +94,7 @@ in
|
|||
addRoutersLabels = true;
|
||||
addServicesLabels = true;
|
||||
};
|
||||
providers.file.watch = true; # filename: dynamicConfigFile
|
||||
providers.docker = {
|
||||
endpoint = "unix:///run/podman/podman.sock";
|
||||
exposedByDefault = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue