Drone runner VM almost works

This commit is contained in:
Alex 2022-05-30 16:36:17 +02:00
parent d47d4e93ab
commit 4ec5cc43d4
Signed by untrusted user: lx
GPG key ID: 0E496D15096376BE
3 changed files with 32 additions and 5 deletions

View file

@ -12,7 +12,7 @@ with lib;
system.build.qcow2 = import <nixpkgs/nixos/lib/make-disk-image.nix> { system.build.qcow2 = import <nixpkgs/nixos/lib/make-disk-image.nix> {
inherit lib config; inherit lib config;
pkgs = import <nixpkgs> { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package pkgs = import <nixpkgs> { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
diskSize = 8192; diskSize = 32768;
format = "qcow2"; format = "qcow2";
configFile = pkgs.writeText "configuration.nix" configFile = pkgs.writeText "configuration.nix"
'' ''

View file

@ -14,11 +14,22 @@ with lib;
autoResize = true; autoResize = true;
}; };
fileSystems."/secrets" = {
device = "/dev/disk/by-label/QEMU\\x20VVFAT";
fsType = "vfat";
};
boot.growPartition = true; boot.growPartition = true;
boot.kernelParams = [ "console=ttyS0" ]; boot.kernelParams = [ "console=ttyS0" ];
boot.loader.grub.device = "/dev/vda"; boot.loader.grub.device = "/dev/vda";
boot.loader.timeout = 0; boot.loader.timeout = 0;
environment.systemPackages = with pkgs; [
iotop
jnettop
htop
];
users.extraUsers.root.openssh.authorizedKeys.keys = [ users.extraUsers.root.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJpaBZdYxHqMxhv2RExAOa7nkKhPBOHupMP3mYaZ73w9 lx@lindy" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJpaBZdYxHqMxhv2RExAOa7nkKhPBOHupMP3mYaZ73w9 lx@lindy"
]; ];
@ -31,11 +42,17 @@ with lib;
virtualisation.docker.enable = true; virtualisation.docker.enable = true;
virtualisation.oci-containers.backend = "docker"; virtualisation.oci-containers.backend = "docker";
systemd.user.services.drone_nix_setup = {
script = ''
docker run --rm -it -v /var/lib/drone/nix:/mnt nixpkgs/nix:nixos-21.05 cp -r /nix/{store,var} /mnt/
'';
wantedBy = [ "multi-user.target" ];
};
virtualisation.oci-containers.containers = { virtualisation.oci-containers.containers = {
drone_runner = { drone_runner = {
image = "drone/drone-runner-docker:1.4.0"; image = "drone/drone-runner-docker:1.4.0";
volumes = [ volumes = [
"/nix:/nix" "/var/lib/drone/nix:/nix"
"/var/run/docker.sock:/var/run/docker.sock" "/var/run/docker.sock:/var/run/docker.sock"
]; ];
environment = { environment = {
@ -49,7 +66,7 @@ with lib;
DRONE_RUNNER_LABELS = "nix:1"; DRONE_RUNNER_LABELS = "nix:1";
}; };
environmentFiles = [ environmentFiles = [
"/dev/qemu/dronesecret0" "/secrets/secret_env"
]; ];
}; };
drone_gc = { drone_gc = {

View file

@ -4,7 +4,15 @@ job "drone-runner" {
group "runner-vm" { group "runner-vm" {
network { network {
port "ssh" { } port "ssh" {
static = 22544
}
}
constraint {
attribute = "${attr.unique.hostname}"
operator = "="
value = "caribou"
} }
task "drone-runner-vm" { task "drone-runner-vm" {
@ -14,7 +22,9 @@ job "drone-runner" {
image_path = "local/drone-runner.qcow2" image_path = "local/drone-runner.qcow2"
accelerator = "kvm" accelerator = "kvm"
args = [ args = [
"-object", "secret,id=dronesecret0,file=secrets/secret_env" "-drive", "index=1,file=fat:rw:/var/lib/nomad/alloc/${NOMAD_ALLOC_ID}/${NOMAD_TASK_NAME}/secrets,format=raw,media=disk",
"-device", "e1000,netdev=user.0",
"-netdev", "user,id=user.0,hostfwd=tcp::${NOMAD_PORT_ssh}-:22",
] ]
port_map { port_map {
ssh = 22 ssh = 22