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

Function extractDockerfile

src/spec-node/dockerfileUtils.ts:56–82  ·  view source on GitHub ↗
(dockerfile: string)

Source from the content-addressed store, hash-verified

54}
55
56export function extractDockerfile(dockerfile: string): Dockerfile {
57 const fromStatementsAhead = /(?=^[\t ]*FROM)/gmi;
58 const parts = dockerfile.split(fromStatementsAhead);
59 const preambleStr = fromStatementsAhead.test(parts[0] || '') ? '' : parts.shift()!;
60 const stageStrs = parts;
61 const stages = stageStrs.map(stageStr => ({
62 from: parseFromStatement(stageStr),
63 instructions: extractInstructions(stageStr),
64 }));
65 const directives = extractDirectives(preambleStr);
66 const versionMatch = directives.syntax && /^(?:docker.io\/)?docker\/dockerfile(?::(?<version>\S+))?/i.exec(directives.syntax) || undefined;
67 const version = versionMatch && (versionMatch.groups?.version || 'latest');
68 return {
69 preamble: {
70 version,
71 directives,
72 instructions: extractInstructions(preambleStr),
73 },
74 stages,
75 stagesByLabel: stages.reduce((obj, stage) => {
76 if (stage.from.label) {
77 obj[stage.from.label] = stage;
78 }
79 return obj;
80 }, {} as Record<string, Stage>),
81 } as Dockerfile;
82}
83
84export function findUserStatement(dockerfile: Dockerfile, buildArgs: Record<string, string>, baseImageEnv: Record<string, string>, globalBuildxPlatformArgs: Record<string, string> = {}, target: string | undefined) {
85 let stage: Stage | undefined = target ? dockerfile.stagesByLabel[target] : dockerfile.stages[dockerfile.stages.length - 1];

Calls 4

parseFromStatementFunction · 0.85
extractInstructionsFunction · 0.85
extractDirectivesFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected