Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use project name in compose group calls #2788

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
}