MCPcopy Create free account
hub / github.com/containers/image / newImageSource

Function newImageSource

docker/daemon/daemon_src.go:26–50  ·  view source on GitHub ↗

newImageSource returns a types.ImageSource for the specified image reference. The caller must call .Close() on the returned ImageSource. It would be great if we were able to stream the input tar as it is being sent; but Docker sends the top-level manifest, which determines which paths to look for,

(ctx context.Context, sys *types.SystemContext, ref daemonReference)

Source from the content-addressed store, hash-verified

24// is the config, and that the following len(RootFS) files are the layers, but that feels
25// way too brittle.)
26func newImageSource(ctx context.Context, sys *types.SystemContext, ref daemonReference) (private.ImageSource, error) {
27 c, err := newDockerClient(sys)
28 if err != nil {
29 return nil, fmt.Errorf("initializing docker engine client: %w", err)
30 }
31 defer c.Close()
32
33 // Per NewReference(), ref.StringWithinTransport() is either an image ID (config digest), or a !reference.NameOnly() reference.
34 // Either way ImageSave should create a tarball with exactly one image.
35 inputStream, err := c.ImageSave(ctx, []string{ref.StringWithinTransport()})
36 if err != nil {
37 return nil, fmt.Errorf("loading image from docker engine: %w", err)
38 }
39 defer inputStream.Close()
40
41 archive, err := tarfile.NewReaderFromStream(sys, inputStream)
42 if err != nil {
43 return nil, err
44 }
45 src := tarfile.NewSource(archive, true, ref.Transport().Name(), nil, -1)
46 return &daemonImageSource{
47 ref: ref,
48 Source: src,
49 }, nil
50}
51
52// Reference returns the reference used to set up this source, _as specified by the user_
53// (not as the image itself, or its underlying storage, claims). This can be used e.g. to determine which public keys are trusted for this image.

Callers 1

NewImageSourceMethod · 0.70

Calls 7

NewReaderFromStreamFunction · 0.92
NewSourceFunction · 0.92
newDockerClientFunction · 0.70
CloseMethod · 0.65
StringWithinTransportMethod · 0.65
NameMethod · 0.65
TransportMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…