Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerTools.buildLayeredImage: fix created=now #92692

Merged
merged 1 commit into from Jul 10, 2020

Conversation

c0deaddict
Copy link
Member

Motivation for this change

Building a layered docker image with created = "now"; like so:

with import <nixpkgs> {};

pkgs.dockerTools.buildLayeredImage {
  name = "k8s-deployer";
  tag = "latest";
  created = "now";
  # ...
}

Fails with error:

these derivations will be built:
  /nix/store/w9bis8iriida0vj9ybfnlwd5yskzwj6k-k8s-deployer.tar.gz.drv
building '/nix/store/w9bis8iriida0vj9ybfnlwd5yskzwj6k-k8s-deployer.tar.gz.drv'...
Traceback (most recent call last):
  File "/nix/store/n59sj4r1rr1f6411wbsr1nx6zz33pq47-stream", line 309, in <module>
    main()
  File "/nix/store/n59sj4r1rr1f6411wbsr1nx6zz33pq47-stream", line 245, in main
    datetime.now(tz=datetime.timezone.utc)
AttributeError: type object 'datetime.datetime' has no attribute 'timezone'
builder for '/nix/store/w9bis8iriida0vj9ybfnlwd5yskzwj6k-k8s-deployer.tar.gz.drv' failed with exit code 1

timezone should be imported from datetime, not from datetime.datetime.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@utdemir
Copy link
Member

utdemir commented Jul 8, 2020

Thank you! The change looks good to me, but could you add a new test for this case to prevent future regressions?

@c0deaddict c0deaddict force-pushed the fix/docker-layer-created-now branch 2 times, most recently from 018a1f8 to 8827a10 Compare July 9, 2020 06:51
@ofborg ofborg bot added the 6.topic: nixos label Jul 9, 2020
@c0deaddict c0deaddict force-pushed the fix/docker-layer-created-now branch from 8827a10 to 6673716 Compare July 9, 2020 07:34
@c0deaddict
Copy link
Member Author

Ok, that was a fun exercise. NixOS tests are quite nice, now that they are written in Python :)

Found another error with the test: the literal string "now" was inserted into the history of layers:

docker: must succeed: docker load --input='/nix/store/i9ih65478lvjjx5kwcfzjpirv2vcxrv2-unstable-layered-date.tar.gz'
docker # parsing time ""now"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "now"" as "2006"
docker: output:
Test "Ensure Layered Docker images can use an unstable date" failed with error: "command `docker load --input='/nix/store/i9ih65478lvjjx5kwcfzjpirv2vcxrv2-unstable-layered-date.tar.gz'` failed (exit code 1)"
error:
Traceback (most recent call last):
  File "/nix/store/bsdhs1krl3xc7xni887r67dnq0078f2y-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 894, in run_tests
    exec(tests, globals())
  File "<string>", line 1, in <module>
  File "<string>", line 83, in <module>
  File "/nix/store/bsdhs1krl3xc7xni887r67dnq0078f2y-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 421, in succeed
    raise Exception(
Exception: command `docker load --input='/nix/store/i9ih65478lvjjx5kwcfzjpirv2vcxrv2-unstable-layered-date.tar.gz'` failed (exit code 1)

Also noticed that the unstableDate test was not testing the right image, correct that and verified that uncommenting created="now" in unstableDate now fails the test (as it should).

Copy link
Member

@utdemir utdemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @c0deaddict , that's great! Good job noticing the previous typo too.

@utdemir
Copy link
Member

utdemir commented Jul 10, 2020

Hey @marsam . Thanks for bringing this PR to my attention. I think this is ready to merge, but I do not have commit rights. Would you mind taking a final look at it?

@marsam
Copy link
Contributor

marsam commented Jul 10, 2020

Sure, thank you both for working on this!
@GrahamcOfBorg test docker-tools

@marsam marsam merged commit 926e93b into NixOS:master Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants