Skip to content

Commit

Permalink
Merge pull request #1603 from microsoft/ravipal/compose-with-nofiles
Browse files Browse the repository at this point in the history
use default files in docker-compose
  • Loading branch information
ravipal committed Feb 5, 2020
2 parents a71d9a5 + 8804dfd commit 3fef3bb
Showing 1 changed file with 32 additions and 4 deletions.
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}` })];
}
}

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

0 comments on commit 3fef3bb

Please sign in to comment.