move extraConfig into configurator

extraConfig can be only set once. By moving it to the configurator we allow users to set this option themself.
This commit is contained in:
Jörg Thalheim 2023-12-05 21:52:25 +01:00 committed by mergify[bot]
parent dd6eacc4c4
commit cbe4ce0571
2 changed files with 15 additions and 14 deletions

View file

@ -750,6 +750,7 @@ class NixConfigurator(ConfiguratorBase):
nix_eval_max_memory_size: int,
nix_workers_secret_name: str = "buildbot-nix-workers",
outputs_path: str | None = None,
prometheus_exporter_port: int | None = None,
) -> None:
super().__init__()
self.nix_workers_secret_name = nix_workers_secret_name
@ -763,6 +764,7 @@ class NixConfigurator(ConfiguratorBase):
self.outputs_path = None
else:
self.outputs_path = Path(outputs_path)
self.prometheus_exporter_port = prometheus_exporter_port
def configure(self, config: dict[str, Any]) -> None:
projects = load_projects(self.github.token(), self.github.project_cache_file)
@ -839,13 +841,20 @@ class NixConfigurator(ConfiguratorBase):
context=Interpolate("buildbot/%(prop:status_name)s"),
)
)
if self.prometheus_exporter_port:
config["services"].append(
reporters.Prometheus(port=self.prometheus_exporter_port)
)
systemd_secrets = secrets.SecretInAFile(
dirname=os.environ["CREDENTIALS_DIRECTORY"]
)
config["secretsProviders"].append(systemd_secrets)
config["www"]["change_hook_dialects"] = config["www"].get(
"change_hook_dialects", {}
)
config["www"].setdefault("plugins", {})
config["www"]["plugins"].update(dict(base_react={}))
config["www"].setdefault("change_hook_dialects", {})
config["www"]["change_hook_dialects"]["github"] = {
"secret": webhook_secret,
"strict": True,
@ -853,8 +862,8 @@ class NixConfigurator(ConfiguratorBase):
"github_property_whitelist": "*",
}
if not config["www"].get("auth"):
config["www"]["avatar_methods"] = config["www"].get("avatar_methods", [])
if "auth" not in config["www"]:
config["www"].setdefault("avatar_methods", [])
config["www"]["avatar_methods"].append(
util.AvatarGitHub(token=self.github.token())
)

View file

@ -126,15 +126,6 @@ in
from datetime import timedelta
from buildbot_nix import GithubConfig, NixConfigurator
'';
extraConfig = ''
c["www"]["plugins"] = c["www"].get("plugins", {})
c["www"]["plugins"].update(
dict(base_react={})
)
${lib.optionalString (cfg.prometheusExporterPort != null) ''
c['services'].append(reporters.Prometheus(port=${builtins.toString cfg.prometheusExporterPort}))
''}
'';
configurators = [
''
util.JanitorConfigurator(logHorizon=timedelta(weeks=4), hour=12, dayOfWeek=6)
@ -152,6 +143,7 @@ in
nix_eval_worker_count=${builtins.toJSON cfg.evalWorkerCount},
nix_supported_systems=${builtins.toJSON cfg.buildSystems},
outputs_path=${if cfg.outputsPath == null then "None" else builtins.toJSON cfg.outputsPath},
prometheus_exporter_port=${if cfg.prometheusExporterPort == null then "None" else builtins.toJSON cfg.prometheusExporterPort},
)
''
];