ci-runner experiment

This commit is contained in:
Hendrik Sokolowski 2022-10-30 21:32:53 +01:00
parent 5e836f6f31
commit 1cec43be02
Signed by: hensoko
GPG key ID: 5C36A01B80BCCC59

View file

@ -1,8 +1,15 @@
{ lib, config, pkgs, self, ... }: { lib, config, pkgs, self, dockerTools, ... }:
with lib; with lib;
let let
bootstrap = pkgs.writeScript "bootstrap.sh" '' runnerImageName = "ci-runner-docker-drone-exec";
runnerImage = dockerTools.buildImage {
name = runnerImageName;
tag = "latest";
fromImageName = "debian";
runAsRoot = ''
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
@ -10,7 +17,7 @@ let
apt update apt update
apt install --yes curl git sudo xz-utils apt install --yes curl git sudo xz-utils
adduser --system --uid 999 build adduser --system --uid 9999 build
chown build /nix chown build /nix
sudo -u build curl -L https://nixos.org/nix/install > install sudo -u build curl -L https://nixos.org/nix/install > install
@ -28,6 +35,11 @@ let
curl -L https://github.com/drone-runners/drone-runner-exec/releases/latest/download/drone_runner_exec_linux_amd64.tar.gz | tar xz curl -L https://github.com/drone-runners/drone-runner-exec/releases/latest/download/drone_runner_exec_linux_amd64.tar.gz | tar xz
sudo install -t /usr/local/bin drone-runner-exec sudo install -t /usr/local/bin drone-runner-exec
'';
};
startup = pkgs.writeScript "startup.sh" ''
chown build /nix
if [ ! -f /run/vars ]; then if [ ! -f /run/vars ]; then
exit 1 exit 1
@ -38,6 +50,7 @@ let
su - -s /bin/bash build sh -c "/usr/local/bin/drone-runner-exec daemon /run/runtime-vars" su - -s /bin/bash build sh -c "/usr/local/bin/drone-runner-exec daemon /run/runtime-vars"
''; '';
psCfg = config.pub-solar; psCfg = config.pub-solar;
cfg = config.pub-solar.ci-runner; cfg = config.pub-solar.ci-runner;
in in
@ -62,7 +75,7 @@ in
runnerEnvironment = lib.mkOption { runnerEnvironment = lib.mkOption {
description = '' description = ''
Additional environment vars added to the vars file on container runtime Additional environment variables added to the vars file on container runtime
''; '';
default = {}; default = {};
}; };
@ -84,15 +97,16 @@ in
oci-containers = { oci-containers = {
backend = "docker"; backend = "docker";
containers."drone-exec-runner" = { containers."drone-exec-runner" = {
image = "debian"; image = runnerImageName;
imageFile = runnerImage;
autoStart = true; autoStart = true;
entrypoint = "bash"; entrypoint = "bash";
cmd = [ "/bootstrap.sh" ]; cmd = [ "/startup.sh" ];
volumes = [ volumes = [
"${cfg.runnerVarsFile}:/run/vars" "${cfg.runnerVarsFile}:/run/vars"
"${cfg.nixCacheLocation}:/nix" "${cfg.nixCacheLocation}:/nix"
"${bootstrap}:/bootstrap.sh" "${startup}:/startup.sh"
]; ];
environment = cfg.runnerEnvironment; environment = cfg.runnerEnvironment;