Skip to content

Commit

Permalink
Docker context support (#1790)
Browse files Browse the repository at this point in the history
Docker context changes are detected and UI/commands are refreshed accordingly
Also cleans up warning suppressions for async Dockerode calls
  • Loading branch information
karolz-ms authored Mar 30, 2020
1 parent 64750d8 commit 91b0d82
Show file tree
Hide file tree
Showing 52 changed files with 417 additions and 205 deletions.
2 changes: 1 addition & 1 deletion extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export { DotNetClient } from './src/debugging/coreclr/CommandLineDotNetClient';
export { compareBuildImageOptions, LaunchOptions } from './src/debugging/coreclr/dockerManager';
export { FileSystemProvider } from './src/debugging/coreclr/fsProvider';
export { LineSplitter } from './src/debugging/coreclr/lineSplitter';
export { OSProvider } from './src/debugging/coreclr/LocalOSProvider';
export { OSProvider } from './src/utils/LocalOSProvider';
export { DockerDaemonIsLinuxPrerequisite, DockerfileExistsPrerequisite, DotNetSdkInstalledPrerequisite, LinuxUserInDockerGroupPrerequisite, MacNuGetFallbackFolderSharedPrerequisite } from './src/debugging/coreclr/prereqManager';
export { ext } from './src/extensionVariables';
export { globAsync } from './src/utils/globAsync';
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,11 @@
"default": 2000,
"description": "%vscode-docker.config.docker.explorerRefreshInterval%"
},
"docker.contextRefreshInterval": {
"type": "number",
"default": 20,
"description": "%vscode-docker.config.docker.contextRefreshInterval%"
},
"docker.commands.build": {
"oneOf": [
{
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"vscode-docker.config.template.composeDown.match": "The regular expression for choosing the right template. Checked against docker-compose YAML files, folder name, etc.",
"vscode-docker.config.template.composeDown.description": "Command templates for `docker-compose down` commands.",
"vscode-docker.config.docker.explorerRefreshInterval": "Docker view refresh interval (milliseconds)",
"vscode-docker.config.docker.contextRefreshInterval": "How often Docker context is checked for changes (seconds)",
"vscode-docker.config.docker.containers.groupBy": "The property to use to group containers in Docker view: ContainerId, ContainerName, CreatedTime, FullTag, ImageId, Networks, Ports, Registry, Repository, RepositoryName, RepositoryNameAndTag, State, Status, Tag, or None",
"vscode-docker.config.docker.containers.description": "Any secondary properties to display for a container (an array). Possible elements include: ContainerId, ContainerName, CreatedTime, FullTag, ImageId, Networks, Ports, Registry, Repository, RepositoryName, RepositoryNameAndTag, State, Status, and Tag",
"vscode-docker.config.docker.containers.label": "The primary property to display for a container: ContainerId, ContainerName, CreatedTime, FullTag, ImageId, Networks, Ports, Registry, Repository, RepositoryName, RepositoryNameAndTag, State, Status, or Tag",
Expand Down
10 changes: 4 additions & 6 deletions src/commands/containers/browseContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IActionContext, TelemetryProperties } from "vscode-azureextensionui";
import { ext } from "../../extensionVariables";
import { localize } from '../../localize';
import { ContainerTreeItem } from "../../tree/containers/ContainerTreeItem";
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { captureCancelStep } from '../../utils/captureCancelStep';

type BrowseTelemetryProperties = TelemetryProperties & { possiblePorts?: number[], selectedPort?: number };
Expand Down Expand Up @@ -59,17 +59,15 @@ export async function browseContainer(context: IActionContext, node?: ContainerT
const telemetryProperties = <BrowseTelemetryProperties>context.telemetry.properties;

if (!node) {
/* eslint-disable-next-line @typescript-eslint/promise-function-async */
node = await captureBrowseCancelStep('node', telemetryProperties, () =>
node = await captureBrowseCancelStep('node', telemetryProperties, async () =>
ext.containersTree.showTreeItemPicker<ContainerTreeItem>(ContainerTreeItem.runningContainerRegExp, {
...context,
noItemFoundErrorMessage: localize('vscode-docker.commands.containers.browseContainer.noContainers', 'No running containers are available to open in a browser')
}));
}

const container = node.getContainer();
/* eslint-disable-next-line @typescript-eslint/promise-function-async */
const inspectInfo: ContainerInspectInfo = await callDockerodeWithErrorHandling(() => container.inspect(), context);
const container = await node.getContainer();
const inspectInfo: ContainerInspectInfo = await callDockerodeWithErrorHandling(async () => container.inspect(), context);

const ports = inspectInfo && inspectInfo.NetworkSettings && inspectInfo.NetworkSettings.Ports || {};
const possiblePorts =
Expand Down
7 changes: 3 additions & 4 deletions src/commands/containers/inspectContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IActionContext, openReadOnlyJson } from "vscode-azureextensionui";
import { ext } from "../../extensionVariables";
import { localize } from '../../localize';
import { ContainerTreeItem } from "../../tree/containers/ContainerTreeItem";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerodeWithErrorHandling";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerode";

export async function inspectContainer(context: IActionContext, node?: ContainerTreeItem): Promise<void> {
if (!node) {
Expand All @@ -18,8 +18,7 @@ export async function inspectContainer(context: IActionContext, node?: Container
});
}

const container = node.getContainer();
// eslint-disable-next-line @typescript-eslint/promise-function-async
const inspectInfo: ContainerInspectInfo = await callDockerodeWithErrorHandling(() => container.inspect(), context);
const container = await node.getContainer();
const inspectInfo: ContainerInspectInfo = await callDockerodeWithErrorHandling(async () => container.inspect(), context);
await openReadOnlyJson(node, inspectInfo);
}
5 changes: 2 additions & 3 deletions src/commands/containers/pruneContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { convertToMB } from '../../utils/convertToMB';

export async function pruneContainers(context: IActionContext): Promise<void> {
Expand All @@ -18,8 +18,7 @@ export async function pruneContainers(context: IActionContext): Promise<void> {
await vscode.window.withProgress(
{ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.containers.pruning', 'Pruning containers...') },
async () => {
/* eslint-disable-next-line @typescript-eslint/promise-function-async */
const result = await callDockerodeWithErrorHandling(() => ext.dockerode.pruneContainers(), context);
const result = await callDockerodeWithErrorHandling(async () => ext.dockerode.pruneContainers(), context);

const numDeleted = (result.ContainersDeleted || []).length;
const mbReclaimed = convertToMB(result.SpaceReclaimed);
Expand Down
7 changes: 3 additions & 4 deletions src/commands/containers/restartContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ContainerTreeItem } from '../../tree/containers/ContainerTreeItem';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { multiSelectNodes } from '../../utils/multiSelectNodes';

export async function restartContainer(context: IActionContext, node?: ContainerTreeItem, nodes?: ContainerTreeItem[]): Promise<void> {
Expand All @@ -23,9 +23,8 @@ export async function restartContainer(context: IActionContext, node?: Container

await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.containers.restart.restarting', 'Restarting Container(s)...') }, async () => {
await Promise.all(nodes.map(async n => {
const container: Container = n.getContainer();
// eslint-disable-next-line @typescript-eslint/promise-function-async
await callDockerodeWithErrorHandling(() => container.restart(), context);
const container: Container = await n.getContainer();
await callDockerodeWithErrorHandling(async () => container.restart(), context);
}));
});
}
7 changes: 3 additions & 4 deletions src/commands/containers/startContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ContainerTreeItem } from '../../tree/containers/ContainerTreeItem';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { multiSelectNodes } from '../../utils/multiSelectNodes';

export async function startContainer(context: IActionContext, node?: ContainerTreeItem, nodes?: ContainerTreeItem[]): Promise<void> {
Expand All @@ -23,9 +23,8 @@ export async function startContainer(context: IActionContext, node?: ContainerTr

await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.containers.start.starting', 'Starting Container(s)...') }, async () => {
await Promise.all(nodes.map(async n => {
const container: Container = n.getContainer();
// eslint-disable-next-line @typescript-eslint/promise-function-async
await callDockerodeWithErrorHandling(() => container.start(), context);
const container: Container = await n.getContainer();
await callDockerodeWithErrorHandling(async () => container.start(), context);
}));
});
}
8 changes: 3 additions & 5 deletions src/commands/containers/stopContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ContainerTreeItem } from '../../tree/containers/ContainerTreeItem';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { multiSelectNodes } from '../../utils/multiSelectNodes';

export async function stopContainer(context: IActionContext, node?: ContainerTreeItem, nodes?: ContainerTreeItem[]): Promise<void> {
Expand All @@ -23,10 +23,8 @@ export async function stopContainer(context: IActionContext, node?: ContainerTre

await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.containers.stop.stopping', 'Stopping Container(s)...') }, async () => {
await Promise.all(nodes.map(async n => {
const container: Container = n.getContainer();
// eslint-disable-next-line @typescript-eslint/promise-function-async
await callDockerodeWithErrorHandling(() => container.stop(), context);

const container: Container = await n.getContainer();
await callDockerodeWithErrorHandling(async () => container.stop(), context);
}));
});
}
7 changes: 3 additions & 4 deletions src/commands/images/inspectImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IActionContext, openReadOnlyJson } from "vscode-azureextensionui";
import { ext } from "../../extensionVariables";
import { localize } from '../../localize';
import { ImageTreeItem } from "../../tree/images/ImageTreeItem";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerodeWithErrorHandling";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerode";

