feat: enable per-worker local store slots #24
|
@ -24,6 +24,7 @@ from buildbot.reporters.generators.build import BuildStatusGenerator
|
||||||
from buildbot.reporters.message import MessageFormatterFunction
|
from buildbot.reporters.message import MessageFormatterFunction
|
||||||
from buildbot.process.buildstep import EXCEPTION
|
from buildbot.process.buildstep import EXCEPTION
|
||||||
from buildbot.process.buildstep import SUCCESS
|
from buildbot.process.buildstep import SUCCESS
|
||||||
|
from buildbot.process.buildstep import BuildStepFailed
|
||||||
from buildbot.process.results import worst_status
|
from buildbot.process.results import worst_status
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -39,6 +40,14 @@ log = Logger()
|
||||||
|
|
||||||
FLAKE_TARGET_ATTRIBUTE_FOR_JOBS = "buildbotJobs"
|
FLAKE_TARGET_ATTRIBUTE_FOR_JOBS = "buildbotJobs"
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EvaluatorSettings:
|
||||||
|
supported_systems: list[str]
|
||||||
|
worker_count: int
|
||||||
|
max_memory_size: int
|
||||||
|
gc_roots_dir: str
|
||||||
|
lock: util.MasterLock
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class NixBuilder:
|
class NixBuilder:
|
||||||
protocol: str
|
protocol: str
|
||||||
|
@ -436,7 +445,7 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
|
||||||
[
|
[
|
||||||
BuildTrigger(
|
BuildTrigger(
|
||||||
builds_scheduler_group=f"{project_name}-nix-build",
|
builds_scheduler_group=f"{project_name}-nix-build",
|
||||||
name="build flake",
|
name="build derivations",
|
||||||
jobs=filtered_jobs,
|
jobs=filtered_jobs,
|
||||||
all_deps=all_deps,
|
all_deps=all_deps,
|
||||||
),
|
),
|
||||||
|
@ -445,6 +454,78 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def make_job_evaluator(name: str, settings: EvaluatorSettings, flake: bool) -> NixEvalCommand:
|
||||||
|
actual_command = []
|
||||||
|
|
||||||
|
if flake:
|
||||||
|
actual_command += ["--flake", f".#{FLAKE_TARGET_ATTRIBUTE_FOR_JOBS}"]
|
||||||
|
else:
|
||||||
|
actual_command += ["--expr", "'import ./.ci/buildbot.nix'"]
|
||||||
|
|
||||||
|
return NixEvalCommand(
|
||||||
|
env={},
|
||||||
|
name=name,
|
||||||
|
supported_systems=settings.supported_systems,
|
||||||
|
command=[
|
||||||
|
"nix-eval-jobs",
|
||||||
|
"--workers",
|
||||||
|
str(settings.worker_count),
|
||||||
|
"--max-memory-size",
|
||||||
|
str(settings.max_memory_size),
|
||||||
|
"--gc-roots-dir",
|
||||||
|
settings.gc_roots_dir,
|
||||||
|
"--force-recurse",
|
||||||
|
"--check-cache-status",
|
||||||
|
] + actual_command,
|
||||||
|
haltOnFailure=True,
|
||||||
|
locks=[settings.lock.access("exclusive")]
|
||||||
|
)
|
||||||
|
|
||||||
|
class NixConfigure(buildstep.CommandMixin, steps.BuildStep):
|
||||||
|
"""
|
||||||
|
Determine what `NixEvalCommand` step should be added after
|
||||||
|
based on the existence of:
|
||||||
|
|
||||||
|
- flake.nix
|
||||||
|
- .ci/buildbot.nix
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, eval_settings: EvaluatorSettings, **kwargs: Any) -> None:
|
||||||
|
self.evaluator_settings = eval_settings
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.observer = logobserver.BufferLogObserver()
|
||||||
|
self.addLogObserver("stdio", self.observer)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def run(self) -> Generator[Any, object, Any]:
|
||||||
|
configure_log: Log = yield self.getLog("stdio")
|
||||||
|
|
||||||
|
# Takes precedence.
|
||||||
|
configure_log.addStdout("checking if there's a .ci/buildbot.nix...")
|
||||||
|
ci_buildbot_defn_exists = yield self.pathExists('.ci/buildbot.nix')
|
||||||
|
if ci_buildbot_defn_exists:
|
||||||
|
configure_log.addStdout(".ci/buildbot.nix found, configured for non-flake CI")
|
||||||
|
self.build.addStepAfterCurrentStep(
|
||||||
|
make_job_evaluator(
|
||||||
|
"evaluate `.ci/buildbot.nix` jobs",
|
||||||
|
self.evaluator_settings,
|
||||||
|
False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
flake_exists = yield self.pathExists('flake.nix')
|
||||||
|
if flake_exists:
|
||||||
|
configure_log.addStdout(f"flake.nix found")
|
||||||
|
self.build.addStepAfterCurrentStep(
|
||||||
|
make_job_evaluator(
|
||||||
|
"evaluate `flake.nix` jobs",
|
||||||
|
self.evaluator_settings,
|
||||||
|
True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
configure_log.addStdout("neither flake.nix found neither .ci/buildbot.nix, no CI to run!")
|
||||||
|
|
||||||
class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep):
|
class NixBuildCommand(buildstep.ShellMixin, steps.BuildStep):
|
||||||
"""Builds a nix derivation."""
|
"""Builds a nix derivation."""
|
||||||
|
@ -486,7 +567,8 @@ def nix_eval_config(
|
||||||
worker_count: int,
|
worker_count: int,
|
||||||
max_memory_size: int,
|
max_memory_size: int,
|
||||||
) -> util.BuilderConfig:
|
) -> util.BuilderConfig:
|
||||||
"""Uses nix-eval-jobs to evaluate $FLAKE_TARGET_ATTRIBUTE_FOR_JOBS (`.#hydraJobs` by default) from flake.nix in parallel.
|
"""
|
||||||
|
Uses nix-eval-jobs to evaluate the entrypoint of this project.
|
||||||
For each evaluated attribute a new build pipeline is started.
|
For each evaluated attribute a new build pipeline is started.
|
||||||
"""
|
"""
|
||||||
factory = util.BuildFactory()
|
factory = util.BuildFactory()
|
||||||
|
@ -517,27 +599,22 @@ def nix_eval_config(
|
||||||
"/nix/var/nix/gcroots/per-user/buildbot-worker/%(prop:project)s/drvs/%(prop:workername)s/",
|
"/nix/var/nix/gcroots/per-user/buildbot-worker/%(prop:project)s/drvs/%(prop:workername)s/",
|
||||||
)
|
)
|
||||||
|
|
||||||
factory.addStep(
|
eval_settings = EvaluatorSettings(
|
||||||
NixEvalCommand(
|
|
||||||
env={},
|
|
||||||
name="evaluate flake",
|
|
||||||
supported_systems=supported_systems,
|
supported_systems=supported_systems,
|
||||||
command=[
|
worker_count=worker_count,
|
||||||
"nix-eval-jobs",
|
max_memory_size=max_memory_size,
|
||||||
"--workers",
|
gc_roots_dir=drv_gcroots_dir,
|
||||||
str(worker_count),
|
lock=eval_lock
|
||||||
"--max-memory-size",
|
)
|
||||||
str(max_memory_size),
|
|
||||||
"--gc-roots-dir",
|
# NixConfigure will choose
|
||||||
drv_gcroots_dir,
|
# how to add a NixEvalCommand job
|
||||||
"--force-recurse",
|
# based on whether there's a flake.nix or
|
||||||
"--check-cache-status",
|
# a .ci/buildbot.nix.
|
||||||
"--flake",
|
factory.addStep(
|
||||||
f".#{FLAKE_TARGET_ATTRIBUTE_FOR_JOBS}"
|
NixConfigure(
|
||||||
],
|
eval_settings
|
||||||
haltOnFailure=True,
|
)
|
||||||
locks=[eval_lock.access("exclusive")],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
factory.addStep(
|
factory.addStep(
|
||||||
|
|
Loading…
Reference in a new issue