diff --git a/nixos/tests/docker-tools.nix b/nixos/tests/docker-tools.nix index ad734a71f01f..21512be201a3 100644 --- a/nixos/tests/docker-tools.nix +++ b/nixos/tests/docker-tools.nix @@ -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}'", diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index 068daa8df722..81dae9b61241 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -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"; + }; + } diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py index 9a13878a783d..8ffd336fce49 100644 --- a/pkgs/build-support/docker/stream_layered_image.py +++ b/pkgs/build-support/docker/stream_layered_image.py @@ -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