Import imports an image from a Tar stream using reader. Caller needs to specify importer. Future version may use oci.v1 as the default. Note that unreferenced blobs may be imported to the content store as well.
(ctx context.Context, reader io.Reader, opts ...ImportOpt)
| 147 | // Caller needs to specify importer. Future version may use oci.v1 as the default. |
| 148 | // Note that unreferenced blobs may be imported to the content store as well. |
| 149 | func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt) ([]images.Image, error) { |
| 150 | var iopts importOpts |
| 151 | for _, o := range opts { |
| 152 | if err := o(&iopts); err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | ctx, done, err := c.WithLease(ctx) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | defer done(ctx) |
| 162 | |
| 163 | var aio []archive.ImportOpt |
| 164 | if iopts.compress { |
| 165 | aio = append(aio, archive.WithImportCompression()) |
| 166 | } |
| 167 | |
| 168 | index, err := archive.ImportIndex(ctx, c.ContentStore(), reader, aio...) |
| 169 | if err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | |
| 173 | var ( |
| 174 | imgs []images.Image |
| 175 | cs = c.ContentStore() |
| 176 | is = c.ImageService() |
| 177 | ) |
| 178 | |
| 179 | if iopts.indexName != "" { |
| 180 | imgs = append(imgs, images.Image{ |
| 181 | Name: iopts.indexName, |
| 182 | Target: index, |
| 183 | }) |
| 184 | } |
| 185 | var platformMatcher = c.platform |
| 186 | if iopts.allPlatforms { |
| 187 | platformMatcher = platforms.All |
| 188 | } else if iopts.platformMatcher != nil { |
| 189 | platformMatcher = iopts.platformMatcher |
| 190 | } |
| 191 | |
| 192 | var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { |
| 193 | // Only save images at top level |
| 194 | if desc.Digest != index.Digest { |
| 195 | // Don't set labels on missing content. |
| 196 | children, err := images.Children(ctx, cs, desc) |
| 197 | if iopts.skipMissing && errdefs.IsNotFound(err) { |
| 198 | return nil, images.ErrSkipDesc |
| 199 | } |
| 200 | return children, err |
| 201 | } |
| 202 | |
| 203 | idx, err := decodeIndex(ctx, cs, desc) |
| 204 | if err != nil { |
| 205 | return nil, err |
| 206 | } |
nothing calls this directly
no test coverage detected