git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #25148 from obsidiansystems/docker-dirlinks

dockerTools: optionally preserve directory symlinks

commit1034aa8e9cb88dc21e5ab646f2e72a45a9294038 authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 9 Apr 2018, 17:44 (9 years ago) parent487be79ded1281
1 file changed+17−4
pkgs/build-support/docker/default.nix+17−4
pkgs/build-support/docker/default.nix+17−4
@@ -249,6 +249,10 @@ rec {
249249 baseJson,
250250 # Files to add to the layer.
251251 contents ? null,
252+ # When copying the contents into the image, preserve symlinks to
253+ # directories (see `rsync -K`). Otherwise, transform those symlinks
254+ # into directories.
255+ keepContentsDirlinks ? false,
252256 # Additional commands to run on the layer before it is tar'd up.
253257 extraCommands ? "", uid ? 0, gid ? 0
254258 }:
@@ -262,7 +266,7 @@ rec {
262266 echo "Adding contents..."
263267 for item in $contents; do
264268 echo "Adding $item"
265− rsync -ak --chown=0:0 $item/ layer/
269+ rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
266270 done
267271 else
268272 echo "No contents to add to layer."
@@ -303,6 +307,10 @@ rec {
303307 runAsRoot,
304308 # Files to add to the layer. If null, an empty layer will be created.
305309 contents ? null,
310+ # When copying the contents into the image, preserve symlinks to
311+ # directories (see `rsync -K`). Otherwise, transform those symlinks
312+ # into directories.
313+ keepContentsDirlinks ? false,
306314 # JSON containing configuration and metadata for this layer.
307315 baseJson,
308316 # Existing image onto which to append the new layer.
@@ -327,7 +335,7 @@ rec {
327335 echo "Adding contents..."
328336 for item in ${toString contents}; do
329337 echo "Adding $item..."
330− rsync -ak --chown=0:0 $item/ layer/
338+ rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
331339 done
332340
333341 chmod ug+w layer
@@ -391,6 +399,10 @@ rec {
391399 fromImageTag ? null,
392400 # Files to put on the image (a nix store path or list of paths).
393401 contents ? null,
402+ # When copying the contents into the image, preserve symlinks to
403+ # directories (see `rsync -K`). Otherwise, transform those symlinks
404+ # into directories.
405+ keepContentsDirlinks ? false,
394406 # Docker config; e.g. what command to run on the container.
395407 config ? null,
396408 # Optional bash script to run on the files prior to fixturizing the layer.
@@ -417,11 +429,12 @@ rec {
417429 if runAsRoot == null
418430 then mkPureLayer {
419431 name = baseName;
420− inherit baseJson contents extraCommands uid gid;
432+ inherit baseJson contents keepContentsDirlinks extraCommands uid gid;
421433 } else mkRootLayer {
422434 name = baseName;
423435 inherit baseJson fromImage fromImageName fromImageTag
424− contents runAsRoot diskSize extraCommands;
436+ contents keepContentsDirlinks runAsRoot diskSize
437+ extraCommands;
425438 };
426439 result = runCommand "docker-image-${baseName}.tar.gz" {
427440 buildInputs = [ jshon pigz coreutils findutils jq ];