at 21.11-pre 2.0 kB view raw
1let 2 hostIp = "192.168.0.1"; 3 hostPort = 10080; 4 containerIp = "192.168.0.100"; 5 containerPort = 80; 6in 7 8import ./make-test-python.nix ({ pkgs, lib, ... }: { 9 name = "containers-portforward"; 10 meta = { 11 maintainers = with lib.maintainers; [ aristid aszlig eelco kampfschlaefer ianwookim ]; 12 }; 13 14 machine = 15 { pkgs, ... }: 16 { imports = [ ../modules/installer/cd-dvd/channel.nix ]; 17 virtualisation.writableStore = true; 18 virtualisation.memorySize = 768; 19 20 containers.webserver = 21 { privateNetwork = true; 22 hostAddress = hostIp; 23 localAddress = containerIp; 24 forwardPorts = [ { protocol = "tcp"; hostPort = hostPort; containerPort = containerPort; } ]; 25 config = 26 { services.httpd.enable = true; 27 services.httpd.adminAddr = "foo@example.org"; 28 networking.firewall.allowedTCPPorts = [ 80 ]; 29 }; 30 }; 31 32 virtualisation.pathsInNixDB = [ pkgs.stdenv ]; 33 }; 34 35 testScript = 36 '' 37 container_list = machine.succeed("nixos-container list") 38 assert "webserver" in container_list 39 40 # Start the webserver container. 41 machine.succeed("nixos-container start webserver") 42 43 # wait two seconds for the container to start and the network to be up 44 machine.sleep(2) 45 46 # Since "start" returns after the container has reached 47 # multi-user.target, we should now be able to access it. 48 # ip = machine.succeed("nixos-container show-ip webserver").strip() 49 machine.succeed("ping -n -c1 ${hostIp}") 50 machine.succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null") 51 52 # Stop the container. 53 machine.succeed("nixos-container stop webserver") 54 machine.fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null") 55 56 # Destroying a declarative container should fail. 57 machine.fail("nixos-container destroy webserver") 58 ''; 59 60})