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)
| 24 | // is the config, and that the following len(RootFS) files are the layers, but that feels |
| 25 | // way too brittle.) |
| 26 | func 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. |
no test coverage detected
searching dependent graphs…