git.iko.soy/typeable/nixpkgs
on master help sign in
dockerTools: Test buildLayeredImage with symlinks

This exercises layer creation in face of store path symlinks, ensuring they are not dereferenced, which can lead to broken layer tarballs

commitffe5ff6009017ebbc384e38b5a26e37556d60ecc authorSarah Brofeldt <sarah@qtr.dk> dateMon 4 Jan 2021, 21:33 (6 years ago) parent08b0d02
2 files changed+18
nixos/tests/docker-tools.nix+7 pkgs/build-support/docker/examples.nix+11
nixos/tests/docker-tools.nix+7
@@ -247,5 +247,12 @@ import ./make-test-python.nix ({ pkgs, ... }: {
247247 ).strip()
248248 == "${if pkgs.system == "aarch64-linux" then "amd64" else "arm64"}"
249249 )
250+
251+ with subtest("buildLayeredImage doesn't dereference /nix/store symlink layers"):
252+ docker.succeed(
253+ "docker load --input='${examples.layeredStoreSymlink}'",
254+ "docker run --rm ${examples.layeredStoreSymlink.imageName} bash -c 'test -L ${examples.layeredStoreSymlink.passthru.symlink}'",
255+ "docker rmi ${examples.layeredStoreSymlink.imageName}",
256+ )
250257 '';
251258})
pkgs/build-support/docker/examples.nix+11
@@ -416,4 +416,15 @@ rec {
416416 contents = crossPkgs.hello;
417417 };
418418
419+ # layered image where a store path is itself a symlink
420+ layeredStoreSymlink =
421+ let
422+ target = pkgs.writeTextDir "dir/target" "Content doesn't matter.";
423+ symlink = pkgs.runCommandNoCC "symlink" {} "ln -s ${target} $out";
424+ in
425+ pkgs.dockerTools.buildLayeredImage {
426+ name = "layeredstoresymlink";
427+ tag = "latest";
428+ contents = [ pkgs.bash symlink ];
429+ } // { passthru = { inherit symlink; }; };
419430}