Skip to content

Commit

Permalink
Rewrite compose commands for ACI contexts (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwateratmsft authored Jul 16, 2020
1 parent 9a1539e commit 5317a18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/commands/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function compose(context: IActionContext, commands: ('up' | 'down')[], mes
detached,
build
);
terminal.sendText(terminalCommand);
terminal.sendText(await rewriteCommandForNewCliIfNeeded(terminalCommand));
} else {
for (const item of selectedItems) {
const terminalCommand = await selectComposeCommand(
Expand All @@ -57,7 +57,7 @@ async function compose(context: IActionContext, commands: ('up' | 'down')[], mes
detached,
build
);
terminal.sendText(terminalCommand);
terminal.sendText(await rewriteCommandForNewCliIfNeeded(terminalCommand));
}
}
terminal.show();
Expand All @@ -75,3 +75,12 @@ export async function composeDown(context: IActionContext, dockerComposeFileUri?
export async function composeRestart(context: IActionContext, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
return await compose(context, ['down', 'up'], localize('vscode-docker.commands.compose.chooseRestart', 'Choose Docker Compose file to restart'), dockerComposeFileUri, selectedComposeFileUris);
}

async function rewriteCommandForNewCliIfNeeded(command: string): Promise<string> {
if ((await ext.dockerContextManager.getCurrentContext()).Type === 'aci') {
// Replace 'docker-compose ' at the start of a string with 'docker compose ', and '--build' anywhere with ''
return command.replace(/^docker-compose /, 'docker compose ').replace(/--build/, '');
} else {
return command;
}
}
1 change: 1 addition & 0 deletions src/docker/ContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const defaultContext: Partial<DockerContext> = {
Description: 'Current DOCKER_HOST based configuration',
};

// These contexts are used by external consumers (e.g. the "Remote - Containers" extension), and should NOT be changed
type VSCodeContext = 'vscode-docker:aciContext' | 'vscode-docker:newSdkContext' | 'vscode-docker:newCliPresent';

export interface ContextManager {
Expand Down

0 comments on commit 5317a18

Please sign in to comment.