dockerTools: Always set imageTag attribute

The image tag can be specified or generated from the output hash.
Previously, a generated tag could be recovered from the evaluated
image with some string operations.

However, with the introduction of streamLayeredImage, it's not
feasible to compute the generated tag yourself.

With this change, the imageTag attribute is set unconditionally,
for the buildImage, buildLayeredImage, streamLayeredImage functions.
This commit is contained in:
Robert Hensing 2020-07-11 15:51:58 +02:00
parent c87c474b17
commit 8c0459f611
3 changed files with 67 additions and 0 deletions

View file

@ -30,8 +30,45 @@ import ./make-test-python.nix ({ pkgs, ... }: {
)
docker.succeed("docker run --rm ${examples.bash.imageName} bash --version")
# Check imageTag attribute matches image
docker.succeed("docker images --format '{{.Tag}}' | grep -F '${examples.bash.imageTag}'")
docker.succeed("docker rmi ${examples.bash.imageName}")
# The remaining combinations
with subtest("Ensure imageTag attribute matches image"):
docker.succeed(
"docker load --input='${examples.bashNoTag}'"
)
docker.succeed(
"docker images --format '{{.Tag}}' | grep -F '${examples.bashNoTag.imageTag}'"
)
docker.succeed("docker rmi ${examples.bashNoTag.imageName}:${examples.bashNoTag.imageTag}")
docker.succeed(
"docker load --input='${examples.bashNoTagLayered}'"
)
docker.succeed(
"docker images --format '{{.Tag}}' | grep -F '${examples.bashNoTagLayered.imageTag}'"
)
docker.succeed("docker rmi ${examples.bashNoTagLayered.imageName}:${examples.bashNoTagLayered.imageTag}")
docker.succeed(
"${examples.bashNoTagStreamLayered} | docker load"
)
docker.succeed(
"docker images --format '{{.Tag}}' | grep -F '${examples.bashNoTagStreamLayered.imageTag}'"
)
docker.succeed(
"docker rmi ${examples.bashNoTagStreamLayered.imageName}:${examples.bashNoTagStreamLayered.imageTag}"
)
docker.succeed(
"docker load --input='${examples.nixLayered}'"
)
docker.succeed("docker images --format '{{.Tag}}' | grep -F '${examples.nixLayered.imageTag}'")
docker.succeed("docker rmi ${examples.nixLayered.imageName}")
with subtest(
"Check if the nix store is correctly initialized by listing "
"dependencies of the installed Nix binary"

View file

@ -442,6 +442,7 @@ rec {
in
runCommand "${name}.tar.gz" {
inherit (stream) imageName;
passthru = { inherit (stream) imageTag; };
buildInputs = [ pigz ];
} "${stream} | pigz -nT > $out";
@ -517,6 +518,11 @@ rec {
layerClosure = writeReferencesToFile layer;
passthru.buildArgs = args;
passthru.layer = layer;
passthru.imageTag =
if tag != null
then lib.toLower tag
else
lib.head (lib.strings.splitString "-" (baseNameOf result.outPath));
# Docker can't be made to run darwin binaries
meta.badPlatforms = lib.platforms.darwin;
} ''
@ -737,6 +743,11 @@ rec {
conf = runCommand "${name}-conf.json" {
inherit maxLayers created;
imageName = lib.toLower name;
passthru.imageTag =
if tag != null
then tag
else
lib.head (lib.strings.splitString "-" (baseNameOf conf.outPath));
paths = referencesByPopularity overallClosure;
buildInputs = [ jq ];
} ''
@ -792,6 +803,7 @@ rec {
'';
result = runCommand "stream-${name}" {
inherit (conf) imageName;
passthru = { inherit (conf) imageTag; };
buildInputs = [ makeWrapper ];
} ''
makeWrapper ${streamScript} $out --add-flags ${conf}

View file

@ -364,4 +364,22 @@ rec {
created = "now";
};
# buildImage without explicit tag
bashNoTag = pkgs.dockerTools.buildImage {
name = "bash-no-tag";
contents = pkgs.bashInteractive;
};
# buildLayeredImage without explicit tag
bashNoTagLayered = pkgs.dockerTools.buildLayeredImage {
name = "bash-no-tag-layered";
contents = pkgs.bashInteractive;
};
# buildImage without explicit tag
bashNoTagStreamLayered = pkgs.dockerTools.streamLayeredImage {
name = "bash-no-tag-stream-layered";
contents = pkgs.bashInteractive;
};
}