dockerTools: optionally preserve directory symlinks

In some cases, this seems to save a lot (>40%) of space.
This commit is contained in:
Ryan Trinkle 2017-04-23 09:45:21 -04:00
parent 9f6baaa89a
commit dce2c258ac

View File

@ -233,6 +233,10 @@ rec {
baseJson, baseJson,
# Files to add to the layer. # Files to add to the layer.
contents ? null, 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. # Additional commands to run on the layer before it is tar'd up.
extraCommands ? "" extraCommands ? ""
}: }:
@ -247,7 +251,7 @@ rec {
echo "Adding contents..." echo "Adding contents..."
for item in $contents; do for item in $contents; do
echo "Adding $item" echo "Adding $item"
rsync -ak --chown=0:0 $item/ layer/ rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
done done
else else
echo "No contents to add to layer." echo "No contents to add to layer."
@ -286,6 +290,10 @@ rec {
runAsRoot, runAsRoot,
# Files to add to the layer. If null, an empty layer will be created. # Files to add to the layer. If null, an empty layer will be created.
contents ? null, 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. # JSON containing configuration and metadata for this layer.
baseJson, baseJson,
# Existing image onto which to append the new layer. # Existing image onto which to append the new layer.
@ -310,7 +318,7 @@ rec {
echo "Adding contents..." echo "Adding contents..."
for item in ${toString contents}; do for item in ${toString contents}; do
echo "Adding $item..." echo "Adding $item..."
rsync -ak --chown=0:0 $item/ layer/ rsync -a${if keepContentsDirlinks then "K" else "k"} --chown=0:0 $item/ layer/
done done
''; '';
@ -372,6 +380,10 @@ rec {
fromImageTag ? null, fromImageTag ? null,
# Files to put on the image (a nix store path or list of paths). # Files to put on the image (a nix store path or list of paths).
contents ? null, 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. # Docker config; e.g. what command to run on the container.
config ? null, config ? null,
# Optional bash script to run on the files prior to fixturizing the layer. # Optional bash script to run on the files prior to fixturizing the layer.
@ -397,11 +409,12 @@ rec {
if runAsRoot == null if runAsRoot == null
then mkPureLayer { then mkPureLayer {
name = baseName; name = baseName;
inherit baseJson contents extraCommands; inherit baseJson contents keepContentsDirlinks extraCommands;
} else mkRootLayer { } else mkRootLayer {
name = baseName; name = baseName;
inherit baseJson fromImage fromImageName fromImageTag inherit baseJson fromImage fromImageName fromImageTag
contents runAsRoot diskSize extraCommands; contents keepContentsDirlinks runAsRoot diskSize
extraCommands;
}; };
result = runCommand "docker-image-${baseName}.tar.gz" { result = runCommand "docker-image-${baseName}.tar.gz" {
buildInputs = [ jshon pigz coreutils findutils ]; buildInputs = [ jshon pigz coreutils findutils ];