saveSingleImage saves the specified image name to the specified path. Supported formats are "oci-archive", "oci-dir" and "docker-dir".
(ctx context.Context, name, format, path string, options *SaveOptions)
| 74 | // saveSingleImage saves the specified image name to the specified path. |
| 75 | // Supported formats are "oci-archive", "oci-dir" and "docker-dir". |
| 76 | func (r *Runtime) saveSingleImage(ctx context.Context, name, format, path string, options *SaveOptions) error { |
| 77 | image, imageName, err := r.LookupImage(name, nil) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | if r.eventChannel != nil { |
| 83 | defer r.writeEvent(&Event{ID: image.ID(), Name: path, Time: time.Now(), Type: EventTypeImageSave}) |
| 84 | } |
| 85 | |
| 86 | // Unless the image was referenced by ID, use the resolved name as a |
| 87 | // tag. |
| 88 | var tag string |
| 89 | if !strings.HasPrefix(image.ID(), imageName) { |
| 90 | tag = imageName |
| 91 | } |
| 92 | |
| 93 | srcRef, err := image.StorageReference() |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | // Prepare the destination reference. |
| 99 | var destRef types.ImageReference |
| 100 | switch format { |
| 101 | case "oci-archive": |
| 102 | destRef, err = ociArchiveTransport.NewReference(path, tag) |
| 103 | |
| 104 | case "oci-dir": |
| 105 | destRef, err = ociTransport.NewReference(path, tag) |
| 106 | options.ManifestMIMEType = ociv1.MediaTypeImageManifest |
| 107 | |
| 108 | case "docker-dir": |
| 109 | destRef, err = dirTransport.NewReference(path) |
| 110 | options.ManifestMIMEType = manifest.DockerV2Schema2MediaType |
| 111 | |
| 112 | default: |
| 113 | return errors.Errorf("unsupported format %q for saving images", format) |
| 114 | } |
| 115 | |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | c, err := r.newCopier(&options.CopyOptions) |
| 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | defer c.close() |
| 125 | |
| 126 | _, err = c.copy(ctx, srcRef, destRef) |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | // saveDockerArchive saves the specified images indicated by names to the path. |
| 131 | // It loads all images from the local containers storage and assembles the meta |
no test coverage detected