make worker name configurable

This commit is contained in:
Jörg Thalheim 2024-04-15 15:17:25 +02:00
parent 13323c8443
commit cb1e2640cd
2 changed files with 14 additions and 4 deletions

View file

@ -11,7 +11,7 @@ from twisted.python import components
def require_env(key: str) -> str: def require_env(key: str) -> str:
val = os.environ.get(key) val = os.environ.get(key)
assert val is not None, "val is not set" assert val is not None, f"{key} environment variable is not set"
return val return val
@ -22,6 +22,9 @@ class WorkerConfig:
.read_text() .read_text()
.rstrip("\r\n") .rstrip("\r\n")
) )
worker_name: str = field(
default_factory=lambda: os.environ.get("WORKER_NAME", socket.gethostname())
)
worker_count: int = int( worker_count: int = int(
os.environ.get("WORKER_COUNT", str(multiprocessing.cpu_count())), os.environ.get("WORKER_COUNT", str(multiprocessing.cpu_count())),
) )
@ -39,8 +42,7 @@ def setup_worker(
basedir = config.buildbot_dir.parent / f"{config.buildbot_dir.name}-{builder_id:03}" basedir = config.buildbot_dir.parent / f"{config.buildbot_dir.name}-{builder_id:03}"
basedir.mkdir(parents=True, exist_ok=True, mode=0o700) basedir.mkdir(parents=True, exist_ok=True, mode=0o700)
hostname = socket.gethostname() workername = f"{config.worker_name}-{builder_id:03}"
workername = f"{hostname}-{builder_id:03}"
keepalive = 600 keepalive = 600
umask = None umask = None
maxdelay = 300 maxdelay = 300

View file

@ -13,6 +13,11 @@ in
options = { options = {
services.buildbot-nix.worker = { services.buildbot-nix.worker = {
enable = lib.mkEnableOption "buildbot-worker"; enable = lib.mkEnableOption "buildbot-worker";
name = lib.mkOption {
type = lib.types.str;
default = config.networking.hostName;
description = "The buildbot worker name.";
};
package = lib.mkOption { package = lib.mkOption {
type = lib.types.package; type = lib.types.package;
default = pkgs.buildbot-worker; default = pkgs.buildbot-worker;
@ -70,7 +75,10 @@ in
OOMPolicy = "continue"; OOMPolicy = "continue";
LoadCredential = [ "worker-password-file:${cfg.workerPasswordFile}" ]; LoadCredential = [ "worker-password-file:${cfg.workerPasswordFile}" ];
Environment = [ "WORKER_PASSWORD_FILE=%d/worker-password-file" ]; Environment = [
"WORKER_PASSWORD_FILE=%d/worker-password-file"
"WORKER_NAME=${cfg.name}"
];
Type = "simple"; Type = "simple";
User = "buildbot-worker"; User = "buildbot-worker";
Group = "buildbot-worker"; Group = "buildbot-worker";