Merge pull request #142075 from hercules-ci/issue-118722-path-in-contents

dockerTools: Fix and test #118722 path in contents

Changed files
+31 -1
nixos
pkgs
build-support
+13
nixos/tests/docker-tools.nix
···
docker.succeed(
"tar -tf ${examples.exportBash} | grep '\./bin/bash' > /dev/null"
)
+
+
with subtest("Ensure bare paths in contents are loaded correctly"):
+
docker.succeed(
+
"docker load --input='${examples.build-image-with-path}'",
+
"docker run --rm build-image-with-path bash -c '[[ -e /hello.txt ]]'",
+
"docker rmi build-image-with-path",
+
)
+
docker.succeed(
+
"${examples.layered-image-with-path} | docker load",
+
"docker run --rm layered-image-with-path bash -c '[[ -e /hello.txt ]]'",
+
"docker rmi layered-image-with-path",
+
)
+
'';
})
+6 -1
pkgs/build-support/docker/default.nix
···
let
+
inherit (lib)
+
escapeShellArgs
+
toList
+
;
+
mkDbExtraCommand = contents:
let
contentsList = if builtins.isList contents then contents else [ contents ];
···
preMount = lib.optionalString (contents != null && contents != [ ]) ''
echo "Adding contents..."
-
for item in ${toString contents}; do
+
for item in ${escapeShellArgs (map (c: "${c}") (toList contents))}; do
echo "Adding $item..."
rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
done
+12
pkgs/build-support/docker/examples.nix
···
# Example export of the bash image
exportBash = pkgs.dockerTools.exportImage { fromImage = bash; };
+
+
build-image-with-path = buildImage {
+
name = "build-image-with-path";
+
tag = "latest";
+
contents = [ pkgs.bashInteractive ./test-dummy ];
+
};
+
+
layered-image-with-path = pkgs.dockerTools.streamLayeredImage {
+
name = "layered-image-with-path";
+
tag = "latest";
+
contents = [ pkgs.bashInteractive ./test-dummy ];
+
};
}