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"] BUILDBOT_GITHUB_USER = os.environ["BUILDBOT_GITHUB_USER"]
NIX_SUPPORTED_SYSTEMS = os.environ["NIX_SUPPORTED_SYSTEMS"].split(" ") NIX_SUPPORTED_SYSTEMS = os.environ["NIX_SUPPORTED_SYSTEMS"].split(" ")
NIX_EVAL_MAX_MEMORY_SIZE = int(os.environ.get("NIX_EVAL_MAX_MEMORY_SIZE", "4096")) 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( 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["protocols"] = {"pb": {"port": "tcp:9989:interface=\\:\\:"}}
c["buildbotURL"] = BUILDBOT_URL c["buildbotURL"] = BUILDBOT_URL

View file

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

View file

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

View file

@ -9,28 +9,36 @@
}; };
outputs = inputs@{ self, flake-parts, ... }: outputs = inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: { flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }:
systems = [ "x86_64-linux" ]; {
flake = { systems = [ "x86_64-linux" "aarch64-linux" ];
nixosModules.buildbot-master = ./nix/master.nix; flake = {
nixosModules.buildbot-worker = ./nix/worker.nix; nixosModules.buildbot-master = ./nix/master.nix;
nixosModules.buildbot-worker = ./nix/worker.nix;
nixosConfigurations = import ./examples { nixosConfigurations =
inherit (inputs) nixpkgs srvos disko; let
buildbot-nix = self; examplesFor = system: import ./examples {
system = "x86_64-linux"; inherit system;
inherit (inputs) nixpkgs;
buildbot-nix = self;
};
in
examplesFor "x86_64-linux" // examplesFor "aarch64-linux";
}; };
checks.x86_64-linux = { perSystem = { self', pkgs, system, ... }: {
nixos-master = self.nixosConfigurations.example-master.config.system.build.toplevel; packages.default = pkgs.mkShell {
nixos-worker = self.nixosConfigurations.example-worker.config.system.build.toplevel; 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
];
};
};
});
} }