Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 40be1827ee6f
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 86f8732194f2
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 30, 2020

  1. dockerTools.buildLayeredImage: fix image with only 2 layers

    A test is also added to ensure an image with 2 layers can be built.
    nlewo committed Jan 30, 2020
    Copy the full SHA
    283bcc1 View commit details
  2. dockerTools.buildLayeredImage: assert maxLayers > 1

    Since a layer is reserved for "customization", the image can not
    contains less than 2 layers.
    
    The user gets the following message at evaluation:
    
        nix-instantiate nixos/tests/docker-tools.nix
        trace: the maxLayers argument of dockerTools.buildLayeredImage function must be greather than 1 (current value: 1)
    nlewo committed Jan 30, 2020
    Copy the full SHA
    01a6847 View commit details
  3. Merge pull request #78834 from nlewo/fix-two-layers-image

    Fix dockerTools.buildLayerImage with 2 layers
    nlewo authored Jan 30, 2020
    Copy the full SHA
    86f8732 View commit details
Showing with 17 additions and 2 deletions.
  1. +3 −0 nixos/tests/docker-tools.nix
  2. +6 −2 pkgs/build-support/docker/default.nix
  3. +8 −0 pkgs/build-support/docker/examples.nix
3 changes: 3 additions & 0 deletions nixos/tests/docker-tools.nix
Original file line number Diff line number Diff line change
@@ -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}'");
'';
})
8 changes: 6 additions & 2 deletions pkgs/build-support/docker/default.nix
Original file line number Diff line number Diff line change
@@ -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 {
8 changes: 8 additions & 0 deletions pkgs/build-support/docker/examples.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}