1# Not everyone has a suitable remote builder set up, so the cross-compilation
2# tests that _include_ running the result are separate. That way, most people
3# can run the majority of the test suite without the extra setup.
4
5
6import ./make-test-python.nix ({ pkgs, ... }:
7let
8
9 remoteSystem =
10 if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
11 then "x86_64-linux"
12 else "aarch64-linux";
13
14 remoteCrossPkgs = import ../.. /*nixpkgs*/ {
15 # NOTE: This is the machine that runs the build - local from the
16 # 'perspective' of the build script.
17 localSystem = remoteSystem;
18
19 # NOTE: Since this file can't control where the test will be _run_ we don't
20 # cross-compile _to_ a different system but _from_ a different system
21 crossSystem = pkgs.stdenv.hostPlatform.system;
22 };
23
24 hello1 = remoteCrossPkgs.dockerTools.buildImage {
25 name = "hello1";
26 tag = "latest";
27 copyToRoot = remoteCrossPkgs.buildEnv {
28 name = "image-root";
29 pathsToLink = [ "/bin" ];
30 paths = [ remoteCrossPkgs.hello ];
31 };
32 };
33
34 hello2 = remoteCrossPkgs.dockerTools.buildLayeredImage {
35 name = "hello2";
36 tag = "latest";
37 contents = remoteCrossPkgs.hello;
38 };
39
40in {
41 name = "docker-tools";
42 meta = with pkgs.lib.maintainers; {
43 maintainers = [ roberth ];
44 };
45
46 nodes = {
47 docker = { ... }: {
48 virtualisation = {
49 diskSize = 2048;
50 docker.enable = true;
51 };
52 };
53 };
54
55 testScript = ''
56 docker.wait_for_unit("sockets.target")
57
58 with subtest("Ensure cross compiled buildImage image can run."):
59 docker.succeed(
60 "docker load --input='${hello1}'"
61 )
62 assert "Hello, world!" in docker.succeed(
63 "docker run --rm ${hello1.imageName} hello",
64 )
65 docker.succeed(
66 "docker rmi ${hello1.imageName}",
67 )
68
69 with subtest("Ensure cross compiled buildLayeredImage image can run."):
70 docker.succeed(
71 "docker load --input='${hello2}'"
72 )
73 assert "Hello, world!" in docker.succeed(
74 "docker run --rm ${hello2.imageName} hello",
75 )
76 docker.succeed(
77 "docker rmi ${hello2.imageName}",
78 )
79 '';
80})