|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 |
|
7 | | -import { createContainerProperties, startEventSeen, ResolverResult, getTunnelInformation, getDockerfilePath, getDockerContextPath, DockerResolverParameters, isDockerFileConfig, uriToWSLFsPath, WorkspaceConfiguration, getFolderImageName, inspectDockerImage, logUMask, SubstitutedConfig, checkDockerSupportForGPU } from './utils'; |
| 7 | +import { createContainerProperties, startEventSeen, ResolverResult, getTunnelInformation, getDockerfilePath, getDockerContextPath, DockerResolverParameters, isDockerFileConfig, uriToWSLFsPath, WorkspaceConfiguration, getFolderImageName, SubstitutedConfig, checkDockerSupportForGPU } from './utils'; |
8 | 8 | import { ContainerProperties, setupInContainer, ResolverProgress, ResolverParameters } from '../spec-common/injectHeadless'; |
9 | 9 | import { ContainerError, toErrorText } from '../spec-common/errors'; |
10 | 10 | import { ContainerDetails, listContainers, DockerCLIParameters, inspectContainers, dockerCLI, dockerPtyCLI, toPtyExecParameters, ImageDetails, toExecParameters } from '../spec-shutdown/dockerUtils'; |
11 | 11 | import { DevContainerConfig, DevContainerFromDockerfileConfig, DevContainerFromImageConfig } from '../spec-configuration/configuration'; |
12 | 12 | import { LogLevel, Log, makeLog } from '../spec-utils/log'; |
13 | | -import { extendImage, getExtendImageBuildInfo, updateRemoteUserUID } from './containerFeatures'; |
| 13 | +import { extendImage, getExtendImageBuildInfo } from './containerFeatures'; |
14 | 14 | import { getDevcontainerMetadata, getImageBuildInfoFromDockerfile, getImageMetadataFromContainer, ImageMetadataEntry, mergeConfiguration, MergedDevContainerConfig } from './imageMetadata'; |
15 | 15 | import { ensureDockerfileHasFinalStageName } from './dockerfileUtils'; |
16 | 16 |
|
@@ -40,24 +40,7 @@ export async function openDockerfileDevContainer(params: DockerResolverParameter |
40 | 40 | const imageMetadata = getImageMetadataFromContainer(container, configWithRaw, undefined, idLabels, common.experimentalImageMetadata, common.output).config; |
41 | 41 | mergedConfig = mergeConfiguration(config, imageMetadata); |
42 | 42 | } else { |
43 | | - const res = await buildNamedImageAndExtend(params, configWithRaw, additionalFeatures, true); |
44 | | - const imageMetadata = res.imageMetadata.config; |
45 | | - mergedConfig = mergeConfiguration(config, imageMetadata); |
46 | | - const { containerUser } = mergedConfig; |
47 | | - const updatedImageName = await updateRemoteUserUID(params, mergedConfig, res.updatedImageName[0], res.imageDetails, findUserArg(config.runArgs) || containerUser); |
48 | | - |
49 | | - // collapsedFeaturesConfig = async () => res.collapsedFeaturesConfig; |
50 | | - |
51 | | - try { |
52 | | - await spawnDevContainer(params, config, mergedConfig, updatedImageName, idLabels, workspaceConfig.workspaceMount, res.imageDetails, containerUser, res.labels || {}); |
53 | | - } finally { |
54 | | - // In 'finally' because 'docker run' can fail after creating the container. |
55 | | - // Trying to get it here, so we can offer 'Rebuild Container' as an action later. |
56 | | - container = await findDevContainer(params, idLabels); |
57 | | - } |
58 | | - if (!container) { |
59 | | - return bailOut(common.output, 'Dev container not found.'); |
60 | | - } |
| 43 | + return bailOut(common.output, 'Code removed.'); |
61 | 44 | } |
62 | 45 |
|
63 | 46 | containerProperties = await createContainerProperties(params, container.Id, workspaceConfig.workspaceFolder, mergedConfig.remoteUser); |
@@ -110,7 +93,7 @@ async function setupContainer(container: ContainerDetails, params: DockerResolve |
110 | 93 | function getDefaultName(config: DevContainerFromDockerfileConfig | DevContainerFromImageConfig, params: DockerResolverParameters) { |
111 | 94 | return 'image' in config ? config.image : getFolderImageName(params.common); |
112 | 95 | } |
113 | | -export async function buildNamedImageAndExtend(params: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>, canAddLabelsToContainer: boolean, argImageNames?: string[]): Promise<{ updatedImageName: string[]; imageMetadata: SubstitutedConfig<ImageMetadataEntry[]>; imageDetails: () => Promise<ImageDetails>; labels?: Record<string, string> }> { |
| 96 | +export async function buildNamedImageAndExtend(params: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>, canAddLabelsToContainer: boolean, argImageNames?: string[]): Promise<{ updatedImageName: string[]; imageMetadata: SubstitutedConfig<ImageMetadataEntry[]>; labels?: Record<string, string> }> { |
114 | 97 | const { config } = configWithRaw; |
115 | 98 | const imageNames = argImageNames ?? [getDefaultName(config, params)]; |
116 | 99 | params.common.progress(ResolverProgress.BuildingImage); |
@@ -167,90 +150,46 @@ async function buildAndExtendImage(buildParams: DockerResolverParameters, config |
167 | 150 | additionalBuildArgs.push('--build-context', `${buildContext}=${featureBuildInfo.buildKitContexts[buildContext]}`); |
168 | 151 | } |
169 | 152 | for (const buildArg in featureBuildInfo.buildArgs) { |
170 | | - additionalBuildArgs.push('--build-arg', `${buildArg}=${featureBuildInfo.buildArgs[buildArg]}`); |
| 153 | + additionalBuildArgs.push('--param', `${buildArg}=${featureBuildInfo.buildArgs[buildArg]}`); |
171 | 154 | } |
172 | 155 | } |
173 | 156 |
|
174 | | - const args: string[] = []; |
175 | | - if (!buildParams.buildKitVersion && |
176 | | - (buildParams.buildxPlatform || buildParams.buildxPush)) { |
177 | | - throw new ContainerError({ description: '--platform or --push require BuildKit enabled.', data: { fileWithError: dockerfilePath } }); |
178 | | - } |
179 | | - if (buildParams.buildKitVersion) { |
180 | | - args.push('buildx', 'build'); |
181 | | - if (buildParams.buildxPlatform) { |
182 | | - args.push('--platform', buildParams.buildxPlatform); |
183 | | - } |
184 | | - if (buildParams.buildxPush) { |
185 | | - args.push('--push'); |
186 | | - } else { |
187 | | - if (buildParams.buildxOutput) { |
188 | | - args.push('--output', buildParams.buildxOutput); |
189 | | - } else { |
190 | | - args.push('--load'); // (short for --output=docker, i.e. load into normal 'docker images' collection) |
191 | | - } |
192 | | - } |
193 | | - args.push('--build-arg', 'BUILDKIT_INLINE_CACHE=1'); |
194 | | - } else { |
195 | | - args.push('build'); |
196 | | - } |
197 | | - args.push('-f', finalDockerfilePath); |
| 157 | + const args: string[] = ['build']; |
| 158 | + args.push('--dockerfile', finalDockerfilePath); |
198 | 159 |
|
199 | | - baseImageNames.map(imageName => args.push('-t', imageName)); |
| 160 | + baseImageNames.map(imageName => args.push('--image-name', imageName)); |
200 | 161 |
|
201 | 162 | const target = extendImageBuildInfo?.featureBuildInfo ? extendImageBuildInfo.featureBuildInfo.overrideTarget : config.build?.target; |
202 | 163 | if (target) { |
203 | 164 | args.push('--target', target); |
204 | 165 | } |
205 | | - if (noCache) { |
206 | | - args.push('--no-cache'); |
207 | | - // `docker build --pull` pulls local image: https://github.com/devcontainers/cli/issues/60 |
208 | | - if (buildParams.buildKitVersion || !extendImageBuildInfo) { |
209 | | - args.push('--pull'); |
210 | | - } |
211 | | - } else { |
212 | | - const configCacheFrom = config.build?.cacheFrom; |
213 | | - if (buildParams.additionalCacheFroms.length || (configCacheFrom && (configCacheFrom === 'string' || configCacheFrom.length))) { |
214 | | - await logUMask(buildParams); |
215 | | - } |
216 | | - buildParams.additionalCacheFroms.forEach(cacheFrom => args.push('--cache-from', cacheFrom)); |
217 | | - if (config.build && config.build.cacheFrom) { |
218 | | - if (typeof config.build.cacheFrom === 'string') { |
219 | | - args.push('--cache-from', config.build.cacheFrom); |
220 | | - } else { |
221 | | - for (let index = 0; index < config.build.cacheFrom.length; index++) { |
222 | | - const cacheFrom = config.build.cacheFrom[index]; |
223 | | - args.push('--cache-from', cacheFrom); |
224 | | - } |
225 | | - } |
226 | | - } |
| 166 | + if (!noCache) { |
| 167 | + args.push('--cache'); |
227 | 168 | } |
228 | 169 | const buildArgs = config.build?.args; |
229 | 170 | if (buildArgs) { |
230 | 171 | for (const key in buildArgs) { |
231 | | - args.push('--build-arg', `${key}=${buildArgs[key]}`); |
| 172 | + args.push('--param', `${key}=${buildArgs[key]}`); |
232 | 173 | } |
233 | 174 | } |
234 | 175 | args.push(...additionalBuildArgs); |
235 | | - args.push(await uriToWSLFsPath(getDockerContextPath(cliHost, config), cliHost)); |
| 176 | + args.push('--build-path', await uriToWSLFsPath(getDockerContextPath(cliHost, config), cliHost)); |
236 | 177 | try { |
| 178 | + buildParams.dockerCLI = 'newt'; |
237 | 179 | if (buildParams.isTTY) { |
238 | 180 | const infoParams = { ...toPtyExecParameters(buildParams), output: makeLog(output, LogLevel.Info) }; |
239 | | - await dockerPtyCLI(infoParams, ...args); |
| 181 | + await dockerPtyCLI(infoParams, process.cwd(), ...args); |
240 | 182 | } else { |
241 | 183 | const infoParams = { ...toExecParameters(buildParams), output: makeLog(output, LogLevel.Info), print: 'continuous' as 'continuous' }; |
242 | | - await dockerCLI(infoParams, ...args); |
| 184 | + await dockerCLI(infoParams, process.cwd(), ...args); |
243 | 185 | } |
244 | 186 | } catch (err) { |
245 | 187 | throw new ContainerError({ description: 'An error occurred building the image.', originalError: err, data: { fileWithError: dockerfilePath } }); |
246 | 188 | } |
247 | 189 |
|
248 | | - const imageDetails = () => inspectDockerImage(buildParams, baseImageNames[0], false); |
249 | | - |
250 | 190 | return { |
251 | 191 | updatedImageName: baseImageNames, |
252 | 192 | imageMetadata: getDevcontainerMetadata(imageBuildInfo.metadata, configWithRaw, extendImageBuildInfo?.featuresConfig), |
253 | | - imageDetails |
254 | 193 | }; |
255 | 194 | } |
256 | 195 |
|
|
0 commit comments