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

Subset of services experiment #2657

Merged
merged 7 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"onCommand:vscode-docker.compose.down",
"onCommand:vscode-docker.compose.restart",
"onCommand:vscode-docker.compose.up",
"onCommand:vscode-docker.compose.up.subset",
"onCommand:vscode-docker.configure",
"onCommand:vscode-docker.configureCompose",
"onCommand:vscode-docker.containers.attachShell",
Expand Down Expand Up @@ -172,6 +173,10 @@
{
"command": "vscode-docker.contexts.use",
"when": "!vscode-docker:contextLocked"
},
{
"command": "vscode-docker.compose.up.subset",
"when": "vscode-docker:composeSubsetExp"
}
],
"editor/context": [
Expand Down Expand Up @@ -200,6 +205,11 @@
"command": "vscode-docker.compose.up",
"group": "docker"
},
{
"when": "resourceFilename =~ /compose.*\\.ya?ml$/i && vscode-docker:composeSubsetExp",
"command": "vscode-docker.compose.up.subset",
"group": "docker"
},
{
"when": "editorLangId == dockerfile",
"command": "vscode-docker.images.build",
Expand Down Expand Up @@ -232,6 +242,11 @@
"command": "vscode-docker.compose.up",
"group": "docker"
},
{
"when": "resourceFilename =~ /compose.*\\.ya?ml$/i && vscode-docker:composeSubsetExp",
"command": "vscode-docker.compose.up.subset",
"group": "docker"
},
{
"when": "resourceFilename =~ /dockerfile/i",
"command": "vscode-docker.images.build",
Expand Down Expand Up @@ -2172,6 +2187,11 @@
"title": "%vscode-docker.commands.compose.up%",
"category": "%vscode-docker.commands.category.docker%"
},
{
"command": "vscode-docker.compose.up.subset",
"title": "%vscode-docker.commands.compose.up.subset%",
"category": "%vscode-docker.commands.category.docker%"
},
{
"command": "vscode-docker.configure",
"title": "%vscode-docker.commands.configure%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"vscode-docker.commands.compose.down": "Compose Down",
"vscode-docker.commands.compose.restart": "Compose Restart",
"vscode-docker.commands.compose.up": "Compose Up",
"vscode-docker.commands.compose.up.subset": "Compose Up - Choose Services",
"vscode-docker.commands.configure": "Add Docker Files to Workspace...",
"vscode-docker.commands.configureCompose": "Add Docker Compose Files to Workspace...",
"vscode-docker.commands.containers.attachShell": "Attach Shell",
Expand Down
20 changes: 18 additions & 2 deletions src/commands/compose/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { rewriteComposeCommandIfNeeded } from '../../docker/Contexts';
import { ext } from '../../extensionVariables';
import { localize } from "../../localize";
import { executeAsTask } from '../../utils/executeAsTask';
import { createFileItem, Item, quickPickDockerComposeFileItem } from '../../utils/quickPickFile';
import { quickPickWorkspaceFolder } from '../../utils/quickPickWorkspaceFolder';
import { selectComposeCommand } from '../selectCommandTemplate';
import { getComposeServiceList } from './getComposeServiceList';

async function compose(context: IActionContext, commands: ('up' | 'down')[], message: string, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
async function compose(context: IActionContext, commands: ('up' | 'down' | 'upSubset')[], message: string, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
const folder: vscode.WorkspaceFolder = await quickPickWorkspaceFolder(context, localize('vscode-docker.commands.compose.workspaceFolder', 'To run Docker compose you must first open a folder or workspace in VS Code.'));

let commandParameterFileUris: vscode.Uri[];
Expand Down Expand Up @@ -46,12 +47,17 @@ async function compose(context: IActionContext, commands: ('up' | 'down')[], mes
let terminalCommand = await selectComposeCommand(
context,
folder,
command,
command === 'down' ? 'down' : 'up',
item?.relativeFilePath,
detached,
build
);

if (command === 'upSubset' && !serviceListPlaceholder.test(terminalCommand)) {
// eslint-disable-next-line no-template-curly-in-string
terminalCommand += ' ${serviceList}';
}

// Add the service list if needed
terminalCommand = await addServicesListIfNeeded(context, folder, terminalCommand);

Expand All @@ -67,6 +73,10 @@ export async function composeUp(context: IActionContext, dockerComposeFileUri?:
return await compose(context, ['up'], localize('vscode-docker.commands.compose.chooseUp', 'Choose Docker Compose file to bring up'), dockerComposeFileUri, selectedComposeFileUris);
}

export async function composeUpSubset(context: IActionContext, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
return await compose(context, ['upSubset'], localize('vscode-docker.commands.compose.chooseUpSubset', 'Choose Docker Compose file to bring up'), dockerComposeFileUri, selectedComposeFileUris);
}

export async function composeDown(context: IActionContext, dockerComposeFileUri?: vscode.Uri, selectedComposeFileUris?: vscode.Uri[]): Promise<void> {
return await compose(context, ['down'], localize('vscode-docker.commands.compose.chooseDown', 'Choose Docker Compose file to take down'), dockerComposeFileUri, selectedComposeFileUris);
}
Expand All @@ -75,6 +85,12 @@ export async function composeRestart(context: IActionContext, dockerComposeFileU
return await compose(context, ['down', 'up'], localize('vscode-docker.commands.compose.chooseRestart', 'Choose Docker Compose file to restart'), dockerComposeFileUri, selectedComposeFileUris);
}

export async function activateComposeUpSubsetExperiment(): Promise<void> {
if (await ext.experimentationService.isCachedFlightEnabled('vscode-docker.composeSubset')) {
await vscode.commands.executeCommand('setContext', 'vscode-docker:composeSubsetExp', true);
}
}

const serviceListPlaceholder = /\${serviceList}/i;
async function addServicesListIfNeeded(context: IActionContext, workspaceFolder: vscode.WorkspaceFolder, command: string): Promise<string> {
if (serviceListPlaceholder.test(command)) {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ext } from "../extensionVariables";
import { scaffold } from "../scaffolding/scaffold";
import { scaffoldCompose } from "../scaffolding/scaffoldCompose";
import { scaffoldDebugConfig } from "../scaffolding/scaffoldDebugConfig";
import { composeDown, composeRestart, composeUp } from "./compose/compose";
import { activateComposeUpSubsetExperiment, composeDown, composeRestart, composeUp, composeUpSubset } from "./compose/compose";
import { attachShellContainer } from "./containers/attachShellContainer";
import { browseContainer } from "./containers/browseContainer";
import { composeGroupDown, composeGroupLogs, composeGroupRestart } from "./containers/composeGroup";
Expand Down Expand Up @@ -118,6 +118,8 @@ export function registerCommands(): void {
registerWorkspaceCommand('vscode-docker.compose.down', composeDown);
registerWorkspaceCommand('vscode-docker.compose.restart', composeRestart);
registerWorkspaceCommand('vscode-docker.compose.up', composeUp);
registerWorkspaceCommand('vscode-docker.compose.up.subset', composeUpSubset);
void activateComposeUpSubsetExperiment();
registerCommand('vscode-docker.pruneSystem', pruneSystem);

registerWorkspaceCommand('vscode-docker.containers.attachShell', attachShellContainer);
Expand Down