Add remote autoscaler daemon endpoint support
All checks were successful
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
buildbot/nix-effects Build done.

This commit is contained in:
Abel Luck 2026-03-05 15:47:57 +01:00
parent 95021a4253
commit 679b5c8d07
11 changed files with 291 additions and 22 deletions

View file

@ -25,6 +25,18 @@ in
description = "Autoscaler daemon Unix socket path for Buildbot gate/release steps.";
};
daemonUrl = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Optional autoscaler daemon HTTP(S) endpoint URL for remote gate/release calls.";
};
daemonAuthTokenFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Optional file containing bearer token for authenticated daemon API calls.";
};
defaultSystem = lib.mkOption {
type = lib.types.str;
default = "x86_64-linux";
@ -131,6 +143,10 @@ in
assertion = cfg.builderClusterHost != null;
message = "services.buildbot-nix.nix-build-autoscaler.builderClusterHost must be set.";
}
{
assertion = cfg.daemonUrl != null || cfg.daemonSocket != "";
message = "services.buildbot-nix.nix-build-autoscaler requires either daemonUrl or daemonSocket.";
}
];
services.buildbot-master.pythonPackages = ps: [
@ -149,6 +165,7 @@ in
];
services.buildbot-master.extraImports = ''
import pathlib
from buildbot_autoscale_ext.configurator import AutoscaleConfigurator
from buildbot_autoscale_ext.settings import AutoscaleSettings
'';
@ -157,7 +174,14 @@ in
''
AutoscaleConfigurator(
AutoscaleSettings(
daemon_socket="${cfg.daemonSocket}",
daemon_socket=${if cfg.daemonUrl == null then ''"${cfg.daemonSocket}"'' else "None"},
daemon_url=${if cfg.daemonUrl != null then ''"${cfg.daemonUrl}"'' else "None"},
daemon_auth_token=${
if cfg.daemonAuthTokenFile != null then
''pathlib.Path("${cfg.daemonAuthTokenFile}").read_text(encoding="utf-8").strip()''
else
"None"
},
default_system="${cfg.defaultSystem}",
reserve_timeout_seconds=${toString cfg.reserveTimeoutSeconds},
poll_interval_seconds=${toString cfg.pollIntervalSeconds},

View file

@ -45,6 +45,24 @@ in
description = "Unix socket path exposed by the autoscaler API server.";
};
listenHost = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "TCP listen host for the autoscaler API server when listenPort is set.";
};
listenPort = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = "Optional TCP listen port for the autoscaler API server. Null keeps Unix socket mode.";
};
authTokenFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Optional file containing bearer token required for /v1 and /metrics API requests.";
};
logLevel = lib.mkOption {
type = lib.types.str;
default = "info";
@ -287,6 +305,10 @@ in
assertion = !cfg.capacity.nestedVirtualization || cfg.aws.onDemandLaunchTemplateIdFile != null;
message = "services.nix-builder-autoscaler.aws.onDemandLaunchTemplateIdFile must be set when capacity.nestedVirtualization is true.";
}
{
assertion = cfg.listenPort == null || (cfg.listenPort >= 1 && cfg.listenPort <= 65535);
message = "services.nix-builder-autoscaler.listenPort must be null or a TCP port between 1 and 65535.";
}
];
environment.systemPackages = [ cfg.package ];
@ -338,10 +360,16 @@ in
${lib.optionalString (cfg.aws.assumeRoleArnFile != null) ''
assume_role_arn="$(tr -d '\n' < ${lib.escapeShellArg cfg.aws.assumeRoleArnFile})"
''}
${lib.optionalString (cfg.authTokenFile != null) ''
auth_token="$(tr -d '\n' < ${lib.escapeShellArg cfg.authTokenFile})"
''}
cat > ${generatedConfigPath} <<EOF
[server]
socket_path = "${cfg.socketPath}"
listen_host = "${cfg.listenHost}"
listen_port = ${toString (if cfg.listenPort != null then cfg.listenPort else 0)}
${lib.optionalString (cfg.authTokenFile != null) ''auth_token = "$auth_token"''}
log_level = "${cfg.logLevel}"
db_path = "${cfg.dbPath}"