forked from microsoft/vscode-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdockerExtension.ts
220 lines (187 loc) · 11.2 KB
/
dockerExtension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as path from 'path';
import { DockerComposeHoverProvider } from './dockerCompose/dockerComposeHoverProvider';
import { DockerfileCompletionItemProvider } from './dockerfile/dockerfileCompletionItemProvider';
import { DockerComposeCompletionItemProvider } from './dockerCompose/dockerComposeCompletionItemProvider';
import composeVersionKeys from './dockerCompose/dockerComposeKeyInfo';
import { DockerComposeParser } from './dockerCompose/dockerComposeParser';
import vscode = require('vscode');
import { buildImage } from './commands/build-image';
import inspectImageCommand from './commands/inspect-image';
import { removeImage } from './commands/remove-image';
import { pushImage } from './commands/push-image';
import { pushAzure } from './commands/push-azure';
import { startContainer, startContainerInteractive, startAzureCLI } from './commands/start-container';
import { stopContainer } from './commands/stop-container';
import { restartContainer } from './commands/restart-container';
import { showLogsContainer } from './commands/showlogs-container';
import { openShellContainer } from './commands/open-shell-container';
import { tagImage } from './commands/tag-image';
import { composeUp, composeDown } from './commands/docker-compose';
import { configure } from './configureWorkspace/configure';
import { systemPrune } from './commands/system-prune';
import { Reporter } from './telemetry/telemetry';
import DockerInspectDocumentContentProvider, { SCHEME as DOCKER_INSPECT_SCHEME } from './documentContentProviders/dockerInspect';
import { DockerExplorerProvider } from './explorer/dockerExplorer';
import { removeContainer } from './commands/remove-container';
import { DocumentSelector, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Middleware, ConfigurationParams, DidChangeConfigurationNotification } from 'vscode-languageclient';
import { WebAppCreator } from './explorer/deploy/webAppCreator';
import { AzureImageNode, AzureRegistryNode, AzureRepositoryNode } from './explorer/models/azureRegistryNodes';
import { DockerHubImageNode, DockerHubRepositoryNode, DockerHubOrgNode } from './explorer/models/dockerHubNodes';
import { AzureAccountWrapper } from './explorer/deploy/azureAccountWrapper';
import * as util from "./explorer/deploy/util";
import { dockerHubLogout, browseDockerHub } from './explorer/utils/dockerHubUtils';
import { AzureAccount } from './typings/azure-account.api';
import * as opn from 'opn';
import { DockerDebugConfigProvider } from './configureWorkspace/configDebugProvider';
import { browseAzurePortal } from './explorer/utils/azureUtils';
export const FROM_DIRECTIVE_PATTERN = /^\s*FROM\s*([\w-\/:]*)(\s*AS\s*[a-z][a-z0-9-_\\.]*)?$/i;
export const COMPOSE_FILE_GLOB_PATTERN = '**/[dD]ocker-[cC]ompose*.{yaml,yml}';
export const DOCKERFILE_GLOB_PATTERN = '**/{*.dockerfile,[dD]ocker[fF]ile}';
export var diagnosticCollection: vscode.DiagnosticCollection;
export var dockerExplorerProvider: DockerExplorerProvider;
export type KeyInfo = { [keyName: string]: string; };
export interface ComposeVersionKeys {
All: KeyInfo,
v1: KeyInfo,
v2: KeyInfo
};
let client: LanguageClient;
const DOCUMENT_SELECTOR: DocumentSelector = [
{ language: 'dockerfile', scheme: 'file' }
];
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
const installedExtensions: any[] = vscode.extensions.all;
const outputChannel = util.getOutputChannel();
let azureAccount: AzureAccount;
for (var i = 0; i < installedExtensions.length; i++) {
const ext = installedExtensions[i];
if (ext.id === 'ms-vscode.azure-account') {
try {
azureAccount = await ext.activate();
} catch (error) {
console.log('Failed to activate the Azure Account Extension: ' + error);
}
break;
}
}
ctx.subscriptions.push(new Reporter(ctx));
dockerExplorerProvider = new DockerExplorerProvider(azureAccount);
vscode.window.registerTreeDataProvider('dockerExplorer', dockerExplorerProvider);
vscode.commands.registerCommand('vscode-docker.explorer.refresh', () => dockerExplorerProvider.refresh());
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(DOCUMENT_SELECTOR, new DockerfileCompletionItemProvider(), '.'));
const YAML_MODE_ID: vscode.DocumentFilter = { language: 'yaml', scheme: 'file', pattern: COMPOSE_FILE_GLOB_PATTERN };
var yamlHoverProvider = new DockerComposeHoverProvider(new DockerComposeParser(), composeVersionKeys.All);
ctx.subscriptions.push(vscode.languages.registerHoverProvider(YAML_MODE_ID, yamlHoverProvider));
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(YAML_MODE_ID, new DockerComposeCompletionItemProvider(), '.'));
ctx.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(DOCKER_INSPECT_SCHEME, new DockerInspectDocumentContentProvider()));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.configure', configure));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.build', buildImage));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.inspect', inspectImageCommand));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.remove', removeImage));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.push', pushImage));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.pushToAzure', pushAzure));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.image.tag', tagImage));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.start', startContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.start.interactive', startContainerInteractive));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.start.azurecli', startAzureCLI));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.stop', stopContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.restart', restartContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.show-logs', showLogsContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.open-shell', openShellContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.container.remove', removeContainer));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.compose.up', composeUp));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.compose.down', composeDown));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.system.prune', systemPrune));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.createWebApp', async (context?: AzureImageNode | DockerHubImageNode) => {
if (context) {
if (azureAccount) {
const azureAccountWrapper = new AzureAccountWrapper(ctx, azureAccount);
const wizard = new WebAppCreator(outputChannel, azureAccountWrapper, context);
const result = await wizard.run();
} else {
const open: vscode.MessageItem = { title: "View in Marketplace" };
const response = await vscode.window.showErrorMessage('Please install the Azure Account extension to deploy to Azure.', open);
if (response === open) {
opn('https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account');
}
}
}
}));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.dockerHubLogout', dockerHubLogout));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.browseDockerHub', async (context?: DockerHubImageNode | DockerHubRepositoryNode | DockerHubOrgNode) => {
browseDockerHub(context);
}));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.browseAzurePortal', async (context?: AzureRegistryNode | AzureRepositoryNode | AzureImageNode ) => {
browseAzurePortal(context);
}));
ctx.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('docker', new DockerDebugConfigProvider()));
activateLanguageClient(ctx);
}
export function deactivate(): Thenable<void> {
if (!client) {
return undefined;
}
// perform cleanup
Configuration.dispose();
return client.stop();
}
namespace Configuration {
let configurationListener: vscode.Disposable;
export function computeConfiguration(params: ConfigurationParams): vscode.WorkspaceConfiguration[] {
if (!params.items) {
return null;
}
let result: vscode.WorkspaceConfiguration[] = [];
for (let item of params.items) {
let config = null;
if (item.scopeUri) {
config = vscode.workspace.getConfiguration(item.section, client.protocol2CodeConverter.asUri(item.scopeUri));
} else {
config = vscode.workspace.getConfiguration(item.section);
}
result.push(config);
}
return result;
}
export function initialize() {
configurationListener = vscode.workspace.onDidChangeConfiguration(() => {
// notify the language server that settings have change
client.sendNotification(DidChangeConfigurationNotification.type, { settings: null });
});
}
export function dispose() {
if (configurationListener) {
// remove this listener when disposed
configurationListener.dispose();
}
}
}
function activateLanguageClient(ctx: vscode.ExtensionContext) {
let serverModule = ctx.asAbsolutePath(path.join("node_modules", "dockerfile-language-server-nodejs", "lib", "server.js"));
let debugOptions = { execArgv: ["--nolazy", "--debug=6009"] };
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc, args: ["--node-ipc"] },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
let middleware: Middleware = {
workspace: {
configuration: Configuration.computeConfiguration
}
};
let clientOptions: LanguageClientOptions = {
documentSelector: DOCUMENT_SELECTOR,
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/.clientrc')
},
middleware: middleware as Middleware
}
client = new LanguageClient("dockerfile-langserver", "Dockerfile Language Server", serverOptions, clientOptions);
client.onReady().then(() => {
// attach the VS Code settings listener
Configuration.initialize();
});
client.start();
}