chore(builders): localize builders specification like Hydra does
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
parent
6584d7ebbc
commit
9d457e6e02
|
@ -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
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{ config
|
||||
, options
|
||||
, pkgs
|
||||
, lib
|
||||
, ...
|
||||
|
@ -15,11 +16,17 @@ in
|
|||
default = "postgresql://@/buildbot";
|
||||
description = "Postgresql database url";
|
||||
};
|
||||
|
||||
workersFile = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "File containing a list of nix workers";
|
||||
};
|
||||
|
||||
buildMachines = lib.mkOption {
|
||||
type = options.nix.buildMachines.type;
|
||||
description = "List of local remote builders machines associated to that Buildbot instance";
|
||||
};
|
||||
|
||||
oauth2 = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
|
@ -216,6 +223,7 @@ in
|
|||
nix_eval_max_memory_size=${builtins.toJSON cfg.evalMaxMemorySize},
|
||||
nix_eval_worker_count=${if cfg.evalWorkerCount == null then "None" else builtins.toString cfg.evalWorkerCount},
|
||||
nix_supported_systems=${builtins.toJSON cfg.buildSystems},
|
||||
nix_builders=${builtins.toJSON cfg.buildMachines},
|
||||
# Signing key file must be available on the workers and readable.
|
||||
signing_keyfile=${if cfg.signingKeyFile == null then "None" else builtins.toJSON cfg.signingKeyFile},
|
||||
binary_cache_config=${if (!cfg.binaryCache.enable) then "None" else builtins.toJSON {
|
||||
|
|
Loading…
Reference in a new issue