at 23.05-pre 1.7 kB view raw
1import ./make-test-python.nix ({ pkgs, lib, ... }: { 2 name = "containers-ephemeral"; 3 meta = { 4 maintainers = with lib.maintainers; [ patryk27 ]; 5 }; 6 7 nodes.machine = { pkgs, ... }: { 8 virtualisation.writableStore = true; 9 10 containers.webserver = { 11 ephemeral = true; 12 privateNetwork = true; 13 hostAddress = "10.231.136.1"; 14 localAddress = "10.231.136.2"; 15 config = { 16 services.nginx = { 17 enable = true; 18 virtualHosts.localhost = { 19 root = pkgs.runCommand "localhost" {} '' 20 mkdir "$out" 21 echo hello world > "$out/index.html" 22 ''; 23 }; 24 }; 25 networking.firewall.allowedTCPPorts = [ 80 ]; 26 }; 27 }; 28 }; 29 30 testScript = '' 31 assert "webserver" in machine.succeed("nixos-container list") 32 33 machine.succeed("nixos-container start webserver") 34 35 with subtest("Container got its own root folder"): 36 machine.succeed("ls /run/nixos-containers/webserver") 37 38 with subtest("Container persistent directory is not created"): 39 machine.fail("ls /var/lib/nixos-containers/webserver") 40 41 # Since "start" returns after the container has reached 42 # multi-user.target, we should now be able to access it. 43 ip = machine.succeed("nixos-container show-ip webserver").rstrip() 44 machine.succeed(f"ping -n -c1 {ip}") 45 machine.succeed(f"curl --fail http://{ip}/ > /dev/null") 46 47 with subtest("Stop the container"): 48 machine.succeed("nixos-container stop webserver") 49 machine.fail(f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null") 50 51 with subtest("Container's root folder was removed"): 52 machine.fail("ls /run/nixos-containers/webserver") 53 ''; 54})