+
Skip to content

Add a button 'Start Docker' #214

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

Merged
merged 9 commits into from
Oct 17, 2022
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
2 changes: 1 addition & 1 deletion src/command/Complain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'inversify';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import { COMPLAIN_COMMAND, COMPLAIN_URL } from 'constant';
Expand Down
2 changes: 1 addition & 1 deletion src/command/EnterLicense.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import JobProvider from 'job/JobProvider';
import LicenseInput from 'license/LicenseInput';
import LicenseProvider from 'license/LicenseProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/command/EnterToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import { getBinaryPath } from '../../node/binary';
import EditorGateway from 'gateway/EditorGateway';
import Types from 'common/Types';
Expand Down
2 changes: 1 addition & 1 deletion src/command/ExitAllJobs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import CommittedImages from 'containerization/CommittedImages';
import EditorGateway from 'gateway/EditorGateway';
Expand Down
2 changes: 1 addition & 1 deletion src/command/ExitJob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import JobFactory from 'job/JobFactory';
import JobProvider from 'job/JobProvider';
import JobRunner from 'job/JobRunner';
Expand Down
2 changes: 1 addition & 1 deletion src/command/GetLicense.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'inversify';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import { GET_LICENSE_COMMAND, GET_LICENSE_KEY_URL } from 'constant';
Expand Down
2 changes: 1 addition & 1 deletion src/command/Help.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'inversify';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import ReporterGateway from 'gateway/ReporterGateway';
Expand Down
2 changes: 1 addition & 1 deletion src/command/ReRunJob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import JobProvider from 'job/JobProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/command/Refresh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import JobProvider from 'job/JobProvider';
import { JOB_TREE_VIEW_ID } from 'constant';

Expand Down
2 changes: 1 addition & 1 deletion src/command/RefreshLicenseTree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import EditorGateway from 'gateway/EditorGateway';
import JobProvider from 'job/JobProvider';
import LicenseProvider from 'license/LicenseProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/command/RunJob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import EditorGateway from 'gateway/EditorGateway';
import JobProvider from 'job/JobProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/command/SelectRepo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from './index';
import type { Command } from '.';
import Types from 'common/Types';
import AllConfigFiles from 'config/AllConfigFiles';
import CommittedImages from 'containerization/CommittedImages';
Expand Down
2 changes: 1 addition & 1 deletion src/command/ShowLogFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'inversify';
import type { Command } from './index';
import type { Command } from '.';
import LogFile from 'log/LogFile';
import { SHOW_LOG_FILE_COMMAND } from 'constant';

Expand Down
46 changes: 46 additions & 0 deletions src/command/StartDocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { inject, injectable } from 'inversify';
import type vscode from 'vscode';
import type { Command } from '.';
import { START_DOCKER_COMMAND } from 'constant';
import Types from 'common/Types';
import ChildProcessGateway from 'gateway/ChildProcessGateway';
import CommandTreeItem from 'job/CommandTreeItem';
import Spawn from 'common/Spawn';
import EnvPath from 'common/EnvPath';
import JobProvider from 'job/JobProvider';

