MCPcopy Index your code
hub / github.com/devcontainers/cli / inspectImageInRegistry

Function inspectImageInRegistry

src/spec-node/utils.ts:320–375  ·  view source on GitHub ↗
(output: Log, platformInfo: PlatformInfo, name: string)

Source from the content-addressed store, hash-verified

318}
319
320export async function inspectImageInRegistry(output: Log, platformInfo: PlatformInfo, name: string): Promise<ImageDetails> {
321 const resourceAndVersion = qualifyImageName(name);
322 const params = { output, env: process.env };
323 const ref = getRef(output, resourceAndVersion);
324 if (!ref) {
325 throw new Error(`Could not parse image name '${name}'`);
326 }
327
328 const registryServer = ref.registry === 'docker.io' ? 'registry-1.docker.io' : ref.registry;
329 const manifestUrl = `https://${registryServer}/v2/${ref.path}/manifests/${ref.version}`;
330 output.write(`manifest url: ${manifestUrl}`, LogLevel.Trace);
331
332 let targetDigest: string | undefined = undefined;
333 const manifest = await getManifest(params, manifestUrl, ref, 'application/vnd.docker.distribution.manifest.v2+json');
334 if (manifest?.manifestObj.config) { // Checking for config because the above mime type sometimes returns an image index.
335 targetDigest = manifest.manifestObj.config.digest;
336 } else {
337 // If we couldn't fetch the manifest, perhaps the registry supports querying for the 'Image Index'
338 // Spec: https://github.com/opencontainers/image-spec/blob/main/image-index.md
339 const imageIndexEntry = await getImageIndexEntryForPlatform(params, manifestUrl, ref, platformInfo);
340 if (imageIndexEntry) {
341 const manifestUrl = `https://${registryServer}/v2/${ref.path}/manifests/${imageIndexEntry.digest}`;
342 const a = await getManifest(params, manifestUrl, ref);
343 if (a) {
344 targetDigest = a.manifestObj.config.digest;
345 }
346 }
347 }
348
349 if (!targetDigest) {
350 throw new Error(`No manifest found for ${resourceAndVersion}.`);
351 }
352
353 const blobUrl = `https://${registryServer}/v2/${ref.path}/blobs/${targetDigest}`;
354 output.write(`blob url: ${blobUrl}`, LogLevel.Trace);
355
356 const httpOptions = {
357 type: 'GET',
358 url: blobUrl,
359 headers: {}
360 };
361
362 const res = await requestEnsureAuthenticated(params, httpOptions, ref);
363 if (!res) {
364 throw new Error(`Failed to fetch blob for ${resourceAndVersion}.`);
365 }
366 const blob = res.resBody.toString();
367 const obj = JSON.parse(blob);
368 return {
369 Id: targetDigest,
370 Config: obj.config,
371 Os: platformInfo.os,
372 Variant: platformInfo.variant,
373 Architecture: platformInfo.arch,
374 };
375}
376
377export function qualifyImageName(name: string) {

Callers 2

inspectDockerImageFunction · 0.85

Calls 6

getRefFunction · 0.90
getManifestFunction · 0.90
qualifyImageNameFunction · 0.85
writeMethod · 0.65

Tested by

no test coverage detected