lix-installer/nix/tests/container-test/default.nix
Ana Hobden d69f335703
init-less install (#188)
* wip

* Add dockerfile

* Add readme bits

* Fix logic inversion

* Relax init detection error

* Tidying heuristics

* Fix doc tests

* Mac supports start-daemon false

* Get VM tests working

* Add instructions

* Some target_os flagging

* More target flagging

* Fix lints

* Fixup more mac-only stuff

* cfg flag examples too

* Fix planner wording

* More os specific lint fixing

* More refinement on mac and the README

* Add new CI jobs to test no-daemon

* Use nix-installer-pr to point at branch

* Tests with no-init

* init/no-daemon are linux only

* nix tests support a per-distro all attribute

* Add working podman test

* Expand docker tests

* Add contributing notes

* format

* Support both podman and docker

* Update contributing

* Add Windows WSL test script for Ubuntu

* format nix tests

* More ignores to check-spelling

* Add systemd based wsl test

* We don't have root-only darwin

* Reflect review nits

* Reenable tests

* Restore mac plan

* Flag off os specific tests

* Better cfg flagging

* Remove dead comments

* Rework readme to look better with new sections

* Correct codeblock language

* Remove some warnings
2023-02-01 12:35:52 -08:00

101 lines
3.5 KiB
Nix

# Largely derived from https://github.com/NixOS/nix/blob/14f7dae3e4eb0c34192d0077383a7f2a2d630129/tests/installer/default.nix
{ forSystem, binaryTarball }:
let
images = {
# Found via https://hub.docker.com/_/ubuntu/ under "How is the rootfs build?"
# Jammy
"ubuntu-v22_04" = {
tarball = import <nix/fetchurl.nix> {
url = "https://launchpad.net/~cloud-images-release-managers/+livefs/ubuntu/jammy/ubuntu-oci/+build/408115/+files/livecd.ubuntu-oci.rootfs.tar.gz";
hash = "sha256-BirwSM4c+ZV1upU0yV3qa+BW9AvpBUxvZuPTeI9mA8M=";
};
tester = ./default/Dockerfile;
system = "x86_64-linux";
};
# focal
"ubuntu-v20_04" = {
tarball = import <nix/fetchurl.nix> {
url = "https://launchpad.net/~cloud-images-release-managers/+livefs/ubuntu/focal/ubuntu-oci/+build/408120/+files/livecd.ubuntu-oci.rootfs.tar.gz";
hash = "sha256-iTJR+DeC5lT4PMqT/xFAFwmlC/qvslDFccDrVFLt/a8=";
};
tester = ./default/Dockerfile;
system = "x86_64-linux";
};
# bionic
"ubuntu-v18_04" = {
tarball = import <nix/fetchurl.nix> {
url = "https://launchpad.net/~cloud-images-release-managers/+livefs/ubuntu/bionic/ubuntu-oci/+build/408103/+files/livecd.ubuntu-oci.rootfs.tar.gz";
hash = "sha256-gi48yl5laoKLoVCDIORsseOM6DI58FNpAjSVe7OOs7I=";
};
tester = ./default/Dockerfile;
system = "x86_64-linux";
};
};
makeTest = containerTool: imageName:
let image = images.${imageName}; in
with (forSystem image.system ({ system, pkgs, lib, ... }: pkgs));
testers.nixosTest
{
name = "container-test-${imageName}";
nodes = {
machine =
{ config, pkgs, ... }: {
virtualisation.${containerTool}.enable = true;
};
};
testScript = ''
machine.start()
machine.copy_from_host("${image.tarball}", "/image")
machine.succeed("mkdir -p /test")
machine.copy_from_host("${image.tester}", "/test/Dockerfile")
machine.copy_from_host("${nix-installer-static}", "/test/nix-installer")
machine.copy_from_host("${binaryTarball.${system}}", "/test/binary-tarball")
machine.succeed("${containerTool} import /image default")
machine.succeed("${containerTool} build -t test /test")
'';
};
container-tests = builtins.mapAttrs
(imageName: image: (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); {
${image.system} = rec {
docker = makeTest "docker" imageName;
podman = makeTest "podman" imageName;
all = pkgs.releaseTools.aggregate {
name = "all";
constituents = [
docker
podman
];
};
};
}))
images;
in
container-tests // {
all."x86_64-linux" = rec {
all = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate {
name = "all";
constituents = [
docker
podman
];
});
docker = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate {
name = "all";
constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".docker) container-tests;
});
podman = (with (forSystem "x86_64-linux" ({ system, pkgs, ... }: pkgs)); pkgs.releaseTools.aggregate {
name = "all";
constituents = pkgs.lib.mapAttrsToList (name: value: value."x86_64-linux".podman) container-tests;
});
};
}