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

dockerTools: Fix and test #118722 path in contents

authored by

Robert Hensing and committed by
GitHub
0645328c af1ac444

+31 -1
+13
nixos/tests/docker-tools.nix
··· 383 383 docker.succeed( 384 384 "tar -tf ${examples.exportBash} | grep '\./bin/bash' > /dev/null" 385 385 ) 386 + 387 + with subtest("Ensure bare paths in contents are loaded correctly"): 388 + docker.succeed( 389 + "docker load --input='${examples.build-image-with-path}'", 390 + "docker run --rm build-image-with-path bash -c '[[ -e /hello.txt ]]'", 391 + "docker rmi build-image-with-path", 392 + ) 393 + docker.succeed( 394 + "${examples.layered-image-with-path} | docker load", 395 + "docker run --rm layered-image-with-path bash -c '[[ -e /hello.txt ]]'", 396 + "docker rmi layered-image-with-path", 397 + ) 398 + 386 399 ''; 387 400 })
+6 -1
pkgs/build-support/docker/default.nix
··· 37 37 38 38 let 39 39 40 + inherit (lib) 41 + escapeShellArgs 42 + toList 43 + ; 44 + 40 45 mkDbExtraCommand = contents: 41 46 let 42 47 contentsList = if builtins.isList contents then contents else [ contents ]; ··· 402 407 403 408 preMount = lib.optionalString (contents != null && contents != [ ]) '' 404 409 echo "Adding contents..." 405 - for item in ${toString contents}; do 410 + for item in ${escapeShellArgs (map (c: "${c}") (toList contents))}; do 406 411 echo "Adding $item..." 407 412 rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/ 408 413 done
+12
pkgs/build-support/docker/examples.nix
··· 553 553 554 554 # Example export of the bash image 555 555 exportBash = pkgs.dockerTools.exportImage { fromImage = bash; }; 556 + 557 + build-image-with-path = buildImage { 558 + name = "build-image-with-path"; 559 + tag = "latest"; 560 + contents = [ pkgs.bashInteractive ./test-dummy ]; 561 + }; 562 + 563 + layered-image-with-path = pkgs.dockerTools.streamLayeredImage { 564 + name = "layered-image-with-path"; 565 + tag = "latest"; 566 + contents = [ pkgs.bashInteractive ./test-dummy ]; 567 + }; 556 568 }