Commit 9a93582d7523

Vincent Demeester <vincent@sbr.pm>
2021-09-15 18:24:18
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>
1 parent 1e97bf4
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
bin/k8s.infra
@@ -0,0 +1,1 @@
+__dispatch.sh
\ No newline at end of file
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
+  '';
+}
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 $@
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 { };
 }