chore(builders): localize builders specification like Hydra does

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
raito 2024-07-18 12:12:32 +02:00
parent 1cb13868bc
commit 10160a1373

View file

@ -3,6 +3,7 @@ import multiprocessing
import os
import sys
import graphlib
import base64
from collections.abc import Generator
from dataclasses import dataclass
from pathlib import Path
@ -36,6 +37,26 @@ log = Logger()
FLAKE_TARGET_ATTRIBUTE_FOR_JOBS = "buildbotJobs"
@dataclass
class NixBuilder:
protocol: str
hostName: str
maxJobs: int
speedFactor: int = 1
# without base64
publicHostKey: str | None = None
sshUser: str | None = None
sshKey: str | None = None
systems: list[str] = ["-"]
supportedFeatures: list[str] = ["-"]
mandatoryFeatures: list[str] = ["-"]
def to_nix_line(self):
encoded_public_key = base64.b64encode(self.publicHostKey.encode('ascii')).decode('ascii') if self.publicHostKey is not None else "-"
fullConnection = f"{self.protocol}://{self.sshUser}@{self.hostName}" if self.sshUser is not None else self.hostName
return f"{fullConnection} {",".join(self.systems)} {self.sshKey or "-"} {self.maxJobs} {self.speedFactor} {",".join(self.supportedFeatures)} {",".join(self.mandatoryFeatures)} {encoded_public_key}"
@dataclass
class OAuth2Config:
name: str
@ -499,6 +520,7 @@ def nix_build_config(
project: GerritProject,
worker_arch: str,
worker_names: list[str],
builders_spec: str,
signing_keyfile: str | None = None,
binary_cache_config: S3BinaryCacheConfig | None = None
) -> util.BuilderConfig:
@ -522,6 +544,8 @@ def nix_build_config(
"--max-silent-time",
str(60 * 20),
"--accept-flake-config",
"--builders",
builders_spec,
"--out-link",
util.Interpolate("result-%(prop:attr)s"),
util.Interpolate("%(prop:drv_path)s^*"),
@ -618,6 +642,7 @@ def config_for_project(
nix_eval_worker_count: int,
nix_eval_max_memory_size: int,
eval_lock: util.MasterLock,
builders_spec: str,
signing_keyfile: str | None = None,
binary_cache_config: S3BinaryCacheConfig | None = None
) -> Project:
@ -680,6 +705,7 @@ def config_for_project(
project,
arch,
[ f"{w}-{arch}" for w in worker_names ],
builders_spec,
signing_keyfile=signing_keyfile,
binary_cache_config=binary_cache_config
)
@ -757,6 +783,7 @@ class GerritNixConfigurator(ConfiguratorBase):
projects: list[str],
url: str,
allowed_origins: list[str],
nix_builders: list[dict[str, Any]],
nix_supported_systems: list[str],
nix_eval_worker_count: int | None,
nix_eval_max_memory_size: int,
@ -780,6 +807,7 @@ class GerritNixConfigurator(ConfiguratorBase):
self.nix_eval_max_memory_size = nix_eval_max_memory_size
self.nix_eval_worker_count = nix_eval_worker_count
self.nix_supported_systems = nix_supported_systems
self.nix_builders: list[NixBuilder] = [NixBuilder(**builder_cfg) for builder_cfg in nix_builders]
self.gerrit_change_source = GerritChangeSource(gerrit_server, gerrit_user, gerritport=gerrit_port, identity_file=gerrit_sshkey_path)
@ -814,6 +842,7 @@ class GerritNixConfigurator(ConfiguratorBase):
eval_lock = util.MasterLock("nix-eval")
builders_spec = " ; ".join(builder.to_nix_line() for builder in self.nix_builders)
for project in self.projects:
config_for_project(
config,
@ -824,6 +853,7 @@ class GerritNixConfigurator(ConfiguratorBase):
self.nix_eval_worker_count or multiprocessing.cpu_count(),
self.nix_eval_max_memory_size,
eval_lock,
builders_spec,
signing_keyfile=self.signing_keyfile,
binary_cache_config=self.binary_cache_config
)