From f73a0793528c57c85fd7737317ee1293c336c774 Mon Sep 17 00:00:00 2001 From: Jonas Fierlings Date: Wed, 28 Feb 2024 12:06:56 +0100 Subject: [PATCH 1/2] dockerTools: Test changing compression of `buildLayeredImage` --- nixos/tests/docker-tools.nix | 8 ++++++++ pkgs/build-support/docker/examples.nix | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nixos/tests/docker-tools.nix b/nixos/tests/docker-tools.nix index 7d91076600f9..c8a227eb2cf7 100644 --- a/nixos/tests/docker-tools.nix +++ b/nixos/tests/docker-tools.nix @@ -178,6 +178,14 @@ in { "docker load --input='${examples.bashUncompressed}'", "docker rmi ${examples.bashUncompressed.imageName}", ) + docker.succeed( + "docker load --input='${examples.bashLayeredUncompressed}'", + "docker rmi ${examples.bashLayeredUncompressed.imageName}", + ) + docker.succeed( + "docker load --input='${examples.bashLayeredZstdCompressed}'", + "docker rmi ${examples.bashLayeredZstdCompressed.imageName}", + ) with subtest( "Check if the nix store is correctly initialized by listing " diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 72c1cbe0d410..52706ef6b21f 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -509,7 +509,23 @@ rec { contents = pkgs.bashInteractive; }; - # buildImage without explicit tag + # buildLayeredImage without compression + bashLayeredUncompressed = pkgs.dockerTools.buildLayeredImage { + name = "bash-layered-uncompressed"; + tag = "latest"; + compressor = "none"; + contents = pkgs.bashInteractive; + }; + + # buildLayeredImage with zstd compression + bashLayeredZstdCompressed = pkgs.dockerTools.buildLayeredImage { + name = "bash-layered-zstd"; + tag = "latest"; + compressor = "zstd"; + contents = pkgs.bashInteractive; + }; + + # streamLayeredImage without explicit tag bashNoTagStreamLayered = pkgs.dockerTools.streamLayeredImage { name = "bash-no-tag-stream-layered"; contents = pkgs.bashInteractive; From f4871a62d2dcf5e580dcd565a10ebb1ff14b3c9b Mon Sep 17 00:00:00 2001 From: Jonas Fierlings Date: Wed, 28 Feb 2024 12:13:58 +0100 Subject: [PATCH 2/2] dockerTools: Do not pass `compressor` to `streamLayeredImage` --- pkgs/build-support/docker/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 0583f522bda3..e88f88546dbf 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -517,7 +517,7 @@ rec { buildLayeredImage = lib.makeOverridable ({ name, compressor ? "gz", ... }@args: let - stream = streamLayeredImage args; + stream = streamLayeredImage (builtins.removeAttrs args ["compressor"]); compress = compressorForImage compressor name; in runCommand "${baseNameOf name}.tar${compress.ext}" @@ -1286,7 +1286,7 @@ rec { # Wrapper around streamNixShellImage to build an image from the result buildNixShellImage = { drv, compressor ? "gz", ... }@args: let - stream = streamNixShellImage args; + stream = streamNixShellImage (builtins.removeAttrs args ["compressor"]); compress = compressorForImage compressor drv.name; in runCommand "${drv.name}-env.tar${compress.ext}"