From 57718902e34486288f63760faddda49ce2eecbdb Mon Sep 17 00:00:00 2001 From: Andrew Brooks Date: Fri, 17 Dec 2021 19:26:53 -0600 Subject: nixos/tests/docker-tools: add test for pre-runAsRoot layer unpack order --- pkgs/build-support/docker/examples.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'pkgs/build-support/docker') diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index f2d4f809ae4..941ee048666 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -405,6 +405,29 @@ rec { created = "now"; }; + # 23. Ensure that layers are unpacked in the correct order before the + # runAsRoot script is executed. + layersUnpackOrder = + let + layerOnTopOf = parent: layerName: + pkgs.dockerTools.buildImage { + name = "layers-unpack-order-${layerName}"; + tag = "latest"; + fromImage = parent; + contents = [ pkgs.coreutils ]; + runAsRoot = '' + #!${pkgs.runtimeShell} + echo -n "${layerName}" >> /layer-order + ''; + }; + # When executing the runAsRoot script when building layer C, if layer B is + # not unpacked on top of layer A, the contents of /layer-order will not be + # "ABC". + layerA = layerOnTopOf null "a"; + layerB = layerOnTopOf layerA "b"; + layerC = layerOnTopOf layerB "c"; + in layerC; + # buildImage without explicit tag bashNoTag = pkgs.dockerTools.buildImage { name = "bash-no-tag"; -- cgit 1.4.1