Skip to content

Commit 14c16f9

Browse files
committed
allow to use local workers instead of having master
1 parent 228f9be commit 14c16f9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

buildbot_nix/buildbot_nix/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ def config_for_project(
10791079
config["builders"].extend(
10801080
[
10811081
# Since all workers run on the same machine, we only assign one of them to do the evaluation.
1082-
# This should prevent exessive memory usage.
1082+
# This should prevent excessive memory usage.
10831083
nix_eval_config(
10841084
project,
10851085
worker_names,
@@ -1289,6 +1289,7 @@ def configure(self, config: dict[str, Any]) -> None:
12891289
config.setdefault("projects", [])
12901290
config.setdefault("secretsProviders", [])
12911291
config.setdefault("www", {})
1292+
config.setdefault("workers", [])
12921293

12931294
worker_names = []
12941295
for w in self.config.nix_worker_secrets().workers:
@@ -1297,8 +1298,13 @@ def configure(self, config: dict[str, Any]) -> None:
12971298
config["workers"].append(worker.Worker(worker_name, w.password))
12981299
worker_names.append(worker_name)
12991300

1301+
for i in range(self.config.local_workers):
1302+
worker_name = f"local-{i}"
1303+
config["workers"].append(worker.LocalWorker(worker_name))
1304+
worker_names.append(worker_name)
1305+
13001306
if worker_names == []:
1301-
msg = f"No workers configured in {self.config.nix_workers_secret_file}"
1307+
msg = f"No workers configured in {self.config.nix_workers_secret_file} and {self.config.local_workers} local workers."
13021308
raise BuildbotNixError(msg)
13031309

13041310
eval_lock = util.MasterLock("nix-eval")
@@ -1362,9 +1368,9 @@ def configure(self, config: dict[str, Any]) -> None:
13621368
config.setdefault("secretsProviders", [])
13631369
config["secretsProviders"].extend(backend.create_secret_providers())
13641370

1365-
systemd_secrets = SecretInAFile(
1366-
dirname=os.environ["CREDENTIALS_DIRECTORY"],
1367-
)
1371+
credentials_directory = os.environ.get("CREDENTIALS_DIRECTORY", "./secrets")
1372+
Path(credentials_directory).mkdir(exist_ok=True, parents=True)
1373+
systemd_secrets = SecretInAFile(dirname=credentials_directory)
13681374
config["secretsProviders"].append(systemd_secrets)
13691375

13701376
config["www"].setdefault("plugins", {})

buildbot_nix/buildbot_nix/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class BuildbotNixConfig(BaseModel):
269269
build_systems: list[str]
270270
eval_max_memory_size: int
271271
eval_worker_count: int | None
272-
nix_workers_secret_file: Path = Field(default=Path("buildbot-nix-workers"))
272+
local_workers: int = 0
273+
nix_workers_secret_file: Path | None = None
273274
domain: str
274275
webhook_base_url: str
275276
use_https: bool
@@ -282,6 +283,8 @@ class BuildbotNixConfig(BaseModel):
282283
branches: BranchConfigDict
283284

284285
def nix_worker_secrets(self) -> WorkerConfig:
286+
if self.nix_workers_secret_file is None:
287+
return WorkerConfig(workers=[])
285288
try:
286289
data = json.loads(read_secret_file(self.nix_workers_secret_file))
287290
except json.JSONDecodeError as e:

0 commit comments

Comments
 (0)