stockholm/krebs/3modules/ci.nix

193 lines
5.4 KiB
Nix
Raw Normal View History

2017-07-27 17:45:45 +00:00
{ config, pkgs, ... }:
with import <stockholm/lib>;
let
cfg = config.krebs.ci;
hostname = config.networking.hostName;
in
{
options.krebs.ci = {
enable = mkEnableOption "krebs continous integration";
2017-08-09 16:14:04 +00:00
stockholmSrc = mkOption {
type = types.str;
default = "http://cgit.${hostname}.r/stockholm";
};
treeStableTimer = mkOption {
type = types.int;
default = 10;
description = "how long to wait until we test changes (in minutes)";
};
2017-08-31 17:01:53 +00:00
hosts = mkOption {
type = types.listOf types.host;
default = [];
description = ''
List of hosts that should be build
'';
2017-07-27 17:45:45 +00:00
};
2017-12-31 12:30:17 +00:00
tests = mkOption {
type = types.listOf types.str;
default = [];
description = ''
List of tests that should be build
'';
};
2017-07-27 17:45:45 +00:00
};
config = mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts.build = {
serverAliases = [ "build.${hostname}.r" ];
locations."/".extraConfig = ''
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:${toString config.krebs.buildbot.master.web.port};
'';
};
};
krebs.buildbot.master = {
slaves = {
testslave = "lasspass";
};
change_source.stockholm = ''
2017-08-09 16:14:04 +00:00
stockholm_repo = '${cfg.stockholmSrc}'
2017-07-27 17:45:45 +00:00
cs.append(
changes.GitPoller(
stockholm_repo,
workdir='stockholm-poller', branches=True,
project='stockholm',
pollinterval=10
)
)
'';
scheduler = {
build-scheduler = ''
sched.append(
schedulers.SingleBranchScheduler(
change_filter=util.ChangeFilter(branch_re=".*"),
treeStableTimer=${toString cfg.treeStableTimer}*60,
2017-07-27 17:45:45 +00:00
name="build-all-branches",
builderNames=[
2017-12-31 12:30:17 +00:00
${optionalString (cfg.hosts != []) ''"hosts",''}
${optionalString (cfg.tests != []) ''"tests",''}
2017-07-27 17:45:45 +00:00
]
)
)
'';
force-scheduler = ''
sched.append(
schedulers.ForceScheduler(
name="force",
builderNames=[
2017-12-31 12:30:17 +00:00
${optionalString (cfg.hosts != []) ''"hosts",''}
${optionalString (cfg.tests != []) ''"tests",''}
2017-07-27 17:45:45 +00:00
]
)
)
'';
};
builder_pre = ''
# prepare grab_repo step for stockholm
grab_repo = steps.Git(
repourl=stockholm_repo,
mode='full'
)
# prepare addShell function
def addShell(factory,**kwargs):
factory.addStep(steps.ShellCommand(**kwargs))
'';
builder = {
2017-12-31 12:30:17 +00:00
hosts = mkIf (cfg.hosts != []) ''
2017-07-27 17:45:45 +00:00
f = util.BuildFactory()
f.addStep(grab_repo)
def build_host(user, host):
addShell(f,
name="{}".format(host),
env={
"NIX_PATH": "secrets=/var/src/stockholm/null:/var/src",
"NIX_REMOTE": "daemon",
"dummy_secrets": "true",
},
command=[
2017-12-05 23:08:11 +00:00
"nix-shell", "-I", "stockholm=.", "--run", " ".join(["test",
2017-07-28 11:37:39 +00:00
"--user={}".format(user),
"--system={}".format(host),
"--force-populate",
"--target=$LOGNAME@${config.krebs.build.host.name}$HOME/{}".format(user),
])
2017-07-31 10:25:53 +00:00
],
timeout=90001
2017-07-27 17:45:45 +00:00
)
2017-08-31 17:01:53 +00:00
${concatMapStringsSep "\n" (host:
"build_host(\"${host.owner.name}\", \"${host.name}\")"
) cfg.hosts}
2017-07-27 17:45:45 +00:00
bu.append(
util.BuilderConfig(
2017-12-31 12:30:17 +00:00
name="hosts",
2017-07-27 17:45:45 +00:00
slavenames=slavenames,
factory=f
)
)
2017-12-31 12:30:17 +00:00
'';
tests = mkIf (cfg.tests != []) ''
f = util.BuildFactory()
f.addStep(grab_repo)
2017-07-27 17:45:45 +00:00
2017-12-31 12:30:17 +00:00
def run_test(test):
addShell(f,
name="{}".format(test),
env={
"NIX_PATH": "secrets=/var/src/stockholm/null:/var/src",
"NIX_REMOTE": "daemon",
"dummy_secrets": "true",
},
command=[
2018-05-09 09:11:50 +00:00
"nix-build", "-I", "stockholm=.", "krebs/0tests",
2017-12-31 12:30:17 +00:00
"-A", "{}".format(test)
],
timeout=90001
)
${concatMapStringsSep "\n" (test:
"run_test(\"${test}\")"
) cfg.tests}
bu.append(
util.BuilderConfig(
name="tests",
slavenames=slavenames,
factory=f
)
)
2017-07-27 17:45:45 +00:00
'';
};
enable = true;
web.enable = true;
irc = {
enable = true;
nick = "build|${hostname}";
2017-10-01 11:41:41 +00:00
server = "irc.r";
2017-10-01 12:26:12 +00:00
channels = [ "xxx" "noise" ];
2017-07-27 17:45:45 +00:00
allowForce = true;
};
extraConfig = ''
c['buildbotURL'] = "http://build.${hostname}.r/"
'';
};
krebs.buildbot.slave = {
enable = true;
masterhost = "localhost";
username = "testslave";
password = "lasspass";
packages = with pkgs; [ gnumake jq nix populate ];
};
};
}