forked from microsoft/vscode-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to launch a subset of Compose services (microsoft#2514)
* New `docker-compose` task * New `${serviceList}` token for docker-compose up customizable command
- Loading branch information
1 parent
63c71a3
commit 7130ca3
Showing
14 changed files
with
373 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { IActionContext, IAzureQuickPickItem } from 'vscode-azureextensionui'; | ||
import { ext } from '../../extensionVariables'; | ||
import { localize } from '../../localize'; | ||
import { execAsync } from '../../utils/spawnAsync'; | ||
|
||
// Matches an `up` or `down` and everything after it--so that it can be replaced with `config --services`, to get a service list using all of the files originally part of the compose command | ||
const composeCommandReplaceRegex = /(\b(up|down)\b).*$/i; | ||
|
||
export async function getComposeServiceList(context: IActionContext, workspaceFolder: vscode.WorkspaceFolder, composeCommand: string): Promise<string> { | ||
const services = await getServices(workspaceFolder, composeCommand); | ||
|
||
// Fetch the previously chosen services list. By default, all will be selected. | ||
const workspaceServiceListKey = `vscode-docker.composeServices.${workspaceFolder.name}`; | ||
const previousChoices = ext.context.workspaceState.get<string[]>(workspaceServiceListKey, services); | ||
|
||
const pickChoices: IAzureQuickPickItem<string>[] = services.map(s => ({ | ||
label: s, | ||
data: s, | ||
picked: previousChoices.some(p => p === s), | ||
})); | ||
|
||
const subsetChoices = | ||
await ext.ui.showQuickPick( | ||
pickChoices, | ||
{ | ||
canPickMany: true, | ||
placeHolder: localize('vscode-docker.getComposeServiceList.choose', 'Choose services to start'), | ||
} | ||
); | ||
|
||
context.telemetry.measurements.totalServices = pickChoices.length; | ||
context.telemetry.measurements.chosenServices = subsetChoices.length; | ||
|
||
// Update the cache | ||
await ext.context.workspaceState.update(workspaceServiceListKey, subsetChoices.map(c => c.data)); | ||
|
||
return subsetChoices.map(c => c.data).join(' '); | ||
} | ||
|
||
async function getServices(workspaceFolder: vscode.WorkspaceFolder, composeCommand: string): Promise<string[]> { | ||
// Start by getting a new command with the exact same files list (replaces the "up ..." or "down ..." with "config --services") | ||
const configCommand = composeCommand.replace(composeCommandReplaceRegex, 'config --services'); | ||
|
||
const { stdout } = await execAsync(configCommand, { cwd: workspaceFolder.uri.fsPath }); | ||
|
||
// The output of the config command is a list of services, one per line | ||
// Split them up and remove empty entries | ||
return stdout.split(/\r?\n/im).filter(l => { return l; }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.