From ace5563a8f8428483c050759274d0a32de9f67d9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Oct 2021 13:13:07 +0200 Subject: Add first working setup for running kind cluster Signed-off-by: Matthias Beyer --- default.nix | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 default.nix (limited to 'default.nix') diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..e8cbc19 --- /dev/null +++ b/default.nix @@ -0,0 +1,90 @@ +{ channel ? "stable", pkgs ? import {} }: + +let + helloService = pkgs.callPackage ./service-hello {}; + worldService = pkgs.callPackage ./service-world {}; + joinerService = pkgs.callPackage ./service-joiner {}; + kubenix = pkgs.callPackage ./nix/kubenix.nix {}; + + buildConfig = t: kubenix.buildResources { configuration = import ./configuration.nix { type = t; }; }; + + helloImage = pkgs.dockerTools.buildLayeredImage { + name = "hello-service"; + tag = "latest"; + config.Cmd = [ "${helloService}/bin/service-hello" ]; + }; + + worldImage = pkgs.dockerTools.buildLayeredImage { + name = "world-service"; + tag = "latest"; + config.Cmd = [ "${worldService}/bin/service-world" ]; + }; + + joinerImage = pkgs.dockerTools.buildLayeredImage { + name = "joiner-service"; + tag = "latest"; + config.Cmd = [ "${joinerService}/bin/service-joiner" ]; + }; +in rec { + inherit helloImage worldImage joinerImage; + + test-deployment = pkgs.callPackage ./nix/test-deployment.nix { }; + + deploy-to-kind = pkgs.callPackage ./nix/deploy-to-kind.nix { + inherit helloImage worldImage joinerImage; + + config = buildConfig "dev"; + }; + + config = buildConfig "dev"; + + redeploy = pkgs.writeScriptBin "redeploy" '' + cat ${config} | ${pkgs.kubectl}/bin/kubectl apply -f - + ''; + + deploy-and-test = pkgs.mkShell { + buildInputs = [ pkgs.kind deploy-to-kind test-deployment ]; + + shellHook = '' + deploy-to-kind + export KUBECONFIG=$(kind get kubeconfig-path) + wait-for-deployment hello + test-deployment + kind delete cluster + ''; + }; + + shell = let + moz_overlay = import ( + builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz + ); + + pkgs = import { overlays = [ moz_overlay ]; }; + rustchannel = pkgs.rustChannelOf { inherit channel; }; + in + pkgs.mkShell { + buildInputs = with pkgs; [ + kind + deploy-to-kind + test-deployment + redeploy + curl + docker + kubectl + + rustchannel.rust-std + rustchannel.rust + rustchannel.rustc + rustchannel.cargo + + cmake + curl + gcc + openssl + pkgconfig + ]; + + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib"; + }; + +} -- cgit v1.2.3