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

Function internalGetImageBuildInfoFromDockerfile

src/spec-node/imageMetadata.ts:401–436  ·  view source on GitHub ↗
(inspectDockerImage: (imageName: string) => Promise<ImageDetails>, dockerfileText: string, dockerBuildArgs: Record<string, string>, targetStage: string | undefined, substitute: SubstituteConfig, output: Log, omitSyntaxDirective: boolean, buildPlatform: PlatformInfo, targetPlatform: PlatformInfo)

Source from the content-addressed store, hash-verified

399}
400
401export async function internalGetImageBuildInfoFromDockerfile(inspectDockerImage: (imageName: string) => Promise<ImageDetails>, dockerfileText: string, dockerBuildArgs: Record<string, string>, targetStage: string | undefined, substitute: SubstituteConfig, output: Log, omitSyntaxDirective: boolean, buildPlatform: PlatformInfo, targetPlatform: PlatformInfo): Promise<ImageBuildInfo> {
402 const dockerfile = extractDockerfile(dockerfileText);
403 if (dockerfile.preamble.directives.syntax && omitSyntaxDirective) {
404 output.write(`Omitting syntax directive '${dockerfile.preamble.directives.syntax}' from Dockerfile.`, LogLevel.Trace);
405 delete dockerfile.preamble.directives.syntax;
406 }
407 // https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#automatic-platform-args-in-the-global-scope
408 const globalBuildxPlatformArgs = {
409 // platform of the node performing the build.
410 BUILDPLATFORM: [buildPlatform.os, buildPlatform.arch, buildPlatform.variant].filter(Boolean).join("/"),
411 // OS component of BUILDPLATFORM
412 BUILDOS: buildPlatform.os,
413 // architecture component of BUILDPLATFORM
414 BUILDARCH: buildPlatform.arch,
415 // variant component of BUILDPLATFORM
416 BUILDVARIANT: buildPlatform.variant ?? "",
417 // platform of the build result. Eg linux/amd64, linux/arm/v7, windows/amd64.
418 TARGETPLATFORM: [targetPlatform.os, targetPlatform.arch, targetPlatform.variant].filter(Boolean).join("/"),
419 // OS component of TARGETPLATFORM
420 TARGETOS: targetPlatform.os,
421 // architecture component of TARGETPLATFORM
422 TARGETARCH: targetPlatform.arch,
423 // variant component of TARGETPLATFORM
424 TARGETVARIANT: targetPlatform.variant ?? "",
425 };
426 const baseImage = findBaseImage(dockerfile, dockerBuildArgs, targetStage, globalBuildxPlatformArgs);
427 const imageDetails = baseImage && await inspectDockerImage(baseImage) || undefined;
428 const dockerfileUser = findUserStatement(dockerfile, dockerBuildArgs, envListToObj(imageDetails?.Config.Env), globalBuildxPlatformArgs, targetStage);
429 const user = dockerfileUser || imageDetails?.Config.User || 'root';
430 const metadata = imageDetails ? getImageMetadata(imageDetails, substitute, output) : { config: [], raw: [], substitute };
431 return {
432 user,
433 metadata,
434 dockerfile,
435 };
436}
437
438export const imageMetadataLabel = 'devcontainer.metadata';
439

Callers 2

Calls 7

extractDockerfileFunction · 0.90
findBaseImageFunction · 0.90
inspectDockerImageFunction · 0.90
findUserStatementFunction · 0.90
envListToObjFunction · 0.90
getImageMetadataFunction · 0.85
writeMethod · 0.65

Tested by

no test coverage detected