diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2021-01-05 10:00:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 10:00:28 +0100 |
commit | 5540dd9b9ba6ebad454c2b3d0d31557b9521378e (patch) | |
tree | 09b8eef9b5f1a04e4f6b2deb3ea251285a30706c | |
parent | 517241f35480aa15999c92b5a669f229ea1b01d6 (diff) | |
parent | ffe5ff6009017ebbc384e38b5a26e37556d60ecc (diff) |
Merge pull request #108416 from srhb/streamlayeredimage-symlinked-storepaths
dockerTools: Fix streamLayeredImage for symlinks
-rw-r--r-- | nixos/tests/docker-tools.nix | 7 | ||||
-rw-r--r-- | pkgs/build-support/docker/examples.nix | 11 | ||||
-rw-r--r-- | pkgs/build-support/docker/stream_layered_image.py | 6 |
3 files changed, 23 insertions, 1 deletions
diff --git a/nixos/tests/docker-tools.nix b/nixos/tests/docker-tools.nix index 8402ba68b720..369ef94f9fad 100644 --- a/nixos/tests/docker-tools.nix +++ b/nixos/tests/docker-tools.nix @@ -247,5 +247,12 @@ import ./make-test-python.nix ({ pkgs, ... }: { ).strip() == "${if pkgs.system == "aarch64-linux" then "amd64" else "arm64"}" ) + + with subtest("buildLayeredImage doesn't dereference /nix/store symlink layers"): + docker.succeed( + "docker load --input='${examples.layeredStoreSymlink}'", + "docker run --rm ${examples.layeredStoreSymlink.imageName} bash -c 'test -L ${examples.layeredStoreSymlink.passthru.symlink}'", + "docker rmi ${examples.layeredStoreSymlink.imageName}", + ) ''; }) diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 85ddeb257405..86375a40baa0 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -416,4 +416,15 @@ rec { contents = crossPkgs.hello; }; + # layered image where a store path is itself a symlink + layeredStoreSymlink = + let + target = pkgs.writeTextDir "dir/target" "Content doesn't matter."; + symlink = pkgs.runCommandNoCC "symlink" {} "ln -s ${target} $out"; + in + pkgs.dockerTools.buildLayeredImage { + name = "layeredstoresymlink"; + tag = "latest"; + contents = [ pkgs.bash symlink ]; + } // { passthru = { inherit symlink; }; }; } diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py index cbae0f723f92..e35bd0b0e8c0 100644 --- a/pkgs/build-support/docker/stream_layered_image.py +++ b/pkgs/build-support/docker/stream_layered_image.py @@ -83,7 +83,11 @@ def archive_paths_to(obj, paths, mtime): for path in paths: path = pathlib.Path(path) - files = itertools.chain([path], path.rglob("*")) + if path.is_symlink(): + files = [path] + else: + files = itertools.chain([path], path.rglob("*")) + for filename in sorted(files): ti = append_root(tar.gettarinfo(filename)) |