Merge pull request #78834 from nlewo/fix-two-layers-image

Fix dockerTools.buildLayerImage with 2 layers
This commit is contained in:
lewo 2020-01-30 21:10:52 +01:00 committed by GitHub
commit 86f8732194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -80,5 +80,8 @@ import ./make-test.nix ({ pkgs, ... }: {
# This is to be sure the order of layers of the parent image is preserved
$docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layersOrder.imageName} cat /tmp/layer2 | grep -q layer2");
$docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layersOrder.imageName} cat /tmp/layer3 | grep -q layer3");
# Ensure image with only 2 layers can be loaded
$docker->succeed("docker load --input='${pkgs.dockerTools.examples.two-layered-image}'");
'';
})

View File

@ -315,7 +315,7 @@ rec {
runCommand "${name}-granular-docker-layers" {
inherit maxLayers;
paths = referencesByPopularity overallClosure;
nativeBuildInputs = [ jshon rsync tarsum ];
nativeBuildInputs = [ jshon rsync tarsum moreutils ];
enableParallelBuilding = true;
}
''
@ -335,7 +335,8 @@ rec {
cat $paths ${lib.concatMapStringsSep " " (path: "| grep -v ${path}") (closures ++ [ overallClosure ])}
}
paths | head -n $((maxLayers - 1)) | cat -n | xargs -P$NIX_BUILD_CORES -n2 ${storePathToLayer}
# We need to sponge to avoid grep broken pipe error when maxLayers == 1
paths | sponge | head -n $((maxLayers - 1)) | cat -n | xargs -r -P$NIX_BUILD_CORES -n2 ${storePathToLayer}
if [ $(paths | wc -l) -ge $maxLayers ]; then
paths | tail -n+$maxLayers | xargs ${storePathToLayer} $maxLayers
fi
@ -544,6 +545,9 @@ rec {
# believe the actual maximum is 128.
maxLayers ? 100
}:
assert
(lib.assertMsg (maxLayers > 1)
"the maxLayers argument of dockerTools.buildLayeredImage function must be greather than 1 (current value: ${toString maxLayers})");
let
baseName = baseNameOf name;
contentsEnv = symlinkJoin {

View File

@ -238,4 +238,12 @@ rec {
config.Cmd = [ "${pkgs.hello}/bin/hello" ];
};
# 15. Create a layered image with only 2 layers
two-layered-image = pkgs.dockerTools.buildLayeredImage {
name = "two-layered-image";
tag = "latest";
config.Cmd = [ "${pkgs.hello}/bin/hello" ];
contents = [ pkgs.bash pkgs.hello ];
maxLayers = 2;
};
}