@wocker/ws 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/controllers/DebugController.d.ts +3 -2
- package/lib/controllers/DebugController.js +4 -2
- package/lib/controllers/ImageController.js +1 -1
- package/lib/controllers/PresetController.d.ts +1 -0
- package/lib/controllers/PresetController.js +20 -16
- package/lib/controllers/ProjectController.d.ts +1 -0
- package/lib/controllers/ProjectController.js +49 -10
- package/lib/main.js +1 -0
- package/lib/makes/FS.d.ts +1 -13
- package/lib/makes/FS.js +0 -51
- package/lib/plugins/ElasticSearchPlugin.d.ts +0 -2
- package/lib/plugins/ElasticSearchPlugin.js +0 -11
- package/lib/plugins/LocaltunnelPlugin.d.ts +0 -2
- package/lib/plugins/LocaltunnelPlugin.js +0 -58
- package/lib/plugins/MaildevPlugin.d.ts +0 -2
- package/lib/plugins/MaildevPlugin.js +0 -6
- package/lib/plugins/MongodbPlugin.d.ts +0 -2
- package/lib/plugins/MongodbPlugin.js +0 -57
- package/lib/plugins/PageKitePlugin.d.ts +0 -2
- package/lib/plugins/PageKitePlugin.js +0 -32
- package/lib/plugins/index.d.ts +0 -2
- package/lib/plugins/index.js +0 -2
- package/lib/services/DockerService.d.ts +2 -1
- package/lib/services/DockerService.js +31 -11
- package/lib/services/PresetService.js +4 -8
- package/lib/services/ProjectService.js +2 -1
- package/package.json +8 -9
- package/lib/plugins/NgrokPlugin.d.ts +0 -37
- package/lib/plugins/NgrokPlugin.js +0 -254
- package/lib/plugins/RedisPlugin.d.ts +0 -16
- package/lib/plugins/RedisPlugin.js +0 -91
- package/plugins/ngrok/Dockerfile +0 -2
|
@@ -23,38 +23,6 @@ let PageKitePlugin = class PageKitePlugin {
|
|
|
23
23
|
pluginPath(...parts) {
|
|
24
24
|
return this.appConfigService.pluginsPath("pagekite", ...parts);
|
|
25
25
|
}
|
|
26
|
-
install(cli) {
|
|
27
|
-
this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
|
|
28
|
-
this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
|
|
29
|
-
cli.command("pagekite:init")
|
|
30
|
-
.action((options) => this.init(options));
|
|
31
|
-
cli.command("pagekite:start")
|
|
32
|
-
.option("name", {
|
|
33
|
-
type: "string",
|
|
34
|
-
alias: "n",
|
|
35
|
-
description: "Project name"
|
|
36
|
-
})
|
|
37
|
-
.option("restart", {
|
|
38
|
-
type: "boolean",
|
|
39
|
-
alias: "r",
|
|
40
|
-
description: "Restart"
|
|
41
|
-
})
|
|
42
|
-
.action((options) => this.start(options));
|
|
43
|
-
cli.command("pagekite:stop")
|
|
44
|
-
.option("name", {
|
|
45
|
-
type: "string",
|
|
46
|
-
alias: "n",
|
|
47
|
-
description: "Project name"
|
|
48
|
-
})
|
|
49
|
-
.action((options) => this.stop(options));
|
|
50
|
-
cli.command("pagekite:build")
|
|
51
|
-
.option("rebuild", {
|
|
52
|
-
type: "boolean",
|
|
53
|
-
alias: "r",
|
|
54
|
-
description: "Rebuild"
|
|
55
|
-
})
|
|
56
|
-
.action((options) => this.build(options));
|
|
57
|
-
}
|
|
58
26
|
async onProjectStart(project) {
|
|
59
27
|
if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
|
|
60
28
|
return;
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ export * from "./ElasticSearchPlugin";
|
|
|
2
2
|
export * from "./LocaltunnelPlugin";
|
|
3
3
|
export * from "./MaildevPlugin";
|
|
4
4
|
export * from "./MongodbPlugin";
|
|
5
|
-
export * from "./NgrokPlugin";
|
|
6
5
|
export * from "./PageKitePlugin";
|
|
7
6
|
export * from "./ProxmoxPlugin";
|
|
8
|
-
export * from "./RedisPlugin";
|
package/lib/plugins/index.js
CHANGED
|
@@ -18,7 +18,5 @@ __exportStar(require("./ElasticSearchPlugin"), exports);
|
|
|
18
18
|
__exportStar(require("./LocaltunnelPlugin"), exports);
|
|
19
19
|
__exportStar(require("./MaildevPlugin"), exports);
|
|
20
20
|
__exportStar(require("./MongodbPlugin"), exports);
|
|
21
|
-
__exportStar(require("./NgrokPlugin"), exports);
|
|
22
21
|
__exportStar(require("./PageKitePlugin"), exports);
|
|
23
22
|
__exportStar(require("./ProxmoxPlugin"), exports);
|
|
24
|
-
__exportStar(require("./RedisPlugin"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import Docker, { Container } from "dockerode";
|
|
4
3
|
import { DockerServiceParams as Params } from "@wocker/core";
|
|
4
|
+
import Docker, { Container } from "dockerode";
|
|
5
5
|
import { LogService } from "./LogService";
|
|
6
6
|
export declare class DockerService {
|
|
7
7
|
protected readonly logService: LogService;
|
|
@@ -16,6 +16,7 @@ export declare class DockerService {
|
|
|
16
16
|
imageLs(options?: Params.ImageList): Promise<Docker.ImageInfo[]>;
|
|
17
17
|
pullImage(tag: string): Promise<void>;
|
|
18
18
|
attach(name: string): Promise<void>;
|
|
19
|
+
logs(name: string): Promise<void>;
|
|
19
20
|
attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
|
|
20
21
|
exec(name: string, args?: string[], tty?: boolean): Promise<import("stream").Duplex>;
|
|
21
22
|
}
|
|
@@ -13,9 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DockerService = void 0;
|
|
16
|
-
const dockerode_1 = __importDefault(require("dockerode"));
|
|
17
16
|
const core_1 = require("@wocker/core");
|
|
18
|
-
const utils_1 = require("
|
|
17
|
+
const utils_1 = require("@wocker/utils");
|
|
18
|
+
const dockerode_1 = __importDefault(require("dockerode"));
|
|
19
|
+
const utils_2 = require("../utils");
|
|
19
20
|
const makes_1 = require("../makes");
|
|
20
21
|
const LogService_1 = require("./LogService");
|
|
21
22
|
let DockerService = class DockerService {
|
|
@@ -159,7 +160,7 @@ let DockerService = class DockerService {
|
|
|
159
160
|
}, {}),
|
|
160
161
|
dockerfile: src
|
|
161
162
|
});
|
|
162
|
-
await (0,
|
|
163
|
+
await (0, utils_2.followProgress)(stream);
|
|
163
164
|
}
|
|
164
165
|
async imageExists(tag) {
|
|
165
166
|
const image = this.docker.getImage(tag);
|
|
@@ -209,17 +210,21 @@ let DockerService = class DockerService {
|
|
|
209
210
|
return;
|
|
210
211
|
}
|
|
211
212
|
const stream = await this.docker.pull(tag);
|
|
212
|
-
await (0,
|
|
213
|
+
await (0, utils_2.followProgress)(stream);
|
|
213
214
|
}
|
|
214
215
|
async attach(name) {
|
|
215
216
|
const container = await this.getContainer(name);
|
|
217
|
+
if (!container) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
216
220
|
const stream = await container.attach({
|
|
217
221
|
logs: true,
|
|
218
222
|
stream: true,
|
|
219
223
|
hijack: true,
|
|
220
224
|
stdin: true,
|
|
221
225
|
stdout: true,
|
|
222
|
-
stderr: true
|
|
226
|
+
stderr: true,
|
|
227
|
+
detachKeys: "ctrl-c"
|
|
223
228
|
});
|
|
224
229
|
process.stdin.resume();
|
|
225
230
|
process.stdin.setEncoding("utf8");
|
|
@@ -230,12 +235,8 @@ let DockerService = class DockerService {
|
|
|
230
235
|
process.stdin.setRawMode(false);
|
|
231
236
|
}
|
|
232
237
|
});
|
|
233
|
-
stream.
|
|
234
|
-
|
|
235
|
-
const [width, height] = process.stdout.getWindowSize();
|
|
236
|
-
await container.resize({
|
|
237
|
-
w: width,
|
|
238
|
-
h: height
|
|
238
|
+
stream.on("data", (data) => {
|
|
239
|
+
process.stdout.write((0, utils_1.demuxOutput)(data));
|
|
239
240
|
});
|
|
240
241
|
stream.on("end", async () => {
|
|
241
242
|
process.exit();
|
|
@@ -247,6 +248,25 @@ let DockerService = class DockerService {
|
|
|
247
248
|
h: height
|
|
248
249
|
});
|
|
249
250
|
});
|
|
251
|
+
const [width, height] = process.stdout.getWindowSize();
|
|
252
|
+
await container.resize({
|
|
253
|
+
w: width,
|
|
254
|
+
h: height
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
async logs(name) {
|
|
258
|
+
const container = await this.getContainer(name);
|
|
259
|
+
if (!container) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const stream = await container.logs({
|
|
263
|
+
stdout: true,
|
|
264
|
+
stderr: true,
|
|
265
|
+
follow: true
|
|
266
|
+
});
|
|
267
|
+
stream.on("data", (data) => {
|
|
268
|
+
process.stdout.write((0, utils_1.demuxOutput)(data));
|
|
269
|
+
});
|
|
250
270
|
}
|
|
251
271
|
async attachStream(stream) {
|
|
252
272
|
process.stdin.resume();
|
|
@@ -44,14 +44,14 @@ let PresetService = class PresetService {
|
|
|
44
44
|
}
|
|
45
45
|
async get(name) {
|
|
46
46
|
const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
|
|
47
|
+
const _this = this;
|
|
47
48
|
return new class extends core_1.Preset {
|
|
48
|
-
constructor(
|
|
49
|
+
constructor(data) {
|
|
49
50
|
super(data);
|
|
50
|
-
this.presetService = presetService;
|
|
51
51
|
}
|
|
52
52
|
async save() {
|
|
53
53
|
}
|
|
54
|
-
}(
|
|
54
|
+
}({
|
|
55
55
|
name,
|
|
56
56
|
...config
|
|
57
57
|
});
|
|
@@ -64,11 +64,7 @@ let PresetService = class PresetService {
|
|
|
64
64
|
if (name && name !== dir) {
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
const preset = new core_1.Preset({
|
|
69
|
-
name: dir,
|
|
70
|
-
...config
|
|
71
|
-
});
|
|
67
|
+
const preset = await this.get(dir);
|
|
72
68
|
presets.push(preset);
|
|
73
69
|
}
|
|
74
70
|
return presets;
|
|
@@ -100,6 +100,7 @@ let ProjectService = class ProjectService {
|
|
|
100
100
|
let container = await this.dockerService.getContainer(project.containerName);
|
|
101
101
|
if (container && restart) {
|
|
102
102
|
container = null;
|
|
103
|
+
await this.appEventsService.emit("project:stop", project);
|
|
103
104
|
await this.dockerService.removeContainer(project.containerName);
|
|
104
105
|
}
|
|
105
106
|
if (!container) {
|
|
@@ -122,8 +123,8 @@ let ProjectService = class ProjectService {
|
|
|
122
123
|
const { State: { Status } } = await container.inspect();
|
|
123
124
|
if (Status === "created" || Status === "exited") {
|
|
124
125
|
await container.start();
|
|
125
|
-
await this.appEventsService.emit("project:start", project);
|
|
126
126
|
}
|
|
127
|
+
await this.appEventsService.emit("project:start", project);
|
|
127
128
|
}
|
|
128
129
|
async stop() {
|
|
129
130
|
const project = await this.get();
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Docker workspace for web projects",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"ws": "./bin/ws.js"
|
|
11
|
+
},
|
|
7
12
|
"homepage": "https://kearisp.github.io/wocker",
|
|
8
13
|
"repository": {
|
|
9
14
|
"type": "git",
|
|
@@ -12,11 +17,6 @@
|
|
|
12
17
|
"bugs": {
|
|
13
18
|
"url": "https://github.com/kearisp/wocker-ws/issues"
|
|
14
19
|
},
|
|
15
|
-
"main": "lib/index.js",
|
|
16
|
-
"types": "lib/index.d.ts",
|
|
17
|
-
"bin": {
|
|
18
|
-
"ws": "./bin/ws.js"
|
|
19
|
-
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"prepare": "npm run build",
|
|
22
22
|
"start": "npm run watch",
|
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@wocker/
|
|
30
|
-
"@wocker/utils": "^1.0.3",
|
|
28
|
+
"@wocker/core": "^1.0.11",
|
|
29
|
+
"@wocker/utils": "^1.0.4",
|
|
31
30
|
"async-mutex": "^0.4.0",
|
|
32
31
|
"axios": "^1.6.7",
|
|
33
32
|
"chalk": "^2.4.2",
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { DockerService, Project } from "@wocker/core";
|
|
2
|
-
import { Cli } from "@kearisp/cli";
|
|
3
|
-
import { AppEventsService, ProjectService } from "../services";
|
|
4
|
-
type StartOptions = {
|
|
5
|
-
name?: string;
|
|
6
|
-
detach?: string;
|
|
7
|
-
};
|
|
8
|
-
type StopOptions = {
|
|
9
|
-
name?: string;
|
|
10
|
-
};
|
|
11
|
-
type LogsOptions = {
|
|
12
|
-
name?: string;
|
|
13
|
-
};
|
|
14
|
-
type AttachOptions = {
|
|
15
|
-
name?: string;
|
|
16
|
-
};
|
|
17
|
-
type ForwardingOptions = {
|
|
18
|
-
name?: string;
|
|
19
|
-
};
|
|
20
|
-
export declare class NgrokPlugin {
|
|
21
|
-
protected readonly appEventsService: AppEventsService;
|
|
22
|
-
protected readonly projectService: ProjectService;
|
|
23
|
-
protected readonly dockerService: DockerService;
|
|
24
|
-
constructor(appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
|
|
25
|
-
install(cli: Cli): void;
|
|
26
|
-
init(options: any): Promise<void>;
|
|
27
|
-
getForwarding(project: Project): Promise<string | undefined>;
|
|
28
|
-
onProjectStart(project: Project): Promise<void>;
|
|
29
|
-
onProjectStop(project: Project): Promise<void>;
|
|
30
|
-
start(options: StartOptions): Promise<void>;
|
|
31
|
-
stop(options: StopOptions): Promise<void>;
|
|
32
|
-
restart(options: StartOptions): Promise<void>;
|
|
33
|
-
logs(options: LogsOptions): Promise<void>;
|
|
34
|
-
attach(options: AttachOptions): Promise<void>;
|
|
35
|
-
forwarding(options: ForwardingOptions): Promise<string>;
|
|
36
|
-
}
|
|
37
|
-
export {};
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.NgrokPlugin = void 0;
|
|
13
|
-
const core_1 = require("@wocker/core");
|
|
14
|
-
const utils_1 = require("@wocker/utils");
|
|
15
|
-
const makes_1 = require("../makes");
|
|
16
|
-
const services_1 = require("../services");
|
|
17
|
-
let NgrokPlugin = class NgrokPlugin {
|
|
18
|
-
constructor(appEventsService, projectService, dockerService) {
|
|
19
|
-
this.appEventsService = appEventsService;
|
|
20
|
-
this.projectService = projectService;
|
|
21
|
-
this.dockerService = dockerService;
|
|
22
|
-
}
|
|
23
|
-
install(cli) {
|
|
24
|
-
this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
|
|
25
|
-
this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
|
|
26
|
-
cli.command("ngrok:init")
|
|
27
|
-
.option("name", {
|
|
28
|
-
alias: "n",
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Project name"
|
|
31
|
-
})
|
|
32
|
-
.action((options) => this.init(options));
|
|
33
|
-
cli.command("ngrok:start")
|
|
34
|
-
.option("name", {
|
|
35
|
-
type: "string",
|
|
36
|
-
alias: "n",
|
|
37
|
-
description: "Project name"
|
|
38
|
-
})
|
|
39
|
-
.option("detach", {
|
|
40
|
-
type: "boolean",
|
|
41
|
-
alias: "d",
|
|
42
|
-
description: "Detach"
|
|
43
|
-
})
|
|
44
|
-
.action((options) => this.start(options));
|
|
45
|
-
cli.command("ngrok:stop")
|
|
46
|
-
.option("name", {
|
|
47
|
-
type: "string",
|
|
48
|
-
alias: "n",
|
|
49
|
-
description: "Project name"
|
|
50
|
-
})
|
|
51
|
-
.action((options) => this.stop(options));
|
|
52
|
-
cli.command("ngrok:restart")
|
|
53
|
-
.option("name", {
|
|
54
|
-
type: "string",
|
|
55
|
-
alias: "n",
|
|
56
|
-
description: "Project name"
|
|
57
|
-
})
|
|
58
|
-
.option("detach", {
|
|
59
|
-
type: "boolean",
|
|
60
|
-
alias: "d",
|
|
61
|
-
description: "Detach"
|
|
62
|
-
})
|
|
63
|
-
.action((options) => this.restart(options));
|
|
64
|
-
cli.command("ngrok:logs")
|
|
65
|
-
.option("name", {
|
|
66
|
-
type: "string",
|
|
67
|
-
alias: "n",
|
|
68
|
-
description: "Project name"
|
|
69
|
-
})
|
|
70
|
-
.action((options) => this.logs(options));
|
|
71
|
-
cli.command("ngrok:attach")
|
|
72
|
-
.option("name", {
|
|
73
|
-
type: "string",
|
|
74
|
-
alias: "n",
|
|
75
|
-
description: "Project name"
|
|
76
|
-
})
|
|
77
|
-
.action((options) => this.attach(options));
|
|
78
|
-
cli.command("ngrok:forwarding")
|
|
79
|
-
.option("name", {
|
|
80
|
-
type: "string",
|
|
81
|
-
alias: "n",
|
|
82
|
-
description: "Project name"
|
|
83
|
-
})
|
|
84
|
-
.action((options) => this.forwarding(options));
|
|
85
|
-
}
|
|
86
|
-
async init(options) {
|
|
87
|
-
const { name } = options;
|
|
88
|
-
if (name) {
|
|
89
|
-
await this.projectService.cdProject(name);
|
|
90
|
-
}
|
|
91
|
-
const project = await this.projectService.get();
|
|
92
|
-
const enable = await (0, utils_1.promptConfirm)({
|
|
93
|
-
message: "Enable ngrok?",
|
|
94
|
-
default: true
|
|
95
|
-
});
|
|
96
|
-
if (enable) {
|
|
97
|
-
const token = await (0, utils_1.promptText)({
|
|
98
|
-
message: "Token",
|
|
99
|
-
default: project.getEnv("NGROK_AUTHTOKEN")
|
|
100
|
-
});
|
|
101
|
-
project.setEnv("NGROK_AUTHTOKEN", token);
|
|
102
|
-
project.setEnv("NGROK_ENABLE", "true");
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
project.setEnv("NGROK_ENABLE", "false");
|
|
106
|
-
}
|
|
107
|
-
await project.save();
|
|
108
|
-
}
|
|
109
|
-
async getForwarding(project) {
|
|
110
|
-
const container = await this.dockerService.getContainer(`ngrok-${project.name}`);
|
|
111
|
-
if (!container) {
|
|
112
|
-
throw new Error(`Ngrok for "${project.name}" not started`);
|
|
113
|
-
}
|
|
114
|
-
const { NetworkSettings: { Networks: { workspace } } } = await container.inspect();
|
|
115
|
-
const stream = await this.dockerService.exec("proxy.workspace", [
|
|
116
|
-
"curl", `http://${workspace.IPAddress}:4040/api/tunnels/command_line`
|
|
117
|
-
], false);
|
|
118
|
-
const res = await new Promise((resolve, reject) => {
|
|
119
|
-
let res = "";
|
|
120
|
-
stream.on("data", (data) => {
|
|
121
|
-
res += (0, utils_1.demuxOutput)(data).toString();
|
|
122
|
-
});
|
|
123
|
-
stream.on("end", () => resolve(res));
|
|
124
|
-
stream.on("error", reject);
|
|
125
|
-
});
|
|
126
|
-
const tunnel = JSON.parse(res);
|
|
127
|
-
return tunnel.public_url;
|
|
128
|
-
}
|
|
129
|
-
async onProjectStart(project) {
|
|
130
|
-
if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const container1 = await this.dockerService.getContainer(`ngrok-${project.name}`);
|
|
134
|
-
if (container1) {
|
|
135
|
-
const { State: { Running } } = await container1.inspect();
|
|
136
|
-
if (Running) {
|
|
137
|
-
console.log("Ngrok is already running");
|
|
138
|
-
const forwarding = await this.getForwarding(project);
|
|
139
|
-
console.log(`Forwarding: ${forwarding}`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
await this.dockerService.removeContainer(`ngrok-${project.name}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
console.log("Ngrok starting...");
|
|
147
|
-
makes_1.Logger.info(`Ngrok start: ${project.name}`);
|
|
148
|
-
await this.dockerService.pullImage("ngrok/ngrok:latest");
|
|
149
|
-
const container = await this.dockerService.createContainer({
|
|
150
|
-
name: `ngrok-${project.name}`,
|
|
151
|
-
image: "ngrok/ngrok:latest",
|
|
152
|
-
tty: true,
|
|
153
|
-
restart: "always",
|
|
154
|
-
env: {
|
|
155
|
-
NGROK_AUTHTOKEN: project.getEnv("NGROK_AUTHTOKEN")
|
|
156
|
-
},
|
|
157
|
-
cmd: ["http", `${project.name}.workspace:80`]
|
|
158
|
-
});
|
|
159
|
-
const stream = await container.attach({
|
|
160
|
-
logs: true,
|
|
161
|
-
stream: true,
|
|
162
|
-
hijack: true,
|
|
163
|
-
stdin: true,
|
|
164
|
-
stdout: true,
|
|
165
|
-
stderr: true
|
|
166
|
-
});
|
|
167
|
-
stream.setEncoding("utf8");
|
|
168
|
-
await container.start();
|
|
169
|
-
await container.resize({
|
|
170
|
-
w: 90,
|
|
171
|
-
h: 40
|
|
172
|
-
});
|
|
173
|
-
await new Promise((resolve, reject) => {
|
|
174
|
-
stream.on("data", (data) => {
|
|
175
|
-
const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
|
|
176
|
-
if (regLink.test(data.toString())) {
|
|
177
|
-
const [link] = regLink.exec(data.toString());
|
|
178
|
-
if (link.includes(".ngrok")) {
|
|
179
|
-
makes_1.Logger.info(`${project.name} forwarding: ${link}`);
|
|
180
|
-
console.log(`Forwarding: ${link}`);
|
|
181
|
-
stream.end();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
stream.on("end", resolve);
|
|
186
|
-
stream.on("error", reject);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async onProjectStop(project) {
|
|
190
|
-
if (!project || project.getEnv("NGROK_ENABLE", "false") !== "true") {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
console.log("Ngrok stopping...");
|
|
194
|
-
await this.dockerService.removeContainer(`ngrok-${project.name}`);
|
|
195
|
-
}
|
|
196
|
-
async start(options) {
|
|
197
|
-
const { name, detach } = options;
|
|
198
|
-
if (name) {
|
|
199
|
-
await this.projectService.cdProject(name);
|
|
200
|
-
}
|
|
201
|
-
const project = await this.projectService.get();
|
|
202
|
-
await this.onProjectStart(project);
|
|
203
|
-
if (!detach) {
|
|
204
|
-
await this.dockerService.attach(`ngrok-${project.name}`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async stop(options) {
|
|
208
|
-
const { name } = options;
|
|
209
|
-
if (name) {
|
|
210
|
-
await this.projectService.cdProject(name);
|
|
211
|
-
}
|
|
212
|
-
const project = await this.projectService.get();
|
|
213
|
-
await this.onProjectStop(project);
|
|
214
|
-
}
|
|
215
|
-
async restart(options) {
|
|
216
|
-
const { name } = options;
|
|
217
|
-
await this.stop({ name });
|
|
218
|
-
await this.start(options);
|
|
219
|
-
}
|
|
220
|
-
async logs(options) {
|
|
221
|
-
const { name } = options;
|
|
222
|
-
if (name) {
|
|
223
|
-
await this.projectService.cdProject(name);
|
|
224
|
-
}
|
|
225
|
-
const project = await this.projectService.get();
|
|
226
|
-
const container = await this.dockerService.getContainer(`ngrok-${project.name}`);
|
|
227
|
-
if (!container) {
|
|
228
|
-
throw new Error("Ngrok not started");
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async attach(options) {
|
|
232
|
-
const { name } = options;
|
|
233
|
-
if (name) {
|
|
234
|
-
await this.projectService.cdProject(name);
|
|
235
|
-
}
|
|
236
|
-
const project = await this.projectService.get();
|
|
237
|
-
await this.dockerService.attach(`ngrok-${project.name}`);
|
|
238
|
-
}
|
|
239
|
-
async forwarding(options) {
|
|
240
|
-
const { name } = options;
|
|
241
|
-
if (name) {
|
|
242
|
-
await this.projectService.cdProject(name);
|
|
243
|
-
}
|
|
244
|
-
const project = await this.projectService.get();
|
|
245
|
-
return this.getForwarding(project);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
exports.NgrokPlugin = NgrokPlugin;
|
|
249
|
-
exports.NgrokPlugin = NgrokPlugin = __decorate([
|
|
250
|
-
(0, core_1.Controller)(),
|
|
251
|
-
__metadata("design:paramtypes", [services_1.AppEventsService,
|
|
252
|
-
services_1.ProjectService,
|
|
253
|
-
core_1.DockerService])
|
|
254
|
-
], NgrokPlugin);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FSManager } from "@wocker/core";
|
|
2
|
-
import { Cli } from "@kearisp/cli";
|
|
3
|
-
import { AppConfigService, DockerService } from "../services";
|
|
4
|
-
export declare class RedisPlugin {
|
|
5
|
-
protected readonly appConfigService: AppConfigService;
|
|
6
|
-
protected readonly dockerService: DockerService;
|
|
7
|
-
protected container: string;
|
|
8
|
-
protected commander: string;
|
|
9
|
-
protected fs: FSManager;
|
|
10
|
-
constructor(appConfigService: AppConfigService, dockerService: DockerService);
|
|
11
|
-
install(cli: Cli): void;
|
|
12
|
-
up(): Promise<void>;
|
|
13
|
-
protected startCommander(): Promise<void>;
|
|
14
|
-
down(): Promise<void>;
|
|
15
|
-
protected stopCommander(): Promise<void>;
|
|
16
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RedisPlugin = void 0;
|
|
13
|
-
const core_1 = require("@wocker/core");
|
|
14
|
-
const services_1 = require("../services");
|
|
15
|
-
let RedisPlugin = class RedisPlugin {
|
|
16
|
-
constructor(appConfigService, dockerService) {
|
|
17
|
-
this.appConfigService = appConfigService;
|
|
18
|
-
this.dockerService = dockerService;
|
|
19
|
-
this.container = "redis.workspace";
|
|
20
|
-
this.commander = "redis-commander.workspace";
|
|
21
|
-
this.fs = new core_1.FSManager(this.appConfigService.pluginsPath("redis"), this.appConfigService.dataPath("plugins/redis"));
|
|
22
|
-
}
|
|
23
|
-
install(cli) {
|
|
24
|
-
cli.command("redis:start")
|
|
25
|
-
.action(() => this.up());
|
|
26
|
-
cli.command("redis:stop")
|
|
27
|
-
.action(() => this.down());
|
|
28
|
-
}
|
|
29
|
-
async up() {
|
|
30
|
-
console.log("Redis up...");
|
|
31
|
-
await this.dockerService.pullImage("redis");
|
|
32
|
-
let container = await this.dockerService.getContainer(this.container);
|
|
33
|
-
if (!container) {
|
|
34
|
-
await this.fs.mkdir("", {
|
|
35
|
-
recursive: true
|
|
36
|
-
});
|
|
37
|
-
container = await this.dockerService.createContainer({
|
|
38
|
-
name: this.container,
|
|
39
|
-
image: "redis",
|
|
40
|
-
restart: "always",
|
|
41
|
-
env: {
|
|
42
|
-
VIRTUAL_HOST: this.container
|
|
43
|
-
},
|
|
44
|
-
volumes: [
|
|
45
|
-
`${this.fs.path()}:/data`
|
|
46
|
-
],
|
|
47
|
-
ports: [
|
|
48
|
-
"6379:6379"
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
await container.start();
|
|
53
|
-
await this.startCommander();
|
|
54
|
-
}
|
|
55
|
-
async startCommander() {
|
|
56
|
-
console.info("RedisCommander starting...");
|
|
57
|
-
let container = await this.dockerService.getContainer(this.commander);
|
|
58
|
-
if (!container) {
|
|
59
|
-
await this.dockerService.pullImage("rediscommander/redis-commander:latest");
|
|
60
|
-
container = await this.dockerService.createContainer({
|
|
61
|
-
name: this.commander,
|
|
62
|
-
image: "rediscommander/redis-commander:latest",
|
|
63
|
-
restart: "always",
|
|
64
|
-
env: {
|
|
65
|
-
VIRTUAL_HOST: this.commander,
|
|
66
|
-
VIRTUAL_PORT: "8081",
|
|
67
|
-
REDIS_HOSTS: this.container
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const { State: { Status } } = await container.inspect();
|
|
72
|
-
if (Status === "created" || Status === "exited") {
|
|
73
|
-
await container.start();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async down() {
|
|
77
|
-
console.log("Redis down...");
|
|
78
|
-
await this.dockerService.removeContainer(this.container);
|
|
79
|
-
await this.stopCommander();
|
|
80
|
-
}
|
|
81
|
-
async stopCommander() {
|
|
82
|
-
console.info("RedisCommander stopping...");
|
|
83
|
-
await this.dockerService.removeContainer(this.commander);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
exports.RedisPlugin = RedisPlugin;
|
|
87
|
-
exports.RedisPlugin = RedisPlugin = __decorate([
|
|
88
|
-
(0, core_1.Controller)(),
|
|
89
|
-
__metadata("design:paramtypes", [services_1.AppConfigService,
|
|
90
|
-
services_1.DockerService])
|
|
91
|
-
], RedisPlugin);
|
package/plugins/ngrok/Dockerfile
DELETED