git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/docker-tools: add test for pre-runAsRoot layer unpack order
commit57718902e34486288f63760faddda49ce2eecbdb authorAndrew Brooks <andrewgrantbrooks@gmail.com> dateFri 17 Dec 2021, 19:26 (5 years ago) parent69ffb00
2 files changed+29
nixos/tests/docker-tools.nix+6 pkgs/build-support/docker/examples.nix+23
nixos/tests/docker-tools.nix+6
@@ -215,6 +215,12 @@ import ./make-test-python.nix ({ pkgs, ... }: {
215215 f"docker run --rm ${examples.layersOrder.imageName} cat /tmp/layer{index}"
216216 )
217217
218+ with subtest("Ensure layers unpacked in correct order before runAsRoot runs"):
219+ assert "abc" in docker.succeed(
220+ "docker load --input='${examples.layersUnpackOrder}'",
221+ "docker run --rm ${examples.layersUnpackOrder.imageName} cat /layer-order"
222+ )
223+
218224 with subtest("Ensure environment variables are correctly inherited"):
219225 docker.succeed(
220226 "docker load --input='${examples.environmentVariables}'"
pkgs/build-support/docker/examples.nix+23
@@ -405,6 +405,29 @@ rec {
405405 created = "now";
406406 };
407407
408+ # 23. Ensure that layers are unpacked in the correct order before the
409+ # runAsRoot script is executed.
410+ layersUnpackOrder =
411+ let
412+ layerOnTopOf = parent: layerName:
413+ pkgs.dockerTools.buildImage {
414+ name = "layers-unpack-order-${layerName}";
415+ tag = "latest";
416+ fromImage = parent;
417+ contents = [ pkgs.coreutils ];
418+ runAsRoot = ''
419+ #!${pkgs.runtimeShell}
420+ echo -n "${layerName}" >> /layer-order
421+ '';
422+ };
423+ # When executing the runAsRoot script when building layer C, if layer B is
424+ # not unpacked on top of layer A, the contents of /layer-order will not be
425+ # "ABC".
426+ layerA = layerOnTopOf null "a";
427+ layerB = layerOnTopOf layerA "b";
428+ layerC = layerOnTopOf layerB "c";
429+ in layerC;
430+
408431 # buildImage without explicit tag
409432 bashNoTag = pkgs.dockerTools.buildImage {
410433 name = "bash-no-tag";