Merge pull request #92692 from c0deaddict/fix/docker-layer-created-now

dockerTools.buildLayeredImage: fix created=now
This commit is contained in:
Mario Rodas 2020-07-10 00:05:35 -05:00 committed by GitHub
commit 926e93be73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"):
docker.succeed(
"docker load --input='${examples.bash}'"
"docker load --input='${examples.unstableDate}'"
)
assert unix_time_second1 not in docker.succeed(
"docker inspect ${examples.unstableDate.imageName} "
+ "| ${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"):
docker.succeed(
"docker load --input='${examples.layered-image}'",

View File

@ -354,4 +354,14 @@ rec {
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 itertools
import threading
from datetime import datetime
from datetime import datetime, timezone
from collections import namedtuple
@ -242,7 +242,7 @@ def main():
conf = json.load(f)
created = (
datetime.now(tz=datetime.timezone.utc)
datetime.now(tz=timezone.utc)
if conf["created"] == "now"
else datetime.fromisoformat(conf["created"])
)
@ -280,7 +280,7 @@ def main():
},
"history": [
{
"created": conf["created"],
"created": datetime.isoformat(created),
"comment": f"store paths: {layer.paths}"
}
for layer in layers