summary refs log tree commit diff
path: root/pkgs/build-support/docker
diff options
context:
space:
mode:
authorRyan Trinkle <ryan.trinkle@gmail.com>2018-04-09 17:44:09 -0400
committerGitHub <noreply@github.com>2018-04-09 17:44:09 -0400
commit1034aa8e9cb88dc21e5ab646f2e72a45a9294038 (patch)
tree9dc6e47d9199982bbcd25739aa7a1559f229d012 /pkgs/build-support/docker
parent487be791d783c706369a1a0740e03a0bb60d8f1f (diff)
parentded1281f4519bfdeea6c79eb6857f00619d9859d (diff)
downloadnixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar.gz
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar.bz2
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar.lz
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar.xz
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.tar.zst
nixpkgs-1034aa8e9cb88dc21e5ab646f2e72a45a9294038.zip
Merge pull request #25148 from obsidiansystems/docker-dirlinks
dockerTools: optionally preserve directory symlinks
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r--pkgs/build-support/docker/default.nix21
1 files changed, 17 insertions, 4 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index f531f1349c6..b8eda3d0967 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -249,6 +249,10 @@ rec {
     baseJson,
     # Files to add to the layer.
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # Additional commands to run on the layer before it is tar'd up.
     extraCommands ? "", uid ? 0, gid ? 0
   }:
@@ -262,7 +266,7 @@ rec {
         echo "Adding contents..."
         for item in $contents; do
           echo "Adding $item"
-          rsync -ak --chown=0:0 $item/ layer/
+          rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
         done
       else
         echo "No contents to add to layer."
@@ -303,6 +307,10 @@ rec {
     runAsRoot,
     # Files to add to the layer. If null, an empty layer will be created.
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # JSON containing configuration and metadata for this layer.
     baseJson,
     # Existing image onto which to append the new layer.
@@ -327,7 +335,7 @@ rec {
         echo "Adding contents..."
         for item in ${toString contents}; do
           echo "Adding $item..."
-          rsync -ak --chown=0:0 $item/ layer/
+          rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
         done
 
         chmod ug+w layer
@@ -391,6 +399,10 @@ rec {
     fromImageTag ? null,
     # Files to put on the image (a nix store path or list of paths).
     contents ? null,
+    # When copying the contents into the image, preserve symlinks to
+    # directories (see `rsync -K`).  Otherwise, transform those symlinks
+    # into directories.
+    keepContentsDirlinks ? false,
     # Docker config; e.g. what command to run on the container.
     config ? null,
     # Optional bash script to run on the files prior to fixturizing the layer.
@@ -417,11 +429,12 @@ rec {
         if runAsRoot == null
         then mkPureLayer {
           name = baseName;
-          inherit baseJson contents extraCommands uid gid;
+          inherit baseJson contents keepContentsDirlinks extraCommands uid gid;
         } else mkRootLayer {
           name = baseName;
           inherit baseJson fromImage fromImageName fromImageTag
-                  contents runAsRoot diskSize extraCommands;
+                  contents keepContentsDirlinks runAsRoot diskSize
+                  extraCommands;
         };
       result = runCommand "docker-image-${baseName}.tar.gz" {
         buildInputs = [ jshon pigz coreutils findutils jq ];