chore(*): refactor the whole code #8
|
@ -93,6 +93,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,
|
||||
|
@ -430,8 +444,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,
|
||||
|
@ -445,11 +459,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
|
||||
|
@ -619,6 +633,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],
|
||||
|
@ -674,8 +689,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,
|
||||
|
@ -764,6 +779,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
|
||||
|
@ -806,6 +824,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