MCPcopy Create free account
hub / github.com/containers/common / LookupImage

Method LookupImage

libimage/runtime.go:206–298  ·  view source on GitHub ↗

Lookup Image looks up `name` in the local container storage. Returns the image and the name it has been found with. Note that name may also use the `containers-storage:` prefix used to refer to the containers-storage transport. Returns storage.ErrImageUnknown if the image could not be found. Unl

(name string, options *LookupImageOptions)

Source from the content-addressed store, hash-verified

204// If the specified name uses the `containers-storage` transport, the resolved
205// name is empty.
206func (r *Runtime) LookupImage(name string, options *LookupImageOptions) (*Image, string, error) {
207 logrus.Debugf("Looking up image %q in local containers storage", name)
208
209 if options == nil {
210 options = &LookupImageOptions{}
211 }
212
213 // If needed extract the name sans transport.
214 storageRef, err := alltransports.ParseImageName(name)
215 if err == nil {
216 if storageRef.Transport().Name() != storageTransport.Transport.Name() {
217 return nil, "", errors.Errorf("unsupported transport %q for looking up local images", storageRef.Transport().Name())
218 }
219 img, err := storageTransport.Transport.GetStoreImage(r.store, storageRef)
220 if err != nil {
221 return nil, "", err
222 }
223 logrus.Debugf("Found image %q in local containers storage (%s)", name, storageRef.StringWithinTransport())
224 return r.storageToImage(img, storageRef), "", nil
225 } else {
226 // Docker compat: strip off the tag iff name is tagged and digested
227 // (e.g., fedora:latest@sha256...). In that case, the tag is stripped
228 // off and entirely ignored. The digest is the sole source of truth.
229 normalizedName, err := normalizeTaggedDigestedString(name)
230 if err != nil {
231 return nil, "", err
232 }
233 name = normalizedName
234 }
235
236 originalName := name
237 idByDigest := false
238 if strings.HasPrefix(name, "sha256:") {
239 // Strip off the sha256 prefix so it can be parsed later on.
240 idByDigest = true
241 name = strings.TrimPrefix(name, "sha256:")
242 }
243
244 // Unless specified, set the platform specified in the system context
245 // for later platform matching. Builder likes to set these things via
246 // the system context at runtime creation.
247 if options.Architecture == "" {
248 options.Architecture = r.systemContext.ArchitectureChoice
249 }
250 if options.OS == "" {
251 options.OS = r.systemContext.OSChoice
252 }
253 if options.Variant == "" {
254 options.Variant = r.systemContext.VariantChoice
255 }
256 // Normalize platform to be OCI compatible (e.g., "aarch64" -> "arm64").
257 options.OS, options.Architecture, options.Variant = NormalizePlatform(options.OS, options.Architecture, options.Variant)
258
259 // First, check if we have an exact match in the storage. Maybe an ID
260 // or a fully-qualified image name.
261 img, err := r.lookupImageInLocalStorage(name, name, options)
262 if err != nil {
263 return nil, "", err

Callers 15

PushMethod · 0.95
timeMethod · 0.95
PullMethod · 0.95
ImportMethod · 0.95
saveSingleImageMethod · 0.95
saveDockerArchiveMethod · 0.95
lookupManifestListMethod · 0.95
ExistsMethod · 0.95
ResolveNameMethod · 0.95
ListImagesMethod · 0.95
RemoveImagesMethod · 0.95

Calls 6

storageToImageMethod · 0.95
NormalizePlatformFunction · 0.85
StringMethod · 0.45

Tested by 8

TestImportFunction · 0.64
TestLoadFunction · 0.64
TestTagFunction · 0.64
TestUntagFunction · 0.64
TestPullFunction · 0.64
TestPullPlatformsFunction · 0.64