(params: DockerResolverParameters, parsedAuthority: DevContainerAuthority | undefined, configFile: URI | undefined, overrideConfigFile: URI | undefined, providedIdLabels: string[] | undefined, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>)
| 36 | } |
| 37 | |
| 38 | async function resolveWithLocalFolder(params: DockerResolverParameters, parsedAuthority: DevContainerAuthority | undefined, configFile: URI | undefined, overrideConfigFile: URI | undefined, providedIdLabels: string[] | undefined, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>): Promise<ResolverResult> { |
| 39 | const { common, workspaceMountConsistencyDefault } = params; |
| 40 | const { cliHost, output } = common; |
| 41 | |
| 42 | const cwd = cliHost.cwd; // Can be inside WSL. |
| 43 | const workspace = parsedAuthority && workspaceFromPath(cliHost.path, isWorkspacePath(parsedAuthority.hostPath) ? cliHost.path.join(cwd, path.basename(parsedAuthority.hostPath)) : cwd); |
| 44 | |
| 45 | const configPath = configFile ? configFile : workspace |
| 46 | ? (await getDevContainerConfigPathIn(cliHost, workspace.configFolderPath) |
| 47 | || (overrideConfigFile ? getDefaultDevContainerConfigPath(cliHost, workspace.configFolderPath) : undefined)) |
| 48 | : overrideConfigFile; |
| 49 | const configs = configPath && await readDevContainerConfigFile(cliHost, workspace, configPath, params.mountWorkspaceGitRoot, params.mountGitWorktreeCommonDir, output, workspaceMountConsistencyDefault, overrideConfigFile) || undefined; |
| 50 | if (!configs) { |
| 51 | if (configPath || workspace) { |
| 52 | throw new ContainerError({ description: `Dev container config (${uriToFsPath(configPath || getDefaultDevContainerConfigPath(cliHost, workspace!.configFolderPath), cliHost.platform)}) not found.` }); |
| 53 | } else { |
| 54 | throw new ContainerError({ description: `No dev container config and no workspace found.` }); |
| 55 | } |
| 56 | } |
| 57 | const idLabels = providedIdLabels || (await findContainerAndIdLabels(params, undefined, providedIdLabels, workspace?.rootFolderPath, configPath?.fsPath, params.removeOnStartup)).idLabels; |
| 58 | const configWithRaw = addSubstitution(configs.config, config => beforeContainerSubstitute(envListToObj(idLabels), config)); |
| 59 | const { config } = configWithRaw; |
| 60 | |
| 61 | const { dockerCLI, dockerComposeCLI } = params; |
| 62 | const { env } = common; |
| 63 | const cliParams: DockerCLIParameters = { cliHost, dockerCLI, dockerComposeCLI, env, output, buildPlatformInfo: params.buildPlatformInfo, targetPlatformInfo: params.targetPlatformInfo }; |
| 64 | await ensureNoDisallowedFeatures(cliParams, config, additionalFeatures, idLabels); |
| 65 | |
| 66 | await runInitializeCommand({ ...params, common: { ...common, output: common.lifecycleHook.output } }, config.initializeCommand, common.lifecycleHook.onDidInput); |
| 67 | |
| 68 | let result: ResolverResult; |
| 69 | if (isDockerFileConfig(config) || 'image' in config) { |
| 70 | result = await openDockerfileDevContainer(params, configWithRaw as SubstitutedConfig<DevContainerFromDockerfileConfig | DevContainerFromImageConfig>, configs.workspaceConfig, idLabels, additionalFeatures); |
| 71 | } else if ('dockerComposeFile' in config) { |
| 72 | if (!workspace) { |
| 73 | throw new ContainerError({ description: `A Dev Container using Docker Compose requires a workspace folder.` }); |
| 74 | } |
| 75 | result = await openDockerComposeDevContainer(params, workspace, configWithRaw as SubstitutedConfig<DevContainerFromDockerComposeConfig>, idLabels, additionalFeatures); |
| 76 | } else { |
| 77 | throw new ContainerError({ description: `Dev container config (${(config as DevContainerConfig).configFilePath}) is missing one of "image", "dockerFile" or "dockerComposeFile" properties.` }); |
| 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | export async function readDevContainerConfigFile(cliHost: CLIHost, workspace: Workspace | undefined, configFile: URI, mountWorkspaceGitRoot: boolean, mountGitWorktreeCommonDir: boolean, output: Log, consistency?: BindMountConsistency, overrideConfigFile?: URI) { |
| 83 | const documents = createDocuments(cliHost); |
no test coverage detected