@injectable()
export default class StartDocker implements Command {
@inject(Types.IChildProcessGateway)
childProcessGateway!: ChildProcessGateway;

@inject(EnvPath)
envPath!: EnvPath;

@inject(Spawn)
spawn!: Spawn;

commandName: string;

constructor() {
this.commandName = START_DOCKER_COMMAND;
}

getCallback(context: vscode.ExtensionContext, jobProvider: JobProvider) {
return (commandTreeItem: CommandTreeItem) => {
commandTreeItem.setIsRunning();
jobProvider.refresh(commandTreeItem);

this.childProcessGateway.cp.spawn(
'/bin/sh',
[
'-c',
this.envPath.isMac()
? 'open -a Docker'
: 'systemctl --user start docker-desktop',
],
this.spawn.getOptions()
);
};
}
}
2 changes: 1 addition & 1 deletion src/command/TryProcessAgain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'inversify';
import type { Command } from './index';
import type { Command } from '.';
import type vscode from 'vscode';
import ConfigFile from 'config/ConfigFile';
import FsGateway from 'gateway/FsGateway';
Expand Down
4 changes: 2 additions & 2 deletions src/common/EnvPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export default class EnvPath {
* Must be whole, i.e. the left side must be the beginning of the string or :, and the right side must be the end of the string or :
* Case-insensitive, because Mac is.
*/
get(): string {
get() {
const path = this.processGateway.process.env.PATH || '';

return this.isMac() && !/(?<=^|:)\/usr\/local\/bin(?=$|:)/i.test(path)
? `${path}:/usr/local/bin`
: path;
}

isMac(): boolean {
isMac() {
return this.osGateway.os.type() === 'Darwin';
}
}
3 changes: 3 additions & 0 deletions src/common/Registrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ReRunJob from 'command/ReRunJob';
import RunJob from 'command/RunJob';
import RunWalkthroughJob from 'command/RunWalkthroughJob';
import ShowLogFile from 'command/ShowLogFile';
import StartDocker from 'command/StartDocker';
import TryProcessAgain from '../command/TryProcessAgain';

import {
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class Registrar {
private runWalkthroughJob: RunWalkthroughJob,
private selectRepo: SelectRepo,
private showLogFile: ShowLogFile,
private startDocker: StartDocker,
private tryProcessAgain: TryProcessAgain
) {}

Expand All @@ -80,6 +82,7 @@ export default class Registrar {
this.runWalkthroughJob,
this.selectRepo,
this.showLogFile,
this.startDocker,
this.tryProcessAgain,
].map((command: Command) => {
return this.editorGateway.editor.commands.registerCommand(
Expand Down
3 changes: 3 additions & 0 deletions src/common/RegistrarFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Refresh from '../command/Refresh';
import RefreshLicenseTree from 'command/RefreshLicenseTree';
import SelectRepo from 'command/SelectRepo';
import ShowLogFile from 'command/ShowLogFile';
import StartDocker from 'command/StartDocker';
import TryProcessAgain from '../command/TryProcessAgain';

@injectable()
Expand All @@ -50,6 +51,7 @@ export default class RegistrarFactory {
@inject(RunWalkthroughJob) private runWalkthroughJob: RunWalkthroughJob,
@inject(SelectRepo) private selectRepo: SelectRepo,
@inject(ShowLogFile) private showLogFile: ShowLogFile,
@inject(StartDocker) private startDocker: StartDocker,
@inject(TryProcessAgain) private tryProcessAgain: TryProcessAgain,
@inject(Types.IEditorGateway) private editorGateway: EditorGateway
) {}
Expand Down Expand Up @@ -84,6 +86,7 @@ export default class RegistrarFactory {
this.runWalkthroughJob,
this.selectRepo,
this.showLogFile,
this.startDocker,
this.tryProcessAgain
);
}
Expand Down
1 change: 1 addition & 0 deletions src/common/test/LocalCi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('LocalCi', () => {
'local-ci.runWalkthroughJob',
'localCiJobs.selectRepo',
'local-ci.show.log-file',
'local-ci.docker.start',
'local-ci.process-error.try-again',
];

Expand Down
1 change: 1 addition & 0 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const HOST_TMP_DIRECTORY = '/tmp/local-ci';
export const RUN_JOB_COMMAND = 'local-ci.job.run';
export const CREATE_CONFIG_FILE_COMMAND = 'local-ci.create.config';
export const SELECT_REPO_COMMAND = 'localCiJobs.selectRepo';
export const START_DOCKER_COMMAND = 'local-ci.docker.start';
export const SHOW_LOG_FILE_COMMAND = 'local-ci.show.log-file';
export const LOG_FILE_SCHEME = 'local-ci-log';
export const CONTINUE_PIPELINE_STEP_NAME = 'Continue the pipeline';
Expand Down
8 changes: 6 additions & 2 deletions src/job/Children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
JOB_TREE_VIEW_ID,
PROCESS_TRY_AGAIN_COMMAND,
SELECT_REPO_COMMAND,
START_DOCKER_COMMAND,
} from 'constant';

type Logs = Record<string, string[]>;
Expand Down Expand Up @@ -128,8 +129,11 @@ export default class Children {
switch (errorType) {
case JobError.DockerNotRunning:
return [
this.warningFactory.create('Error: is Docker running?'),
new this.editorGateway.editor.TreeItem(errorMessage ?? ''),
this.warningCommandFactory.create(
'Please Start Docker',
START_DOCKER_COMMAND
),
this.commandFactory.create('Start Docker', START_DOCKER_COMMAND),
this.commandFactory.create(
'Try Again',
`${JOB_TREE_VIEW_ID}.refresh`
Expand Down
14 changes: 2 additions & 12 deletions src/job/ComandFactory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { inject, injectable } from 'inversify';
import EditorGateway from 'gateway/EditorGateway';
import Types from 'common/Types';
import CommandTreeItem from './CommandTreeItem';

@injectable()
export default class CommandFactory {
@inject(Types.IEditorGateway)
editorGateway!: EditorGateway;

create(label: string, command: string) {
const newCommand = new this.editorGateway.editor.TreeItem(label);

newCommand.collapsibleState =
this.editorGateway.editor.TreeItemCollapsibleState.None;
newCommand.tooltip = label;
newCommand.command = {
command,
title: label,
tooltip: label,
};

return newCommand;
return new CommandTreeItem(this.editorGateway, label, command);
}
}
29 changes: 29 additions & 0 deletions src/job/CommandTreeItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import EditorGateway from 'gateway/EditorGateway';
import type vscode from 'vscode';

export default class CommandTreeItem implements vscode.TreeItem {
collapsibleState: vscode.TreeItemCollapsibleState;
command: vscode.Command;
iconPath?: vscode.ThemeIcon;
tooltip: string;

constructor(
private editorGateway: EditorGateway,
public label: string,
commandName: string
) {
this.collapsibleState =
this.editorGateway.editor.TreeItemCollapsibleState.None;
this.tooltip = label;
this.command = {
command: commandName,
title: label,
tooltip: label,
arguments: [this],
};
}

setIsRunning() {
this.iconPath = new this.editorGateway.editor.ThemeIcon('sync~spin');
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载