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 default files in docker-compose #1603

Merged
merged 2 commits into from
Feb 5, 2020
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
36 changes: 32 additions & 4 deletions src/commands/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ async function compose(commands: ('up' | 'down')[], message: string, dockerCompo
}

const items: vscode.QuickPickItem[] = computeItems(folder, uris);
selectedItems = [<Item>await ext.ui.showQuickPick(items, { placeHolder: `Choose Docker Compose file ${message}` })];

if ((items.length === 1 && isDefaultDockerComposeFile(items[0].label))
|| (items.length === 2 && items.some(i => isDefaultDockerComposeFile(i.label)) && items.some(i => isDefaultDockerComposeOverrideFile(i.label)))) {
// if the current set of docker files contain only docker-compose.yml or docker-compose.yml with override file,
// don't ask user for a docker file and let docker-compose automatically pick these files.
} else {
selectedItems = [<Item>await ext.ui.showQuickPick(items, { placeHolder: `Choose Docker Compose file ${message}` })];
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
}
}

const terminal: vscode.Terminal = ext.terminalProvider.createTerminal('Docker Compose');
Expand All @@ -71,12 +78,33 @@ async function compose(commands: ('up' | 'down')[], message: string, dockerCompo

terminal.sendText(`cd "${folder.uri.fsPath}"`);
for (let command of commands) {
selectedItems.forEach((item: Item) => {
terminal.sendText(command.toLowerCase() === 'up' ? `docker-compose -f "${item.file}" ${command} ${detached} ${build}` : `docker-compose -f "${item.file}" ${command}`);
});
if (selectedItems.length === 0) {
terminal.sendText(command.toLowerCase() === 'up' ? `docker-compose ${command} ${detached} ${build}` : `docker-compose ${command}`);
} else {
selectedItems.forEach((item: Item) => {
terminal.sendText(command.toLowerCase() === 'up' ? `docker-compose -f "${item.file}" ${command} ${detached} ${build}` : `docker-compose -f "${item.file}" ${command}`);
});
}
terminal.show();
}
}

function isDefaultDockerComposeFile(fileName: string): boolean {
if (fileName) {
const lowerCasefileName: string = fileName.toLowerCase();
return lowerCasefileName === 'docker-compose.yml' || lowerCasefileName === 'docker-compose.yaml'
}

return false;
}

function isDefaultDockerComposeOverrideFile(fileName: string): boolean {
if (fileName) {
const lowerCasefileName: string = fileName.toLowerCase();
return lowerCasefileName === 'docker-compose.override.yml' || lowerCasefileName === 'docker-compose.override.yaml'
}

return false;
}

export async function composeUp(_context: IActionContext, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
Expand Down