Skip to content

Commit 1455093

Browse files
committed
partial support multi-platform build
1 parent 63a89ee commit 1455093

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

src/spec-node/containerFeatures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async function getFeaturesBuildOptions(params: DockerResolverParameters, devCont
265265
const syntax = imageBuildInfo.dockerfile?.preamble.directives.syntax;
266266
const omitSyntaxDirective = common.omitSyntaxDirective; // Can be removed when https://github.com/moby/buildkit/issues/4556 is fixed
267267
const dockerfilePrefixContent = `${omitSyntaxDirective ? '' :
268-
useBuildKitBuildContexts && !(imageBuildInfo.dockerfile && supportsBuildContexts(imageBuildInfo.dockerfile)) ? '# syntax=docker/dockerfile:1.4' :
268+
useBuildKitBuildContexts && !(imageBuildInfo.dockerfile && supportsBuildContexts(imageBuildInfo.dockerfile)) ? '# syntax=docker/dockerfile:1.11' :
269269
syntax ? `# syntax=${syntax}` : ''}
270270
ARG _DEV_CONTAINERS_BASE_IMAGE=placeholder
271271
`;

src/spec-node/devContainers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
172172
}, dockerPath, dockerComposePath);
173173

174174
const platformInfo = (() => {
175-
if (common.buildxPlatform) {
175+
if (common.buildxPlatform && common.buildxPlatform.split(',').length === 1) {
176176
const slash1 = common.buildxPlatform.indexOf('/');
177177
const slash2 = common.buildxPlatform.indexOf('/', slash1 + 1);
178178
// `--platform linux/amd64/v3` `--platform linux/arm64/v8`
@@ -189,7 +189,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
189189
arch: <GoARCH> common.buildxPlatform.slice(slash1 + 1),
190190
};
191191
} else {
192-
// `--platform` omitted
192+
// `--platform` omitted or multiple platforms
193193
return {
194194
os: mapNodeOSToGOOS(cliHost.platform),
195195
arch: mapNodeArchitectureToGOARCH(cliHost.arch),

src/spec-node/dockerfileUtils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as semver from 'semver';
77
import { Mount } from '../spec-configuration/containerFeaturesConfiguration';
8+
import { PlatformInfo } from '../spec-common/commonUtils';
89

910

1011
const findFromLines = new RegExp(/^(?<line>\s*FROM.*)/, 'gmi');
@@ -100,15 +101,28 @@ export function findUserStatement(dockerfile: Dockerfile, buildArgs: Record<stri
100101
return undefined;
101102
}
102103

103-
export function findBaseImage(dockerfile: Dockerfile, buildArgs: Record<string, string>, target: string | undefined) {
104+
export function findBaseImage(dockerfile: Dockerfile, buildArgs: Record<string, string>, target: string | undefined, platformInfo: PlatformInfo) {
104105
let stage: Stage | undefined = target ? dockerfile.stagesByLabel[target] : dockerfile.stages[dockerfile.stages.length - 1];
105106
const seen = new Set<Stage>();
106107
while (stage) {
107108
if (seen.has(stage)) {
108109
return undefined;
109110
}
110111
seen.add(stage);
111-
112+
if (stage.from.image.includes('$')) {
113+
buildArgs = {
114+
...buildArgs,
115+
TARGETPLATFORM: platformInfo.variant ? `${platformInfo.arch}/${platformInfo.os}/${platformInfo.variant}` : `${platformInfo.arch}/${platformInfo.os}`,
116+
TARGETOS: platformInfo.os,
117+
TARGETARCH: platformInfo.arch,
118+
};
119+
if (platformInfo.variant) {
120+
buildArgs = {
121+
...buildArgs,
122+
TARGETVARIANT: platformInfo.variant,
123+
};
124+
}
125+
}
112126
const image = replaceVariables(dockerfile, buildArgs, /* not available in FROM instruction */ {}, stage.from.image, dockerfile.preamble, dockerfile.preamble.instructions.length);
113127
const nextStage = dockerfile.stagesByLabel[image];
114128
if (!nextStage) {

src/spec-shutdown/dockerUtils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { CLIHost, runCommand, runCommandNoPty, ExecFunction, ExecParameters, Exec, PtyExecFunction, PtyExec, PtyExecParameters, plainExecAsPtyExec, PlatformInfo } from '../spec-common/commonUtils';
6+
import { CLIHost, runCommand, runCommandNoPty, ExecFunction, ExecParameters, Exec, PtyExecFunction, PtyExec, PtyExecParameters, plainExecAsPtyExec, PlatformInfo, GoARCH, GoOS } from '../spec-common/commonUtils';
77
import { toErrorText } from '../spec-common/errors';
88
import * as ptyType from 'node-pty';
99
import { Log, makeLog } from '../spec-utils/log';
@@ -426,3 +426,20 @@ export function toDockerImageName(name: string) {
426426
.replace(/[^a-z0-9\._-]+/g, '')
427427
.replace(/(\.[\._-]|_[\.-]|__[\._-]|-+[\._])[\._-]*/g, (_, a) => a.substr(0, a.length - 1));
428428
}
429+
430+
export interface ManifestDetail {
431+
readonly schemaVersion: number;
432+
readonly mediaType: string;
433+
readonly manifests: readonly Manifest[];
434+
}
435+
436+
export interface Manifest {
437+
readonly mediaType: string;
438+
readonly size: number;
439+
readonly digest: string;
440+
readonly platform: {
441+
readonly architecture: GoARCH;
442+
readonly os: GoOS;
443+
readonly variant?: string;
444+
};
445+
}

0 commit comments

Comments
 (0)