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.pullImage: Skopeo pulls images by digest #38371

Merged
merged 2 commits into from May 2, 2018

Conversation

nlewo
Copy link
Member

@nlewo nlewo commented Apr 3, 2018

[EDITED]

Skopeo is used to pull images from a Docker registry (instead of a
Docker daemon inside a VM).

An image reference is specified with its name, its digest. The digest is an immutable image identifier (unlike image name
and tag).

Skopeo can be used to get the Digest of an image, for instance:
skopeo inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest'

I still have to

  • update nixpkgs manual

but I would prefer to have some feedback first.

Note: six months ago, I already tryied to use Skopeo to pull images but these patches have been reverted because the Skopeo output format was not compliant with the Docker legacy format (it broke several script/tests). The latest Skoepo version is now compliant with it.
The onTopOfPulledImage docker test has been added to validate this change.

cc @Profpatsch @kuznero @gilligan

Motivation for this change

Remove VM needs and pull with digest. This also fixes #29271.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

# If the image digest is specified, the tag is only used at
# Docker image loading (to set a tag), ie. it is not used to
# pull the image (both digest and tag are not supported by
# Skopeo yet).
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we can’t fetch specific tags with this new implementation? Or does it mean you have to fetch the digest first and use that? What happens if the tag is set but the digest isn’t?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can still use image tags to pull images.
If the tag is set but the digest is not, the tag is used to pull the image.
But if you specify a digest and a tag, Skopeo ignores the tag to pull the image. In this case, the tag is just used at image creation.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, then it should really be ref (either a tag or a digest) and finalImageName ? ref (what the image is named). That way you don’t have to ignore user input silently.

Copy link
Member Author

Choose a reason for hiding this comment

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

The tag is only ignored to pull the image if a specified image digest doesn't match to the specified image tag. In this case, we could ensure the digest matches the expected tag by using skopeo inspect before pulling the image.

I would like to avoid to have to encode the attribute type (digest or tag) in the reference string. For the user, it is more convenient to just have to set an attribute named digest or tag instead of having to put a : or a @ in the image reference string.
Moreover, the tag is always required (even if digest is specified) to create the image.

Another way would be to create a pullImage that only use digest and a pullImageByTag function that could take different type of arguments.
I'm not sure if we have to let - forever - the user pull images with a tag since they are not immutable.

@nlewo nlewo changed the title [wip] dockerTools.pullImage: Skopeo pulls images with digest or tag [wip] dockerTools.pullImage: Skopeo pulls images with digest Apr 6, 2018
@nlewo nlewo changed the title [wip] dockerTools.pullImage: Skopeo pulls images with digest [wip] dockerTools.pullImage: Skopeo pulls images by digest Apr 6, 2018
@nlewo
Copy link
Member Author

nlewo commented Apr 6, 2018

@Profpatsch I've tryied to handle both tag and digest ID but I think pulling images by both tag and digest is too confusing. Moreover, it seems more Nix compliant to pull by digest which are immutable.
So, I pushed a new patch set where we can only pull by digest. What do you think about this?

@Profpatsch
Copy link
Member

I think that’s the way to go, yes.
Now all that’s missing is updating the relevant parts of the dockerTools manual section as far as I can see.

@gilligan
Copy link
Contributor

gilligan commented Apr 6, 2018

Nice, this PR is an improvement for sure. Thanks for the effort. Only documentation left :-)

@nlewo nlewo changed the title [wip] dockerTools.pullImage: Skopeo pulls images by digest dockerTools.pullImage: Skopeo pulls images by digest Apr 9, 2018
@Profpatsch
Copy link
Member

Docs diff looks fine. LGTM?

@nlewo
Copy link
Member Author

nlewo commented Apr 11, 2018

@GrahamcOfBorg test docker-tools

@GrahamcOfBorg
Copy link

Success on aarch64-linux

Attempted: tests.docker-tools

No partial log is available.

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: tests.docker-tools

Partial log (click to expand)

Cooking the image...
Finished.
building path(s) ‘/nix/store/lmvi5jy5m17ziy8hn38wgy9mgbwda5as-closure-info’
/nix/store/aj9rz4k3xvg8q9fzqfnb0q123707zp0n-builder: line 1: .attrs.sh: No such file or directory
builder for ‘/nix/store/9akbgyhsi7mzmq8lhgq0n3qjzlnspqlf-closure-info.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/7m2418fiibkyh1xl5wxla54rpgh29jdy-run-nixos-vm.drv’: 1 dependencies couldn't be built
cannot build derivation ‘/nix/store/18ak37v1wijghbwlradm8yx7fz73ycc4-nixos-vm.drv’: 1 dependencies couldn't be built
cannot build derivation ‘/nix/store/lwqxzlhgjai7cwps2l9vmq6r9f644kpi-nixos-test-driver-docker-tools.drv’: 3 dependencies couldn't be built
cannot build derivation ‘/nix/store/ppk5jlmj0gf8n9r6lclk78xv0ihc0w6v-vm-test-run-docker-tools.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/ppk5jlmj0gf8n9r6lclk78xv0ihc0w6v-vm-test-run-docker-tools.drv’ failed

