mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 23:13:19 +00:00
dockerTools.buildLayeredImage: fix image with only 2 layers
A test is also added to ensure an image with 2 layers can be built.
This commit is contained in:
parent
8539d5f48f
commit
283bcc1003
@ -80,5 +80,8 @@ import ./make-test.nix ({ pkgs, ... }: {
|
|||||||
# This is to be sure the order of layers of the parent image is preserved
|
# 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/layer2 | grep -q layer2");
|
||||||
$docker->succeed("docker run --rm ${pkgs.dockerTools.examples.layersOrder.imageName} cat /tmp/layer3 | grep -q layer3");
|
$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}'");
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
@ -315,7 +315,7 @@ rec {
|
|||||||
runCommand "${name}-granular-docker-layers" {
|
runCommand "${name}-granular-docker-layers" {
|
||||||
inherit maxLayers;
|
inherit maxLayers;
|
||||||
paths = referencesByPopularity overallClosure;
|
paths = referencesByPopularity overallClosure;
|
||||||
nativeBuildInputs = [ jshon rsync tarsum ];
|
nativeBuildInputs = [ jshon rsync tarsum moreutils ];
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
@ -335,7 +335,8 @@ rec {
|
|||||||
cat $paths ${lib.concatMapStringsSep " " (path: "| grep -v ${path}") (closures ++ [ overallClosure ])}
|
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
|
if [ $(paths | wc -l) -ge $maxLayers ]; then
|
||||||
paths | tail -n+$maxLayers | xargs ${storePathToLayer} $maxLayers
|
paths | tail -n+$maxLayers | xargs ${storePathToLayer} $maxLayers
|
||||||
fi
|
fi
|
||||||
|
@ -238,4 +238,12 @@ rec {
|
|||||||
config.Cmd = [ "${pkgs.hello}/bin/hello" ];
|
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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user