commit 9a93582d7523d2f876e90dd5b2740db22ca752e7
parent 1e97bf42db84994ffe68808293d0af64de4aa3dd
Author: Vincent Demeester <vincent@sbr.pm>
Date: Wed, 15 Sep 2021 18:24:18 +0200
tools: create a k8s.infra tool
Very simple to start with : build and sync k8s node base images.
Will probably add more options in the future, but let's start with
something that works.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
5 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/bin/__dispatch.sh b/bin/__dispatch.sh
@@ -19,6 +19,9 @@ case "${TARGET_TOOL}" in
bus)
attr="tools.bus"
;;
+ k8s.infra)
+ attr="tools.k8s_infra"
+ ;;
*)
echo "The tool '${TARGET_TOOL}' is currently not installed in this repository."
exit 1
diff --git a/bin/k8s.infra b/bin/k8s.infra
@@ -0,0 +1 @@
+__dispatch.sh+
\ No newline at end of file
diff --git a/default.nix b/default.nix
@@ -11,4 +11,5 @@ in
tools.bus = pkgs.callPackage ./tools/bus { };
tools.univ = pkgs.callPackage ./tools/univ { };
tools.system = pkgs.callPackage ./tools/system { };
+ tools.k8s_infra = pkgs.callPackage ./tools/k8s.infra { };
}
diff --git a/tools/k8s.infra/default.nix b/tools/k8s.infra/default.nix
@@ -0,0 +1,11 @@
+{ stdenv }:
+
+stdenv.mkDerivation {
+ name = "k8s.infra";
+ src = ./.;
+ phases = [ "installPhase" "fixupPhase" ];
+ installPhase = ''
+ mkdir -p $out $out/bin
+ cp $src/k8s.infra.sh $out/bin/k8s.infra
+ '';
+}
diff --git a/tools/k8s.infra/k8s.infra.sh b/tools/k8s.infra/k8s.infra.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# univ: update niv (and generate a nice commit)
+
+set -euo pipefail
+
+HOST=${HOST:-wakasu.home}
+RSYNC_COMMAND="rsync -avzHXShPse ssh --progress"
+
+main() {
+ for n in k8sn1 k8sn2 k8sn3; do
+ logs=$(mktemp)
+ output=$(mktemp)
+ echo "Build ${n} node (logs: ${logs})…"
+ nixos-generate -f qcow -c ./systems/hosts/${n}.nix 2>${logs} 1>${output}
+ echo "Syncthing image to ${HOST}…"
+ ${RSYNC_COMMAND} $(cat ${output} | tr -d '\n') root@${HOST}:/var/lib/libvirt/images/${n}.qcow2 --dry-run
+ done
+}
+
+main $@