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