dockerTools.buildLayeredImage: fix created=now

This commit is contained in:
Jos van Bakel 2020-07-09 09:34:18 +02:00
parent 0dbc88331f
commit 66737168a4
No known key found for this signature in database
GPG Key ID: 37589FBAE4DA2BC3
3 changed files with 23 additions and 4 deletions

View File

@ -90,13 +90,22 @@ import ./make-test-python.nix ({ pkgs, ... }: {
with subtest("Ensure Docker images can use an unstable date"): with subtest("Ensure Docker images can use an unstable date"):
docker.succeed( docker.succeed(
"docker load --input='${examples.bash}'" "docker load --input='${examples.unstableDate}'"
) )
assert unix_time_second1 not in docker.succeed( assert unix_time_second1 not in docker.succeed(
"docker inspect ${examples.unstableDate.imageName} " "docker inspect ${examples.unstableDate.imageName} "
+ "| ${pkgs.jq}/bin/jq -r .[].Created" + "| ${pkgs.jq}/bin/jq -r .[].Created"
) )
with subtest("Ensure Layered Docker images can use an unstable date"):
docker.succeed(
"docker load --input='${examples.unstableDateLayered}'"
)
assert unix_time_second1 not in docker.succeed(
"docker inspect ${examples.unstableDateLayered.imageName} "
+ "| ${pkgs.jq}/bin/jq -r .[].Created"
)
with subtest("Ensure Layered Docker images work"): with subtest("Ensure Layered Docker images work"):
docker.succeed( docker.succeed(
"docker load --input='${examples.layered-image}'", "docker load --input='${examples.layered-image}'",

View File

@ -354,4 +354,14 @@ rec {
Env = [ "USER=root" ]; Env = [ "USER=root" ];
}; };
}; };
# 20. Ensure that setting created to now results in a date which
# isn't the epoch + 1 for layered images.
unstableDateLayered = pkgs.dockerTools.buildLayeredImage {
name = "unstable-date-layered";
tag = "latest";
contents = [ pkgs.coreutils ];
created = "now";
};
} }

View File

@ -41,7 +41,7 @@ import pathlib
import tarfile import tarfile
import itertools import itertools
import threading import threading
from datetime import datetime from datetime import datetime, timezone
from collections import namedtuple from collections import namedtuple
@ -242,7 +242,7 @@ def main():
conf = json.load(f) conf = json.load(f)
created = ( created = (
datetime.now(tz=datetime.timezone.utc) datetime.now(tz=timezone.utc)
if conf["created"] == "now" if conf["created"] == "now"
else datetime.fromisoformat(conf["created"]) else datetime.fromisoformat(conf["created"])
) )
@ -280,7 +280,7 @@ def main():
}, },
"history": [ "history": [
{ {
"created": conf["created"], "created": datetime.isoformat(created),
"comment": f"store paths: {layer.paths}" "comment": f"store paths: {layer.paths}"
} }
for layer in layers for layer in layers