chore(gerrit): put the gerrit configuration in one place and generate repo URLs templates
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
parent
b417cd4519
commit
f647440f86
|
@ -59,6 +59,20 @@ class GerritProject:
|
|||
# Private SSH key path to access Gerrit API
|
||||
private_sshkey_path: str
|
||||
|
||||
@dataclass
|
||||
class GerritConfig:
|
||||
# Gerrit server domain
|
||||
domain: str
|
||||
port: int
|
||||
username: str
|
||||
|
||||
@property
|
||||
def repourl_template(self) -> str:
|
||||
"""
|
||||
Returns the prefix to build a repourl using that gerrit configuration.
|
||||
"""
|
||||
return 'ssh://{self.username}@{self.domain}:{self.port}/'
|
||||
|
||||
class BuildTrigger(steps.BuildStep):
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -396,8 +410,8 @@ class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep):
|
|||
|
||||
|
||||
def nix_eval_config(
|
||||
gerrit_config: GerritConfig,
|
||||
project: GerritProject,
|
||||
gerrit_private_key: str,
|
||||
worker_names: list[str],
|
||||
supported_systems: list[str],
|
||||
eval_lock: util.MasterLock,
|
||||
|
@ -411,11 +425,11 @@ def nix_eval_config(
|
|||
# check out the source
|
||||
factory.addStep(
|
||||
steps.Gerrit(
|
||||
repourl="ssh://buildbot@gerrit.lix.systems:2022/lix",
|
||||
repourl=f'{gerrit_config.repourl_template}/{project.name}',
|
||||
mode="full",
|
||||
retry=[60, 60],
|
||||
timeout=3600,
|
||||
sshPrivateKey=gerrit_private_key
|
||||
sshPrivateKey=project.private_sshkey_path
|
||||
),
|
||||
)
|
||||
# use one gcroots directory per worker. this should be scoped to the largest unique resource
|
||||
|
@ -589,6 +603,7 @@ def read_secret_file(secret_name: str) -> str:
|
|||
|
||||
def config_for_project(
|
||||
config: dict[str, Any],
|
||||
gerrit_config: GerritConfig,
|
||||
project: GerritProject,
|
||||
worker_names: list[str],
|
||||
nix_supported_systems: list[str],
|
||||
|
@ -644,8 +659,8 @@ def config_for_project(
|
|||
# Since all workers run on the same machine, we only assign one of them to do the evaluation.
|
||||
# This should prevent exessive memory usage.
|
||||
nix_eval_config(
|
||||
gerrit_config,
|
||||
project,
|
||||
gerrit_private_key,
|
||||
[ f"{w}-other" for w in worker_names ],
|
||||
supported_systems=nix_supported_systems,
|
||||
worker_count=nix_eval_worker_count,
|
||||
|
@ -733,6 +748,9 @@ class GerritNixConfigurator(ConfiguratorBase):
|
|||
self.gerrit_user = gerrit_user
|
||||
self.gerrit_port = gerrit_port
|
||||
self.gerrit_sshkey_path = gerrit_sshkey_path
|
||||
self.gerrit_config = GerritConfig(domain=self.gerrit_server,
|
||||
username=self.gerrit_user,
|
||||
port=self.gerrit_port)
|
||||
self.projects = projects
|
||||
|
||||
self.nix_workers_secret_name = nix_workers_secret_name
|
||||
|
@ -774,6 +792,7 @@ class GerritNixConfigurator(ConfiguratorBase):
|
|||
for project in self.projects:
|
||||
config_for_project(
|
||||
config,
|
||||
self.gerrit_config,
|
||||
GerritProject(name=project, private_sshkey_path=self.gerrit_sshkey_path),
|
||||
worker_names,
|
||||
self.nix_supported_systems,
|
||||
|
|
Loading…
Reference in a new issue