Merge pull request #80102 from nlewo/fix-78744

dockerTools.buildLayeredImage: store all paths passed in final layer (fix 78744)
This commit is contained in:
lewo 2020-02-14 09:48:52 +01:00 committed by GitHub
commit d49804cf45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 11 deletions

View File

@ -83,5 +83,11 @@ import ./make-test.nix ({ pkgs, ... }: {
# Ensure image with only 2 layers can be loaded
$docker->succeed("docker load --input='${pkgs.dockerTools.examples.two-layered-image}'");
# Ensure the bulk layer didn't miss store paths
# Regression test for https://github.com/NixOS/nixpkgs/issues/78744
$docker->succeed("docker load --input='${pkgs.dockerTools.examples.bulk-layer}'");
# This ensure the two output paths (ls and hello) are in the layer
$docker->succeed("docker run bulk-layer ls /bin/hello");
'';
})

View File

@ -246,4 +246,16 @@ rec {
contents = [ pkgs.bash pkgs.hello ];
maxLayers = 2;
};
# 16. Create a layered image with more packages than max layers.
# coreutils and hello are part of the same layer
bulk-layer = pkgs.dockerTools.buildLayeredImage {
name = "bulk-layer";
tag = "latest";
contents = with pkgs; [
coreutils hello
];
maxLayers = 2;
};
}

View File

@ -5,11 +5,8 @@ set -eu
layerNumber=$1
shift
storePath="$1"
shift
layerPath="./layers/$layerNumber"
echo "Creating layer #$layerNumber for $storePath"
echo "Creating layer #$layerNumber for $@"
mkdir -p "$layerPath"
@ -35,13 +32,15 @@ tar -cf "$layerPath/layer.tar" \
# to /nix/store. In order to create the correct structure
# in the tar file, we transform the relative nix store
# path to the absolute store path.
n=$(basename "$storePath")
tar -C /nix/store -rpf "$layerPath/layer.tar" \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="s,$n,/nix/store/$n," \
$n
for storePath in "$@"; do
n=$(basename "$storePath")
tar -C /nix/store -rpf "$layerPath/layer.tar" \
--hard-dereference --sort=name \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 --group=0 \
--transform="s,$n,/nix/store/$n," \
$n
done
# Compute a checksum of the tarball.
tarhash=$(tarsum < $layerPath/layer.tar)