Skip to content

Conversation

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Oct 1, 2022

Fetching blobs without foreknown descriptors is useful for using a registry as a general-purpose CAS.

Related: oras blob fetch (ORAS v0.15.0)

Go interface

readCloser, incompleteDesc, err := fetcher.(remotes.FetcherByDigest).FetchByDigest(ctx, dgst)

ctr command

$ ctr content fetch-blob docker.io/library/debian:latest sha256:43d28810c1b4c28a1be3bac8e0e40fcc472b2bfcfcda952544ed99cb874d2b1a

{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["bash"],"Image":"sha256:357a26ba6784f85d683e053559f71c9c8783306e53526fbe8c481eb203845b22","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"926ed85caba06d6ce5919fdab3eae1de98be1fddf12f7126bdcbcc79840861d5","container_config":{"Hostname":"926ed85caba0","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","CMD [\"bash\"]"],"Image":"sha256:357a26ba6784f85d683e053559f71c9c8783306e53526fbe8c481eb203845b22","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"created":"2022-09-13T00:56:19.369186372Z","docker_version":"20.10.12","history":[{"created":"2022-09-13T00:56:18.878860216Z","created_by":"/bin/sh -c #(nop) ADD file:ff01c6dedb67cf22e9b0735e099b9b6367770c4880941862cc7ec0e979b4118b in / "},{"created":"2022-09-13T00:56:19.369186372Z","created_by":"/bin/sh -c #(nop)  CMD [\"bash\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:b9fcb0f781e4bcde2c9f7f27cb93c549f6c6ecfdc7fdcc783813347e97faf19c"]}}

The tag part in the ref string is dummy, so ctr content fetch-blob docker.io/library/debian:dummy@sha256:0000000000000000000000000000000000000000000000000000000000000000 sha256:43d28810c1b4c28a1be3bac8e0e40fcc472b2bfcfcda952544ed99cb874d2b1a returns the same result too.

@AkihiroSuda AkihiroSuda changed the title remotes: add FetcherByDigest for fetching blobs without foreknown descriptors remotes: add FetcherByDigest for fetching blobs without foreknown descriptors (useful for general-purpose CAS) Oct 1, 2022
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

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

LGTM. Not merging immediately since I think @dmcgowan might have thoughts on this too.

@AkihiroSuda AkihiroSuda force-pushed the fetch-by-digest branch 2 times, most recently from 0fd4097 to a15d6d6 Compare October 7, 2022 08:45
@AkihiroSuda
Copy link
Member Author

// FetcherByDigest fetches content by the digest.
type FetcherByDigest interface {
// FetchByDigest the resource identified by the digest.
FetchByDigest(ctx context.Context, dgst digest.Digest) (io.ReadCloser, int64, error)
Copy link
Member

Choose a reason for hiding this comment

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

Returning ocispec.Descriptor would be useful here over just int64. The media type could always be application/octet-stream since it was not fetched with any known/trusted context. Annotations could also be set to include the media type returned by the registry. Generally though we use the Descriptor type for blob metadata, I don't lacking a media types makes that less useful here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to return the desc with application/octet-stream

@dmcgowan dmcgowan self-assigned this Oct 27, 2022
@dmcgowan dmcgowan added this to the 1.7 milestone Oct 27, 2022
@AkihiroSuda AkihiroSuda requested a review from dmcgowan November 2, 2022 05:31
…criptors

Fetching blobs without foreknown descriptors is useful for using a registry as a general-purpose CAS.

Related: `oras blob fetch` (ORAS v0.15.0)

Signed-off-by: Akihiro Suda <[email protected]>
e.g., `ctr content fetch-blob docker.io/library/debian:latest sha256:43d28810c1b4c28a1be3bac8e0e40fcc472b2bfcfcda952544ed99cb874d2b1a`

Signed-off-by: Akihiro Suda <[email protected]>
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.

5 participants