From aedc651903e3b20514c2fda056ff0bc9124b4d5d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Thu, 20 Sep 2018 13:02:22 -0400 Subject: [PATCH] dockerTools.buildImage: test that created=now makes an unstable date --- nixos/tests/docker-tools.nix | 7 +++++++ pkgs/build-support/docker/examples.nix | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/nixos/tests/docker-tools.nix b/nixos/tests/docker-tools.nix index db4eacc37287..5a7590cbf364 100644 --- a/nixos/tests/docker-tools.nix +++ b/nixos/tests/docker-tools.nix @@ -20,7 +20,10 @@ import ./make-test.nix ({ pkgs, ... }: { '' $docker->waitForUnit("sockets.target"); + # Ensure Docker images use a stable date by default $docker->succeed("docker load --input='${pkgs.dockerTools.examples.bash}'"); + $docker->succeed("[ '1970-01-01T00:00:01Z' = \"\$(docker inspect ${pkgs.dockerTools.examples.bash.imageName} | ${pkgs.jq}/bin/jq -r .[].Created)\" ]"); + $docker->succeed("docker run --rm ${pkgs.dockerTools.examples.bash.imageName} bash --version"); $docker->succeed("docker rmi ${pkgs.dockerTools.examples.bash.imageName}"); @@ -51,5 +54,9 @@ import ./make-test.nix ({ pkgs, ... }: { $docker->succeed("docker run --rm runasrootextracommands cat extraCommands"); $docker->succeed("docker run --rm runasrootextracommands cat runAsRoot"); $docker->succeed("docker rmi '${pkgs.dockerTools.examples.runAsRootExtraCommands.imageName}'"); + + # Ensure Docker images can use an unstable date + $docker->succeed("docker load --input='${pkgs.dockerTools.examples.bash}'"); + $docker->succeed("[ '1970-01-01T00:00:01Z' != \"\$(docker inspect ${pkgs.dockerTools.examples.unstableDate.imageName} | ${pkgs.jq}/bin/jq -r .[].Created)\" ]"); ''; }) diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix index ec2667310cdd..822e0dbb31f2 100644 --- a/pkgs/build-support/docker/examples.nix +++ b/pkgs/build-support/docker/examples.nix @@ -141,4 +141,13 @@ rec { runAsRoot = ''echo "(runAsRoot)" > runAsRoot''; extraCommands = ''echo "(extraCommand)" > extraCommands''; }; + + # 9. Ensure that setting created to now results in a date which + # isn't the epoch + 1 + unstableDate = pkgs.dockerTools.buildImage { + name = "unstable-date"; + tag = "latest"; + contents = [ pkgs.coreutils ]; + created = "now"; + }; }