Merge pull request #1 from Mic92/cleanups

Cleanups
This commit is contained in:
Jörg Thalheim 2023-09-15 09:13:55 +02:00 committed by GitHub
commit 50be0f5d92
Failed to generate hash of commit
5 changed files with 56 additions and 35 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

View file

@ -44,6 +44,7 @@ BUILDBOT_URL = os.environ["BUILDBOT_URL"]
BUILDBOT_GITHUB_USER = os.environ["BUILDBOT_GITHUB_USER"]
NIX_SUPPORTED_SYSTEMS = os.environ["NIX_SUPPORTED_SYSTEMS"].split(" ")
NIX_EVAL_MAX_MEMORY_SIZE = int(os.environ.get("NIX_EVAL_MAX_MEMORY_SIZE", "4096"))
BUILDBOT_DB_URL = os.environ.get("DB_URL", "sqlite:///state.sqlite")
def config_for_project(
@ -225,7 +226,7 @@ def build_config() -> dict[str, Any]:
),
}
c["db"] = {"db_url": os.environ.get("DB_URL", "sqlite:///state.sqlite")}
c["db"] = {"db_url": BUILDBOT_DB_URL}
c["protocols"] = {"pb": {"port": "tcp:9989:interface=\\:\\:"}}
c["buildbotURL"] = BUILDBOT_URL

View file

@ -3,6 +3,7 @@
import multiprocessing
import os
import socket
from dataclasses import dataclass
from pathlib import Path
from buildbot_worker.bot import Worker
@ -15,13 +16,20 @@ def require_env(key: str) -> str:
return val
PASSWD = Path(require_env("WORKER_PASSWORD_FILE")).read_text().strip("\r\n")
BUILDBOT_DIR = require_env("BUILDBOT_DIR")
MASTER_URL = require_env("MASTER_URL")
@dataclass
class WorkerConfig:
password: str = Path(require_env("WORKER_PASSWORD_FILE")).read_text().rstrip("\r\n")
worker_count: int = int(
os.environ.get("WORKER_COUNT", str(multiprocessing.cpu_count()))
)
buildbot_dir: str = require_env("BUILDBOT_DIR")
master_url: str = require_env("MASTER_URL")
def setup_worker(application: service.Application, id: int) -> None:
basedir = f"{BUILDBOT_DIR}-{id}"
def setup_worker(
application: service.Application, id: int, config: WorkerConfig
) -> None:
basedir = f"{config.buildbot_dir}-{id}"
os.makedirs(basedir, mode=0o700, exist_ok=True)
hostname = socket.gethostname()
@ -36,10 +44,10 @@ def setup_worker(application: service.Application, id: int) -> None:
None,
None,
workername,
PASSWD,
config.password,
basedir,
keepalive,
connection_string=MASTER_URL,
connection_string=config.master_url,
umask=umask,
maxdelay=maxdelay,
numcpus=numcpus,
@ -50,9 +58,12 @@ def setup_worker(application: service.Application, id: int) -> None:
s.setServiceParent(application)
def setup_workers(application: service.Application, config: WorkerConfig) -> None:
for i in range(config.worker_count):
setup_worker(application, i, config)
# note: this line is matched against to check that this is a worker
# directory; do not edit it.
application = service.Application("buildbot-worker")
for i in range(multiprocessing.cpu_count()):
setup_worker(application, i)
setup_workers(application, WorkerConfig())

View file

@ -1,4 +1,4 @@
{ nixpkgs, system, srvos, buildbot-nix, disko, ... }:
{ nixpkgs, system, buildbot-nix, ... }:
let
# some example configuration to make it eval
dummy = { config, modulesPath, ... }: {
@ -15,7 +15,7 @@ let
inherit (lib) nixosSystem;
in
{
example-master = nixosSystem {
"example-master-${system}" = nixosSystem {
inherit system;
modules = [
dummy
@ -44,7 +44,7 @@ in
buildbot-nix.nixosModules.buildbot-master
];
};
example-worker = nixosSystem {
"example-worker-${system}" = nixosSystem {
inherit system;
modules = [
dummy

View file

@ -9,28 +9,36 @@
};
outputs = inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
systems = [ "x86_64-linux" ];
flake = {
nixosModules.buildbot-master = ./nix/master.nix;
nixosModules.buildbot-worker = ./nix/worker.nix;
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }:
{
systems = [ "x86_64-linux" "aarch64-linux" ];
flake = {
nixosModules.buildbot-master = ./nix/master.nix;
nixosModules.buildbot-worker = ./nix/worker.nix;
nixosConfigurations = import ./examples {
inherit (inputs) nixpkgs srvos disko;
buildbot-nix = self;
system = "x86_64-linux";
nixosConfigurations =
let
examplesFor = system: import ./examples {
inherit system;
inherit (inputs) nixpkgs;
buildbot-nix = self;
};
in
examplesFor "x86_64-linux" // examplesFor "aarch64-linux";
};
checks.x86_64-linux = {
nixos-master = self.nixosConfigurations.example-master.config.system.build.toplevel;
nixos-worker = self.nixosConfigurations.example-worker.config.system.build.toplevel;
perSystem = { self', pkgs, system, ... }: {
packages.default = pkgs.mkShell {
packages = [
pkgs.bashInteractive
];
};
checks =
let
nixosMachines = lib.mapAttrs' (name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel) ((lib.filterAttrs (_: config: config.pkgs.system == system)) self.nixosConfigurations);
packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages;
devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells;
in
nixosMachines // packages // devShells;
};
};
perSystem = { pkgs, system, ... }: {
packages.default = pkgs.mkShell {
packages = [
pkgs.bashInteractive
];
};
};
});
});
}