Skip to content

Commit

Permalink
Use project name in compose group calls (#2788)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwateratmsft authored Mar 16, 2021
1 parent 7279594 commit 10f2e27
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/commands/containers/composeGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ export async function composeGroupDown(context: IActionContext, node: ContainerG
async function composeGroup(context: IActionContext, composeCommand: 'logs' | 'restart' | 'down', node: ContainerGroupTreeItem, additionalArguments?: string): Promise<void> {
const workingDirectory = getComposeWorkingDirectory(node);
const filesArgument = getComposeFiles(node)?.map(f => isWindows() ? `-f "${f}"` : `-f '${f}'`)?.join(' ');
const projectName = getProjectName(node);

if (!workingDirectory || !filesArgument) {
if (!workingDirectory || !filesArgument || !projectName) {
context.errorHandling.suppressReportIssue = true;
throw new Error(localize('vscode-docker.commands.containers.composeGroup.noCompose', 'Unable to determine compose project info for container group \'{0}\'.', node.label));
}

const terminalCommand = `docker-compose ${filesArgument} ${composeCommand} ${additionalArguments || ''}`;
const projectNameArgument = isWindows() ? `-p "${projectName}"` : `-p '${projectName}'`;

const terminalCommand = `docker-compose ${filesArgument} ${projectNameArgument} ${composeCommand} ${additionalArguments || ''}`;

await executeAsTask(context, await rewriteComposeCommandIfNeeded(terminalCommand), 'Docker Compose', { addDockerEnv: true, cwd: workingDirectory, });
}
Expand All @@ -52,3 +55,9 @@ function getComposeFiles(node: ContainerGroupTreeItem): string[] | undefined {
// (In short, the working dir may not be the same as the cwd when the docker-compose up command was called, BUT the files are relative to that cwd)
return container?.labels?.['com.docker.compose.project.config_files']?.split(',')?.map(f => path.parse(f).base);
}

function getProjectName(node: ContainerGroupTreeItem): string | undefined {
// Find a container with the `com.docker.compose.project` label, which gives the project name
const container = (node.ChildTreeItems as ContainerTreeItem[]).find(c => c.labels?.['com.docker.compose.project']);
return container?.labels?.['com.docker.compose.project'];
}

0 comments on commit 10f2e27

Please sign in to comment.