Skip to content

Commit

Permalink
SQUASH: proper cleanup of Nomad agents
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Feb 8, 2023
1 parent 78306ba commit dc63f58
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 226 deletions.
139 changes: 63 additions & 76 deletions nix/workbench/backend/nomad.nix
@@ -1,5 +1,6 @@
{ pkgs
, lib
# TODO: Fetch this from config services inside materialise-profile !
, eventlogged ? true
# The exec driver uses SRE's plugin that allows Nix derivation artifacts!
, execTaskDriver
Expand All @@ -15,82 +16,68 @@ let
# Unlike the supervisor backend `useCabalRun` is always false here.
useCabalRun = false;

extraShellPkgs =
let
# The version of Nomad and the needed plugins are built here instead of
# being defined in the flake!
nomad = (pkgs.buildGo119Module rec {
pname = "nomad";
version = "1.4.3"; # Both are using 1.4.3
subPackages = [ "." ];
doCheck = true;
# If we are going to use the `exec` driver we use the SRE patched
# version of Nomad that allows to use `nix_installables` as artifacts.
src =
if execTaskDriver
then (pkgs.fetchFromGitHub
# "github:input-output-hk/nomad/release/1.4.3"
{
owner = "input-output-hk";
repo = pname;
# $ nomad --version
# Nomad v1.4.4-dev
rev = "release/${version}";
# nix-prefetch-url --unpack https://github.com/input-output-hk/nomad/archive/release/1.4.3.tar.gz
sha256 = "0z4bdx0nx6460q9r032l8ghx337h3fpi6cx8wh7i3qllpyi51a2k";
}
)
else (pkgs.fetchFromGitHub
{
owner = "hashicorp";
repo = pname;
rev = "v${version}";
# nix-prefetch-url --unpack https://github.com/hashicorp/nomad/archive/v1.4.3.tar.gz
sha256 = "0j2ik501sg6diyabwwfrqnz1wxx485w5pxry4bfkg5smgyp5y18r";
}
)
;
# error: either `vendorHash` or `vendorSha256` is required
# https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317
vendorSha256 = "sha256-JQRpsQhq5r/QcgFwtnptmvnjBEhdCFrXFrTKkJioL3A=";
});
# The plugin is defined but only used if `execTaskDriver` is true.
nomad-driver-podman = (pkgs.buildGo119Module rec {
pname = "nomad-driver-podman";
version = "0.4.1";
subPackages = [ "." ];
doCheck = false; # some tests require a running podman service to pass
src = pkgs.fetchFromGitHub {
owner = "hashicorp";
repo = pname;
rev = "v${version}";
# nix-prefetch-url --unpack https://github.com/hashicorp/nomad-driver-podman/archive/v0.4.1.tar.gz
sha256 = "03856ws02xkqg5374x35zzz5900456rvpsridsjgwvvyqnysn9ls";
};
# error: either `vendorHash` or `vendorSha256` is required
# https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317
vendorSha256 = "sha256-AtgxHAkNzzjMQoSqROpuNoSDum/6JR+mLpcHLFL9EIY=";
});
in
[ nomad ]
++
(lib.optional (!execTaskDriver)
[
# https://docs.podman.io/en/latest/markdown/podman.1.html#rootless-mode
# cni cni-plugins # slirp4netns is already included with `podman`
# Was not needed even thou it says so!
# https://docs.podman.io/en/latest/markdown/podman.1.html#note-unsupported-file-systems-in-rootless-mode
# fuse-overlayfs
nomad-driver-podman
# https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md
(with pkgs; [ podman ])
]
)
++
(lib.optional (execTaskDriver)
[ pkgs.webfs ]
)
;
extraShellPkgs = let
# The version of Nomad and the needed plugins are built here instead of
# being defined in the flake!
nomad = (pkgs.buildGo119Module rec {
pname = "nomad";
version = "1.4.3"; # Both Nomad versions are using 1.4.3
subPackages = [ "." ];
doCheck = true;
src = pkgs.fetchFromGitHub {
owner = "hashicorp";
repo = pname;
rev = "v${version}";
# nix-prefetch-url --unpack https://github.com/hashicorp/nomad/archive/v1.4.3.tar.gz
sha256 = "0j2ik501sg6diyabwwfrqnz1wxx485w5pxry4bfkg5smgyp5y18r";
};
# error: either `vendorHash` or `vendorSha256` is required
# https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317
vendorSha256 = "sha256-JQRpsQhq5r/QcgFwtnptmvnjBEhdCFrXFrTKkJioL3A=";
});
# The version of Nomad and the needed plugins are built here instead of
# being defined in the flake!
# Both Nomad versions are using 1.4.3 but `nomad --version` returns:
# "Nomad v1.4.4-dev"
nomad-sre = (pkgs.buildGo119Module rec {
pname = "nomad";
version = "1.4.3";
subPackages = [ "." ];
doCheck = true;
src = pkgs.fetchFromGitHub { # "github:input-output-hk/nomad/release/1.4.3"
owner = "input-output-hk";
repo = pname;
rev = "release/${version}";
# nix-prefetch-url --unpack https://github.com/input-output-hk/nomad/archive/release/1.4.3.tar.gz
sha256 = "0z4bdx0nx6460q9r032l8ghx337h3fpi6cx8wh7i3qllpyi51a2k";
};
# error: either `vendorHash` or `vendorSha256` is required
# https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317
vendorSha256 = "sha256-JQRpsQhq5r/QcgFwtnptmvnjBEhdCFrXFrTKkJioL3A=";
});
# The plugin is defined but only used if `execTaskDriver` is true.
nomad-driver-podman = (pkgs.buildGo119Module rec {
pname = "nomad-driver-podman";
version = "0.4.1";
subPackages = [ "." ];
doCheck = false; # some tests require a running podman service to pass
src = pkgs.fetchFromGitHub {
owner = "hashicorp";
repo = pname;
rev = "v${version}";
# nix-prefetch-url --unpack https://github.com/hashicorp/nomad-driver-podman/archive/v0.4.1.tar.gz
sha256 = "03856ws02xkqg5374x35zzz5900456rvpsridsjgwvvyqnysn9ls";
};
# error: either `vendorHash` or `vendorSha256` is required
# https://discourse.nixos.org/t/buildgomodule-how-to-get-vendorsha256/9317
vendorSha256 = "sha256-AtgxHAkNzzjMQoSqROpuNoSDum/6JR+mLpcHLFL9EIY=";
});
in if !execTaskDriver
then [ nomad pkgs.podman nomad-driver-podman ]
# If we are going to use the `exec` driver we use the SRE patched
# version of Nomad that allows to use `nix_installables` as artifacts.
else [ nomad-sre pkgs.webfs ]
;

# Backend-specific Nix bits:
materialise-profile =
Expand Down

0 comments on commit dc63f58

Please sign in to comment.