Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

dockerTools: optionally preserve directory symlinks

In some cases, this seems to save a lot (>40%) of space.

(cherry picked from commit dce2c258ac33ee1cd3b3e852b36e1d8fa11f33a1)

authored by Ryan Trinkle and committed by John Ericson 2a17d7ca e08245f8

+17 -4
+17 -4
pkgs/build-support/docker/default.nix
··· 249 249 baseJson, 250 250 # Files to add to the layer. 251 251 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, 252 256 # Additional commands to run on the layer before it is tar'd up. 253 257 extraCommands ? "", uid ? 0, gid ? 0 254 258 }: ··· 262 266 echo "Adding contents..." 263 267 for item in $contents; do 264 268 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/ 266 270 done 267 271 else 268 272 echo "No contents to add to layer." ··· 303 307 runAsRoot, 304 308 # Files to add to the layer. If null, an empty layer will be created. 305 309 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, 306 314 # JSON containing configuration and metadata for this layer. 307 315 baseJson, 308 316 # Existing image onto which to append the new layer. ··· 327 335 echo "Adding contents..." 328 336 for item in ${toString contents}; do 329 337 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/ 331 339 done 332 340 333 341 chmod ug+w layer ··· 391 399 fromImageTag ? null, 392 400 # Files to put on the image (a nix store path or list of paths). 393 401 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, 394 406 # Docker config; e.g. what command to run on the container. 395 407 config ? null, 396 408 # Optional bash script to run on the files prior to fixturizing the layer. ··· 417 429 if runAsRoot == null 418 430 then mkPureLayer { 419 431 name = baseName; 420 - inherit baseJson contents extraCommands uid gid; 432 + inherit baseJson contents keepContentsDirlinks extraCommands uid gid; 421 433 } else mkRootLayer { 422 434 name = baseName; 423 435 inherit baseJson fromImage fromImageName fromImageTag 424 - contents runAsRoot diskSize extraCommands; 436 + contents keepContentsDirlinks runAsRoot diskSize 437 + extraCommands; 425 438 }; 426 439 result = runCommand "docker-image-${baseName}.tar.gz" { 427 440 buildInputs = [ jshon pigz coreutils findutils jq ];