@nlewo
Copy link
Member Author

nlewo commented Apr 13, 2018

@GrahamcOfBorg test docker-tools

@GrahamcOfBorg
Copy link

No attempt on x86_64-linux (full log)

The following builds were skipped because they don't evaluate on x86_64-linux: tests.docker-tools

Partial log (click to expand)

while evaluating ‘hydraJob’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/lib/customisation.nix:162:14, called from /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/nixos/release.nix:23:16:
while evaluating the attribute ‘drvPath’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/lib/customisation.nix:179:13:
while evaluating the attribute ‘drvPath’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/lib/customisation.nix:146:13:
while evaluating the attribute ‘buildCommand’ of the derivation ‘vm-test-run-docker-tools’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘buildCommand’ of the derivation ‘nixos-test-driver-docker-tools’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘buildCommand’ of the derivation ‘nixos-vm’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘text’ of the derivation ‘run-nixos-vm’ at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating anonymous function at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/build-support/closure-info.nix:9:1, called from /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/nixos/modules/virtualisation/qemu-vm.nix:105:13:
assertion failed at /home/ofborg/ofborg2/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/builder-7c6f434c2/pkgs/build-support/closure-info.nix:11:1

@GrahamcOfBorg
Copy link

Success on aarch64-linux

Attempted: tests.docker-tools

No partial log is available.

@nlewo
Copy link
Member Author

nlewo commented Apr 14, 2018

@grahamc it seems like the ofborg builder is using Nix1 (assert builtins.langVersion >= 5; is failing). I'm surprised since I'm pretty sure I already used ofborg to run Nixos 18.03 tests. Do you know what is happening?

@nlewo
Copy link
Member Author

nlewo commented Apr 14, 2018

Test failure is not related to this PR. I locally ran docker-tools tests which succeeded.

@nlewo
Copy link
Member Author

nlewo commented Apr 20, 2018

I would have liked more feedback on this... since my last attempt has been reverted!
@Mic92 @puffnfresh @globin WDYT?

Copy link
Contributor

@puffnfresh puffnfresh left a comment

Choose a reason for hiding this comment

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

There's also https://github.com/awakesecurity/hocker - how does that compare to Skopeo?

# this hash will need change if the tag is updated at docker hub
sha256 = "0nncn9pn5miygan51w34c2p9qssi96jgsaqv44dxxdprc8pg0g83";
imageDigest = "sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b";
sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8";
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have a release note for if hashes changes.

Copy link
Member

Choose a reason for hiding this comment

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

see nixpkgs/nixos/doc/manual/release-notes/rl-1809.xml

@@ -77,6 +77,8 @@ following incompatible changes:</para>
<itemizedlist>
<listitem>
<para>
<literal>dockerTools.pullImage</literal> relies on image digest
instead of image tag to download the image.
Copy link
Member

Choose a reason for hiding this comment

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

Ok this was already done. It should also mention that hashes will change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Profpatsch
Copy link
Member

@puffnfresh See https://nixos.wiki/wiki/Workgroup:Container for a short synopsis on many relevant tools.

@puffnfresh
Copy link
Contributor

@Profpatsch really cool, thank you!

@nlewo
Copy link
Member Author

nlewo commented Apr 23, 2018

@puffnfresh Skopeo is not related to Nix. It is used by many others project to manipulate container images (Docker, OCI, ...) across container image registries. One advantages of Hocker is that each layer is stored in the Nix store. This means if several images shares the same layer, it only exists one time. This is not currently the case with our implementation of pullImage, but I would like to also provide this with Skopeo (it can pull layer one per one).

nlewo added 2 commits May 2, 2018 18:05
Skopeo is used to pull images from a Docker registry (instead of a
Docker deamon in a VM).

An image reference is specified with its name and its digest which is
an immutable image identifier (unlike image name and tag).

Skopeo can be used to get the digest of an image, for instance:
$ skopeo inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest'
@nlewo
Copy link
Member Author

nlewo commented May 2, 2018

@Mic92 @Profpatsch Does this PR look good to you?

@globin globin merged commit d35dcb1 into NixOS:master May 2, 2018
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.

dockerTools.pullImage fails to pull image when behind corporate proxy
7 participants