(params: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, workspaceConfig: WorkspaceConfiguration, idLabels: string[], additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>)
| 18 | export const configFileLabel = 'devcontainer.config_file'; |
| 19 | |
| 20 | export async function openDockerfileDevContainer(params: DockerResolverParameters, configWithRaw: SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, workspaceConfig: WorkspaceConfiguration, idLabels: string[], additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>): Promise<ResolverResult> { |
| 21 | const { common } = params; |
| 22 | const { config } = configWithRaw; |
| 23 | |
| 24 | let container: ContainerDetails | undefined; |
| 25 | let containerProperties: ContainerProperties | undefined; |
| 26 | |
| 27 | try { |
| 28 | container = await findExistingContainer(params, idLabels); |
| 29 | let imageMetadata: ImageMetadataEntry[]; |
| 30 | let mergedConfig: MergedDevContainerConfig; |
| 31 | if (container) { |
| 32 | |
| 33 | await startExistingContainer(params, idLabels, container); |
| 34 | imageMetadata = getImageMetadataFromContainer(container, configWithRaw, undefined, idLabels, common.output).config; |
| 35 | mergedConfig = mergeConfiguration(config, imageMetadata); |
| 36 | } else { |
| 37 | const res = await buildNamedImageAndExtend(params, configWithRaw, additionalFeatures, true); |
| 38 | imageMetadata = res.imageMetadata.config; |
| 39 | mergedConfig = mergeConfiguration(config, imageMetadata); |
| 40 | const { containerUser } = mergedConfig; |
| 41 | const updatedImageName = await updateRemoteUserUID(params, mergedConfig, res.updatedImageName[0], res.imageDetails, findUserArg(config.runArgs) || containerUser); |
| 42 | try { |
| 43 | await spawnDevContainer(params, config, mergedConfig, updatedImageName, idLabels, workspaceConfig.workspaceMount, workspaceConfig.additionalMountString, res.imageDetails, containerUser, res.labels || {}); |
| 44 | } finally { |
| 45 | // In 'finally' because 'docker run' can fail after creating the container. |
| 46 | // Trying to get it here, so we can offer 'Rebuild Container' as an action later. |
| 47 | container = await findDevContainer(params, idLabels); |
| 48 | } |
| 49 | if (!container) { |
| 50 | return bailOut(common.output, 'Dev container not found.'); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | containerProperties = await createContainerProperties(params, container.Id, workspaceConfig.workspaceFolder, mergedConfig.remoteUser); |
| 55 | return await setupContainer(container, params, containerProperties, config, mergedConfig, imageMetadata); |
| 56 | |
| 57 | } catch (e) { |
| 58 | throw createSetupError(e, container, params, containerProperties, config); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | function createSetupError(originalError: any, container: ContainerDetails | undefined, params: DockerResolverParameters, containerProperties: ContainerProperties | undefined, config: DevContainerConfig | undefined): ContainerError { |
| 63 | let description = 'An error occurred setting up the container.'; |
no test coverage detected