Compare commits
2 Commits
8d187d1ef0
...
ebea10d242
Author | SHA1 | Date |
---|---|---|
Julien Malka | ebea10d242 | 1 year ago |
Julien Malka | c208537f49 | 1 year ago |
@ -0,0 +1,57 @@
|
||||
{ lib, pkgs, config, ... }:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.luj.buildbot;
|
||||
port = "1810";
|
||||
package = pkgs.buildbot-worker;
|
||||
python = package.pythonModule;
|
||||
home = "/var/lib/buildbot-worker";
|
||||
buildbotDir = "${home}/worker";
|
||||
in
|
||||
{
|
||||
#buildbot worker
|
||||
|
||||
nix.settings.allowed-users = [ "buildbot-worker" ];
|
||||
users.users.buildbot-worker = {
|
||||
description = "Buildbot Worker User.";
|
||||
isSystemUser = true;
|
||||
createHome = true;
|
||||
home = "/var/lib/buildbot-worker";
|
||||
group = "buildbot-worker";
|
||||
useDefaultShell = true;
|
||||
};
|
||||
users.groups.buildbot-worker = { };
|
||||
|
||||
systemd.services.buildbot-worker = {
|
||||
reloadIfChanged = true;
|
||||
description = "Buildbot Worker.";
|
||||
after = [ "network.target" "buildbot-master.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
path = [
|
||||
pkgs.nix-eval-jobs
|
||||
pkgs.git
|
||||
pkgs.gh
|
||||
pkgs.nix
|
||||
pkgs.nix-output-monitor
|
||||
];
|
||||
environment.PYTHONPATH = "${python.withPackages (_: [package])}/${python.sitePackages}";
|
||||
environment.MASTER_URL = ''TCP:2a01\\:e34\\:ec2a\\:8e60\\:8ec7\\:b5d2\\:f663\\:a67a:9989'';
|
||||
environment.BUILDBOT_DIR = buildbotDir;
|
||||
environment.WORKER_PASSWORD_FILE = "/var/lib/buildbot-worker/password.txt";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = "buildbot-worker";
|
||||
Group = "buildbot-worker";
|
||||
WorkingDirectory = home;
|
||||
|
||||
# Restart buildbot with a delay. This time way we can use buildbot to deploy itself.
|
||||
ExecReload = "+${pkgs.systemd}/bin/systemd-run --on-active=60 ${pkgs.systemd}/bin/systemctl restart buildbot-worker";
|
||||
ExecStart = "${python.pkgs.twisted}/bin/twistd --nodaemon --pidfile= --logfile - --python ${./worker.py}";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import multiprocessing
|
||||
import os
|
||||
import socket
|
||||
from io import open
|
||||
|
||||
from buildbot_worker.bot import Worker
|
||||
from twisted.application import service
|
||||
|
||||
|
||||
def require_env(key: str) -> str:
|
||||
val = os.environ.get(key)
|
||||
assert val is not None, "val is not set"
|
||||
return val
|
||||
|
||||
|
||||
def setup_worker(application: service.Application, id: int) -> None:
|
||||
basedir = f"{require_env('BUILDBOT_DIR')}-{id}"
|
||||
os.makedirs(basedir, mode=0o700, exist_ok=True)
|
||||
|
||||
master_url = require_env("MASTER_URL")
|
||||
hostname = socket.gethostname()
|
||||
workername = f"{hostname}-{id}"
|
||||
|
||||
with open(
|
||||
require_env("WORKER_PASSWORD_FILE"), "r", encoding="utf-8"
|
||||
) as passwd_file:
|
||||
passwd = passwd_file.read().strip("\r\n")
|
||||
keepalive = 600
|
||||
umask = None
|
||||
maxdelay = 300
|
||||
numcpus = None
|
||||
allow_shutdown = None
|
||||
|
||||
s = Worker(
|
||||
"2a01:e34:ec2a:8e60:8ec7:b5d2:f663:a67a",
|
||||
9989,
|
||||
workername,
|
||||
passwd,
|
||||
basedir,
|
||||
keepalive,
|
||||
umask=umask,
|
||||
maxdelay=maxdelay,
|
||||
numcpus=numcpus,
|
||||
allow_shutdown=allow_shutdown,
|
||||
)
|
||||
s.setServiceParent(application)
|
||||
|
||||
|
||||
# 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(14):
|
||||
setup_worker(application, i)
|
||||
|
||||
|
Reference in New Issue