nixos/tests/docker-tools: add test for pre-runAsRoot layer unpack order

This commit is contained in:
Andrew Brooks 2021-12-17 19:26:53 -06:00
parent 69ffb0004a
commit 57718902e3
2 changed files with 29 additions and 0 deletions

View file

@ -215,6 +215,12 @@ import ./make-test-python.nix ({ pkgs, ... }: {
f"docker run --rm ${examples.layersOrder.imageName} cat /tmp/layer{index}"
)
with subtest("Ensure layers unpacked in correct order before runAsRoot runs"):
assert "abc" in docker.succeed(
"docker load --input='${examples.layersUnpackOrder}'",
"docker run --rm ${examples.layersUnpackOrder.imageName} cat /layer-order"
)
with subtest("Ensure environment variables are correctly inherited"):
docker.succeed(
"docker load --input='${examples.environmentVariables}'"

View file

@ -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";