randomly pick a builder and pass it as --store
This commit is contained in:
parent
9bbadeb1e6
commit
ae574a5529
|
@ -4,6 +4,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import graphlib
|
import graphlib
|
||||||
import base64
|
import base64
|
||||||
|
import random
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -62,13 +63,20 @@ class NixBuilder:
|
||||||
supportedFeatures: list[str] = field(default_factory=lambda: [])
|
supportedFeatures: list[str] = field(default_factory=lambda: [])
|
||||||
mandatoryFeatures: list[str] = field(default_factory=lambda: [])
|
mandatoryFeatures: list[str] = field(default_factory=lambda: [])
|
||||||
|
|
||||||
def to_nix_line(self):
|
def to_nix_store(self):
|
||||||
systems = ["-"] if not self.systems else self.systems
|
fullConnection = f"{self.sshUser}@{self.hostName}" if self.sshUser is not None else self.hostName
|
||||||
supportedFeatures = ["-"] if not self.supportedFeatures else self.supportedFeatures
|
fullConnection = f"{self.protocol}://{fullConnection}"
|
||||||
mandatoryFeatures = ["-"] if not self.mandatoryFeatures else self.mandatoryFeatures
|
params = []
|
||||||
encoded_public_key = base64.b64encode(self.publicHostKey.encode('ascii')).decode('ascii') if self.publicHostKey is not None else "-"
|
if self.sshKey is not None:
|
||||||
fullConnection = f"{self.protocol}://{self.sshUser}@{self.hostName}" if self.sshUser is not None else self.hostName
|
params.append(f"ssh-key={self.sshKey}")
|
||||||
return f"{fullConnection} {",".join(systems)} {self.sshKey or "-"} {self.maxJobs} {self.speedFactor} {",".join(supportedFeatures)} {",".join(mandatoryFeatures)} {encoded_public_key}"
|
if self.publicHostKey is not None:
|
||||||
|
encoded_public_key = base64.b64encode(self.publicHostKey.encode('ascii')).decode('ascii')
|
||||||
|
params.append(f"base64-ssh-public-host-key={encoded_public_key}")
|
||||||
|
if params != []:
|
||||||
|
fullConnection += "?"
|
||||||
|
fullConnection += "&".join(params)
|
||||||
|
|
||||||
|
return fullConnection
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -655,25 +663,16 @@ def nix_build_config(
|
||||||
project: GerritProject,
|
project: GerritProject,
|
||||||
worker_arch: str,
|
worker_arch: str,
|
||||||
worker_names: list[str],
|
worker_names: list[str],
|
||||||
builders_spec: str,
|
build_stores: list[str],
|
||||||
signing_keyfile: str | None = None,
|
signing_keyfile: str | None = None,
|
||||||
binary_cache_config: S3BinaryCacheConfig | None = None
|
binary_cache_config: S3BinaryCacheConfig | None = None
|
||||||
) -> util.BuilderConfig:
|
) -> util.BuilderConfig:
|
||||||
"""Builds one nix flake attribute."""
|
"""Builds one nix flake attribute."""
|
||||||
factory = util.BuildFactory()
|
factory = util.BuildFactory()
|
||||||
factory.addStep(
|
|
||||||
steps.ShellCommand(
|
# pick a store to run the build on
|
||||||
name="Copy the derivation to the local worker store",
|
# TODO proper scheduling instead of picking the first builder
|
||||||
command=[
|
build_store = build_stores[0]
|
||||||
"nix",
|
|
||||||
"copy",
|
|
||||||
"--derivation",
|
|
||||||
"--to",
|
|
||||||
"../store",
|
|
||||||
util.Interpolate("%(prop:drv_path)s^*")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
factory.addStep(
|
factory.addStep(
|
||||||
NixBuildCommand(
|
NixBuildCommand(
|
||||||
|
@ -697,7 +696,9 @@ def nix_build_config(
|
||||||
"--builders",
|
"--builders",
|
||||||
builders_spec,
|
builders_spec,
|
||||||
"--store",
|
"--store",
|
||||||
util.Interpolate("%(prop:builddir)s/store"),
|
build_store,
|
||||||
|
"--eval-store",
|
||||||
|
"ssh-ng://localhost",
|
||||||
"--out-link",
|
"--out-link",
|
||||||
util.Interpolate("result-%(prop:attr)s"),
|
util.Interpolate("result-%(prop:attr)s"),
|
||||||
util.Interpolate("%(prop:drv_path)s^*"),
|
util.Interpolate("%(prop:drv_path)s^*"),
|
||||||
|
@ -718,7 +719,7 @@ def nix_build_config(
|
||||||
"store",
|
"store",
|
||||||
"sign",
|
"sign",
|
||||||
"--store",
|
"--store",
|
||||||
util.Interpolate("%(prop:builddir)s/store"),
|
build_store,
|
||||||
"--key-file",
|
"--key-file",
|
||||||
signing_keyfile,
|
signing_keyfile,
|
||||||
util.Interpolate(
|
util.Interpolate(
|
||||||
|
@ -735,6 +736,8 @@ def nix_build_config(
|
||||||
command=[
|
command=[
|
||||||
"nix",
|
"nix",
|
||||||
"copy",
|
"copy",
|
||||||
|
"--store",
|
||||||
|
build_store,
|
||||||
"--to",
|
"--to",
|
||||||
f"s3://{binary_cache_config.bucket}?profile={binary_cache_config.profile}®ion={binary_cache_config.region}&endpoint={binary_cache_config.endpoint}",
|
f"s3://{binary_cache_config.bucket}?profile={binary_cache_config.profile}®ion={binary_cache_config.region}&endpoint={binary_cache_config.endpoint}",
|
||||||
util.Property(
|
util.Property(
|
||||||
|
@ -796,7 +799,7 @@ def config_for_project(
|
||||||
nix_eval_worker_count: int,
|
nix_eval_worker_count: int,
|
||||||
nix_eval_max_memory_size: int,
|
nix_eval_max_memory_size: int,
|
||||||
eval_lock: util.MasterLock,
|
eval_lock: util.MasterLock,
|
||||||
builders_spec: str,
|
nix_builders: list[NixBuilder],
|
||||||
signing_keyfile: str | None = None,
|
signing_keyfile: str | None = None,
|
||||||
binary_cache_config: S3BinaryCacheConfig | None = None
|
binary_cache_config: S3BinaryCacheConfig | None = None
|
||||||
) -> Project:
|
) -> Project:
|
||||||
|
@ -853,7 +856,7 @@ def config_for_project(
|
||||||
project,
|
project,
|
||||||
arch,
|
arch,
|
||||||
[ f"{w}-{arch}" for w in worker_names ],
|
[ f"{w}-{arch}" for w in worker_names ],
|
||||||
builders_spec,
|
[b.to_nix_store() for b in nix_builders if arch in b.systems or arch == "other"],
|
||||||
signing_keyfile=signing_keyfile,
|
signing_keyfile=signing_keyfile,
|
||||||
binary_cache_config=binary_cache_config
|
binary_cache_config=binary_cache_config
|
||||||
)
|
)
|
||||||
|
@ -994,7 +997,6 @@ class GerritNixConfigurator(ConfiguratorBase):
|
||||||
|
|
||||||
eval_lock = util.MasterLock("nix-eval")
|
eval_lock = util.MasterLock("nix-eval")
|
||||||
|
|
||||||
builders_spec = " ; ".join(builder.to_nix_line() for builder in self.nix_builders)
|
|
||||||
for project in self.projects:
|
for project in self.projects:
|
||||||
config_for_project(
|
config_for_project(
|
||||||
config,
|
config,
|
||||||
|
@ -1005,7 +1007,7 @@ class GerritNixConfigurator(ConfiguratorBase):
|
||||||
self.nix_eval_worker_count or multiprocessing.cpu_count(),
|
self.nix_eval_worker_count or multiprocessing.cpu_count(),
|
||||||
self.nix_eval_max_memory_size,
|
self.nix_eval_max_memory_size,
|
||||||
eval_lock,
|
eval_lock,
|
||||||
builders_spec,
|
self.nix_builders,
|
||||||
signing_keyfile=self.signing_keyfile,
|
signing_keyfile=self.signing_keyfile,
|
||||||
binary_cache_config=self.binary_cache_config
|
binary_cache_config=self.binary_cache_config
|
||||||
)
|
)
|
||||||
|
|
|
@ -62,6 +62,7 @@ in
|
||||||
pkgs.openssh
|
pkgs.openssh
|
||||||
pkgs.nix
|
pkgs.nix
|
||||||
pkgs.nix-eval-jobs
|
pkgs.nix-eval-jobs
|
||||||
|
pkgs.bash
|
||||||
];
|
];
|
||||||
environment.PYTHONPATH = "${python.withPackages (_: [cfg.package])}/${python.sitePackages}";
|
environment.PYTHONPATH = "${python.withPackages (_: [cfg.package])}/${python.sitePackages}";
|
||||||
environment.MASTER_URL = cfg.coordinatorUrl;
|
environment.MASTER_URL = cfg.coordinatorUrl;
|
||||||
|
|
Loading…
Reference in a new issue