Merge pull request #18896 from tboettch/dockerToolsFix

dockerTools: Fix layer redundancy.

authored by Luca Bruno and committed by GitHub c049fd4a 3d7d44a4

+16 -5
+16 -5
pkgs/build-support/docker/default.nix
··· 1 1 { stdenv, lib, callPackage, runCommand, writeReferencesToFile, writeText, vmTools, writeScript 2 - , docker, shadow, utillinux, coreutils, jshon, e2fsprogs, go, pigz }: 2 + , docker, shadow, utillinux, coreutils, jshon, e2fsprogs, go, pigz, findutils }: 3 3 4 4 # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. 5 5 ··· 249 249 then mkPureLayer { inherit baseJson contents extraCommands; } 250 250 else mkRootLayer { inherit baseJson fromImage fromImageName fromImageTag contents runAsRoot diskSize extraCommands; }); 251 251 result = runCommand "${baseName}.tar.gz" { 252 - buildInputs = [ jshon pigz ]; 252 + buildInputs = [ jshon pigz coreutils findutils ]; 253 253 254 254 imageName = name; 255 255 imageTag = tag; ··· 261 261 buildArgs = args; 262 262 }; 263 263 } '' 264 + # Print tar contents: 265 + # 1: Interpreted as relative to the root directory 266 + # 2: With no trailing slashes on directories 267 + # This is useful for ensuring that the output matches the values generated by the "find" command 268 + ls_tar() { 269 + for f in $(tar -tf $1 | xargs realpath -ms --relative-to=.); do 270 + if [ "$f" != "." ]; then 271 + echo "/$f" 272 + fi 273 + done 274 + } 275 + 264 276 mkdir image 265 277 touch baseFiles 266 278 if [ -n "$fromImage" ]; then ··· 276 288 parentID=$(jshon -e $fromImageName -e $fromImageTag -u < image/repositories) 277 289 278 290 for l in image/*/layer.tar; do 279 - tar -tf $l >> baseFiles 291 + ls_tar $l >> baseFiles 280 292 done 281 293 fi 282 294 ··· 297 309 fi 298 310 299 311 echo Adding layer 300 - tar -tf temp/layer.tar >> baseFiles 301 - sed 's/^\.//' -i baseFiles 312 + ls_tar temp/layer.tar >> baseFiles 302 313 comm <(sort -u baseFiles) <(sort -u layerFiles) -1 -3 > newFiles 303 314 tar -rpf temp/layer.tar --mtime=0 --no-recursion --files-from newFiles 2>/dev/null || true 304 315