Deploy garage on staging using nix2 driver

This commit is contained in:
Alex 2022-11-29 14:21:12 +01:00
parent 105c081728
commit c9f9ed4c71
Signed by untrusted user: lx
GPG key ID: 0E496D15096376BE
5 changed files with 41 additions and 55 deletions

View file

@ -57,22 +57,21 @@ job "garage-staging" {
# } # }
task "server" { task "server" {
driver = "exec2" driver = "nix2"
config { config {
#command = "/usr/bin/env" packages = [
command = "/run/current-system/sw/bin/nix" "bash", # so that we can enter a shell inside container
args = [
"run",
"git+https://git.deuxfleurs.fr/Deuxfleurs/garage.git?ref=nix-remove-system&rev=60c26fbc628d7b450ae39214b578ab6a30583d5c", "git+https://git.deuxfleurs.fr/Deuxfleurs/garage.git?ref=nix-remove-system&rev=60c26fbc628d7b450ae39214b578ab6a30583d5c",
"--",
"server"
] ]
command = "garage"
args = [ "server" ]
bind = { bind = {
"/mnt/storage/garage-staging/data" = "/data", "/mnt/storage/garage-staging/data" = "/data",
"/mnt/ssd/garage-staging/meta" = "/meta", "/mnt/ssd/garage-staging/meta" = "/meta",
} }
} }
user = "root"
template { template {
data = file("../config/garage.toml") data = file("../config/garage.toml")

View file

@ -77,16 +77,16 @@
## EXPERIMENTAL ON STAGING: NIX NOMAD JOBS ## EXPERIMENTAL ON STAGING: NIX NOMAD JOBS
services.nomad.dropPrivileges = false; services.nomad.dropPrivileges = false;
# ----- nomad-driver-nix & nomad-driver-exec2 ----- # ----- nomad-driver-nix & nomad-driver-nix2 -----
services.nomad.extraSettingsPlugins = services.nomad.extraSettingsPlugins =
let nomad_driver_nix = import ./nomad-driver-nix.nix { inherit pkgs; }; let nomad_driver_nix = import ./nomad-driver-nix.nix { inherit pkgs; };
nomad_driver_exec2 = import ./nomad-driver-exec2.nix { inherit pkgs; }; nomad_driver_nix2 = import ./nomad-driver-nix2.nix { inherit pkgs; };
in [ in [
(pkgs.symlinkJoin { (pkgs.symlinkJoin {
name = "nomad-drivers"; name = "nomad-drivers";
paths = [ paths = [
nomad_driver_nix nomad_driver_nix
nomad_driver_exec2 nomad_driver_nix2
]; ];
}) })
]; ];
@ -99,22 +99,11 @@
# default config for the exec2 driver # default config for the exec2 driver
services.nomad.settings.plugin = [ services.nomad.settings.plugin = [
{ {
"exec2-driver" = [ "nix2-driver" = [
{ {
config = [ config = [
{ {
bind_read_only = { # default_nixpkgs = "github:nixos/nixpkgs/nixos-22.11";
"/etc/static" = "/etc/static";
"/etc/passwd" = "/etc/passwd";
"/etc/resolv.conf" = "/etc/resolv.conf";
"/etc/nix/nix.conf" = "/etc/nix/nix.conf";
"/etc/ssl" = "/etc/ssl";
"/etc/nsswitch.conf" = "/etc/nsswitch.conf";
"/nix" = "/nix";
"/bin" = "/bin";
"/usr" = "/usr";
"/run/current-system/sw" = "/run/current-system/sw";
};
} }
]; ];
} }

View file

@ -9,7 +9,7 @@ copy cluster/$CLUSTER/node/$NIXHOST.site.nix /etc/nixos/site.nix
if [ "$CLUSTER" = "staging" ]; then if [ "$CLUSTER" = "staging" ]; then
copy nix/nomad-driver-nix.nix /etc/nixos/nomad-driver-nix.nix copy nix/nomad-driver-nix.nix /etc/nixos/nomad-driver-nix.nix
copy nix/nomad-driver-exec2.nix /etc/nixos/nomad-driver-exec2.nix copy nix/nomad-driver-nix2.nix /etc/nixos/nomad-driver-nix2.nix
fi fi
# use ./upgrade_nixos instead to upgrade NixOS # use ./upgrade_nixos instead to upgrade NixOS

View file

@ -1,31 +0,0 @@
{
pkgs ? import <nixpkgs> {}
}:
pkgs.buildGoModule rec {
pname = "nomad-driver-exec2";
version = "0.1.0";
src = pkgs.fetchFromGitHub {
owner = "Alexis211";
repo = "nomad-driver-exec2";
rev = "14bd8f2010c3a1f90c6d1297f47ebbf46ee87dde";
sha256 = "sha256-k75VEi2+9mS9v3bx/ygumy0niQP7bLWIgB0Zwhuky+k=";
};
vendorSha256 = "sha256-EQdTxVOBRYQjg7kAB+pFJYcNwk0zlsjjJxM+EO/cK84=";
ldflags = [
"-X github.com/Alexis211/nomad-driver-exec2/exec2.pluginVersion=${version}"
];
postInstall = ''
mv $out/bin/nomad-driver-exec2 $out/bin/exec2-driver
'';
meta = with pkgs.lib; {
description = "Nomad exec driver with support for bind mouns";
homepage = "https://github.com/Alexis211/nomad-driver-exec2";
license = licenses.mpl20;
platforms = platforms.linux;
};
}

29
nix/nomad-driver-nix2.nix Normal file
View file

@ -0,0 +1,29 @@
{
pkgs ? import <nixpkgs> {}
}:
pkgs.buildGoModule rec {
pname = "nomad-driver-nix2";
version = "0.1.0";
src = builtins.fetchGit {
url = "https://git.deuxfleurs.fr/lx/nomad-driver-nix2";
rev = "d13a77952cd6404fa535b3863fca0a5bf8501af5";
};
vendorSha256 = "sha256-EQdTxVOBRYQjg7kAB+pFJYcNwk0zlsjjJxM+EO/cK84=";
ldflags = [
"-X git.deuxfleurs.fr/lx/nomad-driver-nix2/nix2.pluginVersion=${version}"
];
postInstall = ''
mv $out/bin/nomad-driver-nix2 $out/bin/nix2
'';
meta = with pkgs.lib; {
description = "Nomad driver to run Nix jobs";
homepage = "https://git.deuxfleurs.fr/lx/nomad-driver-nix2";
license = licenses.mpl20;
platforms = platforms.linux;
};
}