From 0b229a771e846893e759cd4102172e60a541d439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sat, 13 Aug 2022 20:38:41 +0200 Subject: [PATCH 1/5] Barebones ci-runner module This adds a barebones CI-runner module with the following option: `pub-solar.ci-runner.enable` If enabled, this will start a systemd service on boot that runs `drone-runner-exec`. The configuration expects you to have a file called `secrets/drone-runner-exec-config` handled by agenix that gets put into `/run/agenix/drone-runner-exec-config` and is owned by root. This file should contain a configuration similar to the following: ``` CLIENT_DRONE_RPC_PROTO=https CLIENT_DRONE_RPC_HOST=drone.company.com CLIENT_DRONE_RPC_SECRET=super-duper-secret ``` --- modules/ci-runner/default.nix | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules/ci-runner/default.nix diff --git a/modules/ci-runner/default.nix b/modules/ci-runner/default.nix new file mode 100644 index 00000000..28325b14 --- /dev/null +++ b/modules/ci-runner/default.nix @@ -0,0 +1,35 @@ +{ lib, config, pkgs, self, ... }: +with lib; +let + psCfg = config.pub-solar; + cfg = config.pub-solar.ci-runner; +in +{ + options.pub-solar.ci-runner = { + enable = mkEnableOption "Enables a systemd service that runs drone-ci-runner"; + }; + + config = mkIf cfg.enable { + systemd.services.ci-runner = { + enable = true; + + description = "CI runner for the PubSolarOS repository that can run test VM instances with KVM."; + + serviceConfig = { + Type = "simple"; + Restart = "always"; + }; + + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" "libvirtd.service" ]; + + script = ''${pkgs.drone-runner-exec}/bin/drone-runner-exec daemon /run/agenix/drone-runner-exec-config''; + }; + + age.secrets."drone-runner-exec-config" = { + file = "${self}/secrets/drone-runner-exec-config"; + mode = "700"; + owner = "root"; + }; + }; +} From e3d76f1999d0512cc4f8f4e8032858000665c3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sat, 13 Aug 2022 22:31:30 +0200 Subject: [PATCH 2/5] Move ci-runner to user and add git, virsh and nix to path --- modules/ci-runner/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ci-runner/default.nix b/modules/ci-runner/default.nix index 28325b14..4db42286 100644 --- a/modules/ci-runner/default.nix +++ b/modules/ci-runner/default.nix @@ -10,7 +10,7 @@ in }; config = mkIf cfg.enable { - systemd.services.ci-runner = { + systemd.user.services.ci-runner = { enable = true; description = "CI runner for the PubSolarOS repository that can run test VM instances with KVM."; @@ -20,6 +20,8 @@ in Restart = "always"; }; + path = "${pkgs.git}/bin:${pkgs.nix}/bin:${pkgs.libvirt}/bin"; + wantedBy = [ "multi-user.target" ]; after = [ "network.target" "libvirtd.service" ]; @@ -29,7 +31,7 @@ in age.secrets."drone-runner-exec-config" = { file = "${self}/secrets/drone-runner-exec-config"; mode = "700"; - owner = "root"; + owner = psCfg.user.name; }; }; } From c5362c045313d983bd571ef4dd6fd5d48d53f31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 20:24:50 +0200 Subject: [PATCH 3/5] Fix path in drone runner exec --- modules/ci-runner/default.nix | 6 +++++- pkgs/drone-docker-runner.nix | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/ci-runner/default.nix b/modules/ci-runner/default.nix index 4db42286..1460ab16 100644 --- a/modules/ci-runner/default.nix +++ b/modules/ci-runner/default.nix @@ -20,7 +20,11 @@ in Restart = "always"; }; - path = "${pkgs.git}/bin:${pkgs.nix}/bin:${pkgs.libvirt}/bin"; + path = [ + pkgs.git + pkgs.nix + pkgs.libvirt + ]; wantedBy = [ "multi-user.target" ]; after = [ "network.target" "libvirtd.service" ]; diff --git a/pkgs/drone-docker-runner.nix b/pkgs/drone-docker-runner.nix index 7d098536..e1773d5a 100644 --- a/pkgs/drone-docker-runner.nix +++ b/pkgs/drone-docker-runner.nix @@ -6,7 +6,7 @@ self: with self; '' --env=DRONE_RPC_PROTO=$DRONE_RPC_PROTO \ --env=DRONE_RPC_HOST=$DRONE_RPC_HOST \ --env=DRONE_RPC_SECRET=$(${self.libsecret}/bin/secret-tool lookup drone rpc-secret) \ - --env=DRONE_RUNNER_CAPACITY=4 \ + --env=DRONE_RUNNER_CAPACITY=8 \ --env=DRONE_RUNNER_NAME=$(${self.inetutils}/bin/hostname) \ --publish=3000:3000 \ --restart=always \ From 14ba7010615ddd723474bb5844ff686f42bfaabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 20:28:18 +0200 Subject: [PATCH 4/5] Don't use libvirt in ci-runner --- modules/ci-runner/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ci-runner/default.nix b/modules/ci-runner/default.nix index 1460ab16..0e78e55e 100644 --- a/modules/ci-runner/default.nix +++ b/modules/ci-runner/default.nix @@ -23,11 +23,10 @@ in path = [ pkgs.git pkgs.nix - pkgs.libvirt ]; wantedBy = [ "multi-user.target" ]; - after = [ "network.target" "libvirtd.service" ]; + after = [ "network.target" ]; script = ''${pkgs.drone-runner-exec}/bin/drone-runner-exec daemon /run/agenix/drone-runner-exec-config''; }; From 8fc8ac2d586735b6a697c950b6536746ac1e73e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Thu, 25 Aug 2022 15:25:34 +0200 Subject: [PATCH 5/5] Fix service startup for ci-runner --- modules/ci-runner/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ci-runner/default.nix b/modules/ci-runner/default.nix index 0e78e55e..1460ab16 100644 --- a/modules/ci-runner/default.nix +++ b/modules/ci-runner/default.nix @@ -23,10 +23,11 @@ in path = [ pkgs.git pkgs.nix + pkgs.libvirt ]; wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; + after = [ "network.target" "libvirtd.service" ]; script = ''${pkgs.drone-runner-exec}/bin/drone-runner-exec daemon /run/agenix/drone-runner-exec-config''; };