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

Function readDockerComposeConfig

src/spec-node/dockerCompose.ts:575–628  ·  view source on GitHub ↗
(params: DockerCLIParameters, composeFiles: string[], envFile: string | undefined)

Source from the content-addressed store, hash-verified

573}
574
575export async function readDockerComposeConfig(params: DockerCLIParameters, composeFiles: string[], envFile: string | undefined) {
576 try {
577 const composeGlobalArgs = ([] as string[]).concat(...composeFiles.map(composeFile => ['-f', composeFile]));
578 if (envFile) {
579 composeGlobalArgs.push('--env-file', envFile);
580 }
581 const composeCLI = await params.dockerComposeCLI();
582 if ((parseVersion(composeCLI.version) || [])[0] >= 2) {
583 composeGlobalArgs.push('--profile', '*');
584 }
585 try {
586 const partial = toExecParameters(params, 'dockerComposeCLI' in params ? await params.dockerComposeCLI() : undefined);
587 const { stdout } = await dockerComposeCLI({
588 ...partial,
589 output: makeLog(params.output, LogLevel.Info),
590 print: 'onerror'
591 }, ...composeGlobalArgs, 'config');
592 const stdoutStr = stdout.toString();
593 params.output.write(stdoutStr);
594 return yaml.load(stdoutStr) || {} as any;
595 } catch (err) {
596 if (!Buffer.isBuffer(err?.stderr) || err?.stderr.toString().indexOf('UnicodeEncodeError') === -1) {
597 throw err;
598 }
599 // Upstream issues. https://github.com/microsoft/vscode-remote-release/issues/5308
600 if (params.cliHost.platform === 'win32') {
601 const { cmdOutput } = await dockerComposePtyCLI({
602 ...params,
603 output: makeLog({
604 event: params.output.event,
605 dimensions: {
606 columns: 999999,
607 rows: 1,
608 },
609 }, LogLevel.Info),
610 }, ...composeGlobalArgs, 'config');
611 return yaml.load(cmdOutput.replace(terminalEscapeSequences, '')) || {} as any;
612 }
613 const { stdout } = await dockerComposeCLI({
614 ...params,
615 env: {
616 ...params.env,
617 LANG: 'en_US.UTF-8',
618 LC_CTYPE: 'en_US.UTF-8',
619 }
620 }, ...composeGlobalArgs, 'config');
621 const stdoutStr = stdout.toString();
622 params.output.write(stdoutStr);
623 return yaml.load(stdoutStr) || {} as any;
624 }
625 } catch (err) {
626 throw err instanceof ContainerError ? err : new ContainerError({ description: 'An error occurred retrieving the Docker Compose configuration.', originalError: err, data: { fileWithError: composeFiles[0] } });
627 }
628}
629
630export async function findComposeContainer(params: DockerCLIParameters | DockerResolverParameters, projectName: string, serviceName: string): Promise<string | undefined> {
631 const list = await listContainers(params, true, [

Callers 4

doBuildFunction · 0.90
getImageBuildInfoFunction · 0.90

Calls 6

parseVersionFunction · 0.90
toExecParametersFunction · 0.90
dockerComposeCLIFunction · 0.90
makeLogFunction · 0.90
dockerComposePtyCLIFunction · 0.90
writeMethod · 0.65

Tested by

no test coverage detected