export async function inspectImage(context: IActionContext, node?: ImageTreeItem): Promise<void> {
if (!node) {
Expand All @@ -18,8 +18,7 @@ export async function inspectImage(context: IActionContext, node?: ImageTreeItem
});
}

const image: Image = node.getImage();
// eslint-disable-next-line @typescript-eslint/promise-function-async
const inspectInfo: ImageInspectInfo = await callDockerodeWithErrorHandling(() => image.inspect(), context);
const image: Image = await node.getImage();
const inspectInfo: ImageInspectInfo = await callDockerodeWithErrorHandling(async () => image.inspect(), context);
await openReadOnlyJson(node, inspectInfo);
}
5 changes: 2 additions & 3 deletions src/commands/images/pruneImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { convertToMB } from '../../utils/convertToMB';

export async function pruneImages(context: IActionContext): Promise<void> {
Expand All @@ -18,8 +18,7 @@ export async function pruneImages(context: IActionContext): Promise<void> {
await vscode.window.withProgress(
{ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.images.pruning', 'Pruning images...') },
async () => {
/* eslint-disable-next-line @typescript-eslint/promise-function-async */
const result = await callDockerodeWithErrorHandling(() => ext.dockerode.pruneImages(), context);
const result = await callDockerodeWithErrorHandling(async () => ext.dockerode.pruneImages(), context);

const numDeleted = (result.ImagesDeleted || []).length;
const mbReclaimed = convertToMB(result.SpaceReclaimed);
Expand Down
3 changes: 2 additions & 1 deletion src/commands/images/runImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ async function runImageCore(context: IActionContext, node: ImageTreeItem | undef
});
}

const inspectInfo = await node.getImage().inspect();
const image = await node.getImage();
const inspectInfo = await image.inspect();

const terminalCommand = await selectRunCommand(
context,
Expand Down
7 changes: 3 additions & 4 deletions src/commands/images/tagImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ImageTreeItem } from '../../tree/images/ImageTreeItem';
import { RegistryTreeItemBase } from '../../tree/registries/RegistryTreeItemBase';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';
import { extractRegExGroups } from '../../utils/extractRegExGroups';

export async function tagImage(context: IActionContext, node?: ImageTreeItem, registry?: RegistryTreeItemBase): Promise<string> {
Expand All @@ -33,9 +33,8 @@ export async function tagImage(context: IActionContext, node?: ImageTreeItem, re
tag = newTaggedName.slice(newTaggedName.lastIndexOf(':') + 1);
}

const image: Image = node.getImage();
// eslint-disable-next-line @typescript-eslint/promise-function-async
await callDockerodeWithErrorHandling(() => image.tag({ repo: repo, tag: tag }), context);
const image: Image = await node.getImage();
await callDockerodeWithErrorHandling(async () => image.tag({ repo: repo, tag: tag }), context);
return newTaggedName;
}

Expand Down
7 changes: 3 additions & 4 deletions src/commands/networks/createNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { window } from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeAsync, callDockerodeWithErrorHandling } from '../../utils/callDockerode';

export async function createNetwork(context: IActionContext): Promise<void> {

Expand All @@ -16,7 +16,7 @@ export async function createNetwork(context: IActionContext): Promise<void> {
prompt: localize('vscode-docker.commands.networks.create.promptName', 'Name of the network')
});

const engineVersion = await ext.dockerode.version();
const engineVersion = await callDockerodeAsync(async () => ext.dockerode.version());
const drivers = engineVersion.Os === 'windows'
? [
{ label: 'nat' },
Expand All @@ -36,8 +36,7 @@ export async function createNetwork(context: IActionContext): Promise<void> {
}
);

/* eslint-disable-next-line @typescript-eslint/promise-function-async */
const result = <{ id: string }>await callDockerodeWithErrorHandling(() => ext.dockerode.createNetwork({ Name: name, Driver: driverSelection.label }), context);
const result = <{ id: string }>await callDockerodeWithErrorHandling(async () => ext.dockerode.createNetwork({ Name: name, Driver: driverSelection.label }), context);

/* eslint-disable-next-line @typescript-eslint/no-floating-promises */
window.showInformationMessage(localize('vscode-docker.commands.networks.create.created', 'Network Created with ID {0}', result.id.substr(0, 12)));
Expand Down
8 changes: 4 additions & 4 deletions src/commands/networks/inspectNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IActionContext, openReadOnlyJson } from "vscode-azureextensionui";
import { ext } from "../../extensionVariables";
import { localize } from '../../localize';
import { NetworkTreeItem } from "../../tree/networks/NetworkTreeItem";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerodeWithErrorHandling";
import { callDockerodeWithErrorHandling } from "../../utils/callDockerode";

export async function inspectNetwork(context: IActionContext, node?: NetworkTreeItem): Promise<void> {
if (!node) {
Expand All @@ -18,8 +18,8 @@ export async function inspectNetwork(context: IActionContext, node?: NetworkTree
});
}

const network: Network = node.getNetwork()
// eslint-disable-next-line @typescript-eslint/promise-function-async, @typescript-eslint/tslint/config
const inspectInfo: {} = await callDockerodeWithErrorHandling(() => network.inspect(), context); // inspect is missing type in @types/dockerode
const network: Network = await node.getNetwork()
// eslint-disable-next-line @typescript-eslint/tslint/config
const inspectInfo: {} = await callDockerodeWithErrorHandling(async () => network.inspect(), context); // inspect is missing type in @types/dockerode
await openReadOnlyJson(node, inspectInfo);
}
5 changes: 2 additions & 3 deletions src/commands/networks/pruneNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerodeWithErrorHandling';
import { callDockerodeWithErrorHandling } from '../../utils/callDockerode';

export async function pruneNetworks(context: IActionContext): Promise<void> {
const confirmPrune: string = localize('vscode-docker.commands.networks.prune.confirm', 'Are you sure you want to remove all unused networks?');
Expand All @@ -17,8 +17,7 @@ export async function pruneNetworks(context: IActionContext): Promise<void> {
await vscode.window.withProgress(
{ location: vscode.ProgressLocation.Notification, title: localize('vscode-docker.commands.networks.pruning', 'Pruning networks...') },
async () => {
/* eslint-disable-next-line @typescript-eslint/promise-function-async */
const result = await callDockerodeWithErrorHandling(() => ext.dockerode.pruneNetworks(), context);
const result = await callDockerodeWithErrorHandling(async () => ext.dockerode.pruneNetworks(), context);

const numDeleted = (result.NetworksDeleted || []).length;
let message = localize('vscode-docker.commands.networks.prune.removed', 'Removed {0} networks(s).', numDeleted);
Expand Down
Loading

0 comments on commit 91b0d82

Please sign in to comment.