From cb1e2640cd6118866dce034ed5234744f73b5d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 15 Apr 2024 15:17:25 +0200 Subject: [PATCH] make worker name configurable --- buildbot_nix/worker.py | 8 +++++--- nix/worker.nix | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/buildbot_nix/worker.py b/buildbot_nix/worker.py index 3f7139d..31ae821 100644 --- a/buildbot_nix/worker.py +++ b/buildbot_nix/worker.py @@ -11,7 +11,7 @@ from twisted.python import components def require_env(key: str) -> str: 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 @@ -22,6 +22,9 @@ class WorkerConfig: .read_text() .rstrip("\r\n") ) + worker_name: str = field( + default_factory=lambda: os.environ.get("WORKER_NAME", socket.gethostname()) + ) worker_count: int = int( 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.mkdir(parents=True, exist_ok=True, mode=0o700) - hostname = socket.gethostname() - workername = f"{hostname}-{builder_id:03}" + workername = f"{config.worker_name}-{builder_id:03}" keepalive = 600 umask = None maxdelay = 300 diff --git a/nix/worker.nix b/nix/worker.nix index cf804fa..f7f1ae5 100644 --- a/nix/worker.nix +++ b/nix/worker.nix @@ -13,6 +13,11 @@ in options = { services.buildbot-nix.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 { type = lib.types.package; default = pkgs.buildbot-worker; @@ -70,7 +75,10 @@ in OOMPolicy = "continue"; 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"; User = "buildbot-worker"; Group = "buildbot-worker";