dockerTools: Add store dependencies of the customization layer

This commit is contained in:
Robert Hensing
2021-10-01 13:47:01 +02:00
parent 1d5953184a
commit 48cfdc8ca5
3 changed files with 22 additions and 6 deletions

View File

@@ -276,15 +276,22 @@ import ./make-test-python.nix ({ pkgs, ... }: {
# Ensure the image has the correct number of layers # Ensure the image has the correct number of layers
assert len(set_of_layers("layered-bulk-layer")) == 4 assert len(set_of_layers("layered-bulk-layer")) == 4
with subtest("Ensure correct behavior when no store is needed"): with subtest("Ensure only minimal paths are added to the store"):
# TODO: make an example that has no store paths, for example by making
# busybox non-self-referential.
# This check tests that buildLayeredImage can build images that don't need a store. # This check tests that buildLayeredImage can build images that don't need a store.
docker.succeed( docker.succeed(
"docker load --input='${pkgs.dockerTools.examples.no-store-paths}'" "docker load --input='${pkgs.dockerTools.examples.no-store-paths}'"
) )
# This check may be loosened to allow an *empty* store rather than *no* store. docker.succeed("docker run --rm no-store-paths ls / >/dev/console")
docker.succeed("docker run --rm no-store-paths ls /")
docker.fail("docker run --rm no-store-paths ls /nix/store") # If busybox isn't self-referential, we need this line
# docker.fail("docker run --rm no-store-paths ls /nix/store >/dev/console")
# However, it currently is self-referential, so we check that it is the
# only store path.
docker.succeed("diff <(docker run --rm no-store-paths ls /nix/store) <(basename ${pkgs.pkgsStatic.busybox}) >/dev/console")
with subtest("Ensure buildLayeredImage does not change store path contents."): with subtest("Ensure buildLayeredImage does not change store path contents."):
docker.succeed( docker.succeed(
@@ -379,6 +386,11 @@ import ./make-test-python.nix ({ pkgs, ... }: {
"docker run --rm ${examples.layeredImageWithFakeRootCommands.imageName} sh -c 'stat -c '%u' /home/jane | grep -E ^1000$'" "docker run --rm ${examples.layeredImageWithFakeRootCommands.imageName} sh -c 'stat -c '%u' /home/jane | grep -E ^1000$'"
) )
with subtest("The image contains store paths referenced by the fakeRootCommands output"):
docker.succeed(
"docker run --rm ${examples.layeredImageWithFakeRootCommands.imageName} /hello/bin/hello"
)
with subtest("exportImage produces a valid tarball"): with subtest("exportImage produces a valid tarball"):
docker.succeed( docker.succeed(
"tar -tf ${examples.exportBash} | grep '\./bin/bash' > /dev/null" "tar -tf ${examples.exportBash} | grep '\./bin/bash' > /dev/null"

View File

@@ -864,13 +864,13 @@ rec {
}; };
closureRoots = lib.optionals includeStorePaths /* normally true */ ( closureRoots = lib.optionals includeStorePaths /* normally true */ (
[ baseJson ] ++ contentsList [ baseJson customisationLayer ]
); );
overallClosure = writeText "closure" (lib.concatStringsSep " " closureRoots); overallClosure = writeText "closure" (lib.concatStringsSep " " closureRoots);
# These derivations are only created as implementation details of docker-tools, # These derivations are only created as implementation details of docker-tools,
# so they'll be excluded from the created images. # so they'll be excluded from the created images.
unnecessaryDrvs = [ baseJson overallClosure ]; unnecessaryDrvs = [ baseJson overallClosure customisationLayer ];
conf = runCommand "${baseName}-conf.json" conf = runCommand "${baseName}-conf.json"
{ {

View File

@@ -350,6 +350,9 @@ rec {
# This removes sharing of busybox and is not recommended. We do this # This removes sharing of busybox and is not recommended. We do this
# to make the example suitable as a test case with working binaries. # to make the example suitable as a test case with working binaries.
cp -r ${pkgs.pkgsStatic.busybox}/* . cp -r ${pkgs.pkgsStatic.busybox}/* .
# This is a "build" dependency that will not appear in the image
${pkgs.hello}/bin/hello
''; '';
}; };
@@ -504,6 +507,7 @@ rec {
fakeRootCommands = '' fakeRootCommands = ''
mkdir -p ./home/jane mkdir -p ./home/jane
chown 1000 ./home/jane chown 1000 ./home/jane
ln -s ${pkgs.pkgsStatic.hello} ./hello
''; '';
}; };