MCPcopy Index your code
hub / github.com/devcontainers/cli / _openDockerComposeDevContainer

Function _openDockerComposeDevContainer

src/spec-node/dockerCompose.ts:34–114  ·  view source on GitHub ↗
(params: DockerResolverParameters, buildParams: DockerCLIParameters, workspace: Workspace, configWithRaw: SubstitutedConfig<DevContainerFromDockerComposeConfig>, remoteWorkspaceFolder: string, idLabels: string[], additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>)

Source from the content-addressed store, hash-verified

32}
33
34async function _openDockerComposeDevContainer(params: DockerResolverParameters, buildParams: DockerCLIParameters, workspace: Workspace, configWithRaw: SubstitutedConfig<DevContainerFromDockerComposeConfig>, remoteWorkspaceFolder: string, idLabels: string[], additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>): Promise<ResolverResult> {
35 const { common } = params;
36 const { cliHost: buildCLIHost } = buildParams;
37 const { config } = configWithRaw;
38
39 let container: ContainerDetails | undefined;
40 let containerProperties: ContainerProperties | undefined;
41 try {
42
43 const composeFiles = await getDockerComposeFilePaths(buildCLIHost, config, buildCLIHost.env, buildCLIHost.cwd);
44 const cwdEnvFile = buildCLIHost.path.join(buildCLIHost.cwd, '.env');
45 const envFile = Array.isArray(config.dockerComposeFile) && config.dockerComposeFile.length === 0 && await buildCLIHost.isFile(cwdEnvFile) ? cwdEnvFile : undefined;
46 const composeConfig = await readDockerComposeConfig(buildParams, composeFiles, envFile);
47 const projectName = await getProjectName(buildParams, workspace, composeFiles, composeConfig);
48 const containerId = await findComposeContainer(params, projectName, config.service);
49 if (params.expectExistingContainer && !containerId) {
50 throw new ContainerError({ description: 'The expected container does not exist.' });
51 }
52 container = containerId ? await inspectContainer(params, containerId) : undefined;
53
54 if (container && (params.removeOnStartup === true || params.removeOnStartup === container.Id)) {
55 const text = 'Removing existing container.';
56 const start = common.output.start(text);
57 await removeContainer(params, container.Id);
58 common.output.stop(text, start);
59 container = undefined;
60 }
61
62 // let collapsedFeaturesConfig: CollapsedFeaturesConfig | undefined;
63 if (!container || container.State.Status !== 'running') {
64 const res = await startContainer(params, buildParams, configWithRaw, projectName, composeFiles, envFile, composeConfig, container, idLabels, additionalFeatures);
65 container = await inspectContainer(params, res.containerId);
66 // collapsedFeaturesConfig = res.collapsedFeaturesConfig;
67 // } else {
68 // const labels = container.Config.Labels || {};
69 // const featuresConfig = await generateFeaturesConfig(params.common, (await createFeaturesTempFolder(params.common)), config, async () => labels, getContainerFeaturesFolder);
70 // collapsedFeaturesConfig = collapseFeaturesConfig(featuresConfig);
71 }
72
73 const imageMetadata = getImageMetadataFromContainer(container, configWithRaw, undefined, idLabels, common.output).config;
74 const mergedConfig = mergeConfiguration(configWithRaw.config, imageMetadata);
75 containerProperties = await createContainerProperties(params, container.Id, remoteWorkspaceFolder, mergedConfig.remoteUser);
76
77 const {
78 remoteEnv: extensionHostEnv,
79 updatedConfig,
80 updatedMergedConfig,
81 } = await setupInContainer(common, containerProperties, config, mergedConfig, lifecycleCommandOriginMapFromMetadata(imageMetadata));
82
83 return {
84 params: common,
85 properties: containerProperties,
86 config: updatedConfig,
87 mergedConfig: updatedMergedConfig,
88 resolvedAuthority: {
89 extensionHostEnv,
90 },
91 tunnelInformation: common.isLocalContainer ? getTunnelInformation(container) : {},

Callers 1

Calls 15

inspectContainerFunction · 0.90
removeContainerFunction · 0.90
mergeConfigurationFunction · 0.90
setupInContainerFunction · 0.90
getTunnelInformationFunction · 0.90
readDockerComposeConfigFunction · 0.85
getProjectNameFunction · 0.85
findComposeContainerFunction · 0.85

Tested by

no test coverage detected