From 09e9821598a056e8d11dfd41e05ccbf370d57562 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Fri, 8 Dec 2023 12:45:14 +0100 Subject: [PATCH] Adopt additional_contexts in compose (microsoft/vscode-remote-release#7305) --- src/spec-node/dockerCompose.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/spec-node/dockerCompose.ts b/src/spec-node/dockerCompose.ts index f695a0cf3..b51db8bdd 100644 --- a/src/spec-node/dockerCompose.ts +++ b/src/spec-node/dockerCompose.ts @@ -182,8 +182,10 @@ export async function buildAndExtendDockerCompose(configWithRaw: SubstitutedConf } // determine whether we need to extend with features - const noBuildKitParams = { ...params, buildKitVersion: undefined }; // skip BuildKit -> can't set additional build contexts with compose - const extendImageBuildInfo = await getExtendImageBuildInfo(noBuildKitParams, configWithRaw, baseName, imageBuildInfo, composeService.user, additionalFeatures, canAddLabelsToContainer); + const version = parseVersion((await params.dockerComposeCLI()).version); + const supportsAdditionalBuildContexts = version && !isEarlierVersion(version, [2, 17, 0]); + const optionalBuildKitParams = supportsAdditionalBuildContexts ? params : { ...params, buildKitVersion: undefined }; + const extendImageBuildInfo = await getExtendImageBuildInfo(optionalBuildKitParams, configWithRaw, baseName, imageBuildInfo, composeService.user, additionalFeatures, canAddLabelsToContainer); let overrideImageName: string | undefined; let buildOverrideContent = ''; @@ -229,6 +231,13 @@ export async function buildAndExtendDockerCompose(configWithRaw: SubstitutedConf buildOverrideContent += ` - ${buildArg}=${featureBuildInfo.buildArgs[buildArg]}\n`; } } + + if (Object.keys(featureBuildInfo.buildKitContexts).length > 0) { + buildOverrideContent += ' additional_contexts:\n'; + for (const buildKitContext in featureBuildInfo.buildKitContexts) { + buildOverrideContent += ` - ${buildKitContext}=${featureBuildInfo.buildKitContexts[buildKitContext]}\n`; + } + } } // Generate the docker-compose override and build