Add configuration manager and setting for docker desktop path

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-11-20 20:52:16 -05:00
parent a9e3938f62
commit 2f5e5210b4
5 changed files with 108 additions and 15 deletions

View File

@@ -499,6 +499,18 @@
} }
] ]
}, },
"configuration": {
"title": "GitHub Local Actions",
"properties": {
"githubLocalActions.dockerDesktopPath": {
"type": "string",
"markdownDescription": "The path to your Docker Desktop executable (used for Windows and MacOS). To start Docker Engine from the `Components` view, this application will be launched. Refer to the default path based on OS:\n\n* **Windows**: `C:/Program Files/Docker/Docker/Docker Desktop.exe`\n\n* **MacOS**: `/Applications/Docker.app`\n\n* **Linux**: Not Required",
"items": {
"type": "string"
}
}
}
},
"colors": [ "colors": [
{ {
"id": "GitHubLocalActions.green", "id": "GitHubLocalActions.green",

View File

@@ -1,11 +1,14 @@
import * as childProcess from "child_process"; import * as childProcess from "child_process";
import { env, extensions, QuickPickItemKind, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, ThemeIcon, Uri, window } from "vscode"; import { commands, env, extensions, QuickPickItemKind, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, ThemeIcon, Uri, window } from "vscode";
import { ConfigurationManager, Platform, Section } from "./configurationManager";
import { act, componentsTreeDataProvider } from "./extension"; import { act, componentsTreeDataProvider } from "./extension";
import ComponentsTreeDataProvider from "./views/components/componentsTreeDataProvider";
export interface Component<T extends CliStatus | ExtensionStatus> { export interface Component<T extends CliStatus | ExtensionStatus> {
name: string, name: string,
icon: string, icon: string,
version?: string, version?: string,
path?: string,
status: T, status: T,
required: boolean, required: boolean,
information: string, information: string,
@@ -121,10 +124,12 @@ export class ComponentsManager {
}); });
const dockerCliInfo = await this.getCliInfo('docker version', /Client:\n.+\n\sVersion:\s+(.+)/, true, true); const dockerCliInfo = await this.getCliInfo('docker version', /Client:\n.+\n\sVersion:\s+(.+)/, true, true);
const dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
components.push({ components.push({
name: 'Docker Engine', name: 'Docker Engine',
icon: 'dashboard', icon: 'dashboard',
version: dockerCliInfo.version, version: dockerCliInfo.version,
path: dockerDesktopPath,
status: dockerCliInfo.status, status: dockerCliInfo.status,
required: true, required: true,
information: 'https://docs.docker.com/engine', information: 'https://docs.docker.com/engine',
@@ -132,15 +137,11 @@ export class ComponentsManager {
await env.openExternal(Uri.parse('https://docs.docker.com/engine/install')); await env.openExternal(Uri.parse('https://docs.docker.com/engine/install'));
}, },
start: async () => { start: async () => {
//TODO: Make the below win32 and darwin paths customizable const dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
switch (process.platform) { if (dockerDesktopPath) {
case 'win32': await env.openExternal(Uri.parse(dockerDesktopPath));
await env.openExternal(Uri.parse('C:/Program Files/Docker/Docker/Docker Desktop.exe')); } else {
break; if (process.platform === Platform.linux) {
case 'darwin':
await env.openExternal(Uri.parse('/Applications/Docker.app'));
break;
case 'linux':
await tasks.executeTask({ await tasks.executeTask({
name: 'Docker Engine', name: 'Docker Engine',
detail: 'Start Docker Engine', detail: 'Start Docker Engine',
@@ -162,15 +163,39 @@ export class ComponentsManager {
group: TaskGroup.Build, group: TaskGroup.Build,
execution: new ShellExecution('sudo dockerd') execution: new ShellExecution('sudo dockerd')
}); });
break; } else {
default: window.showErrorMessage(`Invalid environment: ${process.platform}`, 'Report an Issue').then(async value => {
window.showErrorMessage(`Invalid environment: ${process.platform}`); if (value === 'Report an Issue') {
await commands.executeCommand('githubLocalActions.reportAnIssue');
}
});
return; return;
} }
}
window.showInformationMessage('Once Docker Engine is successfully started (this could take a few seconds), refresh the components view.', 'Refresh').then(async value => { window.withProgress({ location: { viewId: ComponentsTreeDataProvider.VIEW_ID } }, async () => {
// Delay 4 seconds for Docker Desktop to be started
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
await delay(4000);
// Check again for docker status
const newDockerCliInfo = await this.getCliInfo('docker version', /Client:\n.+\n\sVersion:\s+(.+)/, true, true);
if (dockerCliInfo.status !== newDockerCliInfo.status) {
componentsTreeDataProvider.refresh();
} else {
const verificationMessage = process.platform === Platform.linux ?
'If it failed to start, start it manually.' :
'If it failed to start, configure your Docker Desktop path or start it manually.';
const options = process.platform === Platform.linux ?
['Refresh'] :
['Refresh', 'Configure Docker Desktop Path'];
window.showInformationMessage(`Once Docker Engine is successfully started, refresh the components view. ${verificationMessage}`, ...options).then(async value => {
if (value === 'Refresh') { if (value === 'Refresh') {
componentsTreeDataProvider.refresh(); componentsTreeDataProvider.refresh();
} else if (value === 'Configure Docker Desktop Path') {
await commands.executeCommand('workbench.action.openSettings', ConfigurationManager.getSearchTerm(Section.dockerDesktopPath));
}
});
} }
}); });
} }

View File

@@ -0,0 +1,46 @@
import { ConfigurationTarget, workspace } from 'vscode';
export enum Platform {
windows = 'win32',
mac = 'darwin',
linux = 'linux'
}
export enum Section {
dockerDesktopPath = 'dockerDesktopPath'
}
export namespace ConfigurationManager {
export const group: string = 'githubLocalActions';
export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions';
export function initialize(): void {
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
if (!dockerDesktopPath) {
switch (process.platform) {
case Platform.windows:
dockerDesktopPath = 'C:/Program Files/Docker/Docker/Docker Desktop.exe';
break;
case Platform.mac:
dockerDesktopPath = '/Applications/Docker.app';
break;
default:
return;
}
ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath);
}
}
export function getSearchTerm(section: Section): string {
return `${ConfigurationManager.searchPrefix} ${ConfigurationManager.group}.${section}`;
}
export function get<T>(section: Section): T | undefined {
return workspace.getConfiguration(ConfigurationManager.group).get(section) as T;
}
export async function set(section: Section, value: any): Promise<void> {
return await workspace.getConfiguration(ConfigurationManager.group).update(section, value, ConfigurationTarget.Global);
}
}

View File

@@ -1,6 +1,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { commands, env, TreeCheckboxChangeEvent, Uri, window, workspace } from 'vscode'; import { commands, env, TreeCheckboxChangeEvent, Uri, window, workspace } from 'vscode';
import { Act } from './act'; import { Act } from './act';
import { ConfigurationManager } from './configurationManager';
import ComponentsTreeDataProvider from './views/components/componentsTreeDataProvider'; import ComponentsTreeDataProvider from './views/components/componentsTreeDataProvider';
import { DecorationProvider } from './views/decorationProvider'; import { DecorationProvider } from './views/decorationProvider';
import { GithubLocalActionsTreeItem } from './views/githubLocalActionsTreeItem'; import { GithubLocalActionsTreeItem } from './views/githubLocalActionsTreeItem';
@@ -49,6 +50,14 @@ export function activate(context: vscode.ExtensionContext) {
settingsTreeDataProvider.refresh(); settingsTreeDataProvider.refresh();
}); });
// Initialize configurations
ConfigurationManager.initialize();
workspace.onDidChangeConfiguration(async event => {
if (event.affectsConfiguration(ConfigurationManager.group)) {
ConfigurationManager.initialize();
}
});
context.subscriptions.push( context.subscriptions.push(
componentsTreeView, componentsTreeView,
workflowsTreeView, workflowsTreeView,

View File

@@ -14,6 +14,7 @@ export default class ComponentTreeItem extends TreeItem implements GithubLocalAc
this.iconPath = new ThemeIcon(component.icon); this.iconPath = new ThemeIcon(component.icon);
this.resourceUri = Uri.parse(`${ComponentTreeItem.contextValue}:${component.name}?status=${component.status}&required=${component.required}`, true); this.resourceUri = Uri.parse(`${ComponentTreeItem.contextValue}:${component.name}?status=${component.status}&required=${component.required}`, true);
this.tooltip = `Name: ${component.name}\n` + this.tooltip = `Name: ${component.name}\n` +
(component.path ? `Path: ${component.path}\n` : ``) +
`Status: ${component.status}\n` + `Status: ${component.status}\n` +
`Required: ${component.required ? 'Yes' : 'No'}\n` + `Required: ${component.required ? 'Yes' : 'No'}\n` +
(component.message ? `Message: ${component.message}` : ``); (component.message ? `Message: ${component.message}` : ``);