diff options
author | Antoine Eiche <lewo@abesis.fr> | 2020-01-30 10:42:13 +0100 |
---|---|---|
committer | Antoine Eiche <lewo@abesis.fr> | 2020-01-30 21:09:44 +0100 |
commit | 283bcc1003c9cdabbbbe8d117b66d8dec6b46af9 (patch) | |
tree | fcc270aad6c6dcd94d2aaf93510f1dbde3d862a6 /pkgs/build-support/docker | |
parent | 8539d5f48f9de4ba428d2ca6687712db1d9cb2b7 (diff) |
dockerTools.buildLayeredImage: fix image with only 2 layers
A test is also added to ensure an image with 2 layers can be built.
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r-- | pkgs/build-support/docker/default.nix | 5 | ||||
-rw-r--r-- | pkgs/build-support/docker/examples.nix | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 3fcae13e20d7..9f831d48bfa1 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -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 diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index d7d1a6933100..a1f71d35793c 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -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; + }; } |