@wocker/ws 1.0.9 → 1.0.10
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.js +9 -13
- package/lib/controllers/ProjectController.js +22 -8
- package/lib/main.js +1 -0
- package/lib/makes/FS.d.ts +1 -13
- package/lib/makes/FS.js +0 -51
- 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/ProjectService.js +3 -2
- package/package.json +3 -3
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AppConfigService } from "../services";
|
|
1
|
+
import { AppConfigService, LogService } from "../services";
|
|
2
2
|
export declare class DebugController {
|
|
3
3
|
protected readonly appConfigService: AppConfigService;
|
|
4
|
-
|
|
4
|
+
protected readonly logService: LogService;
|
|
5
|
+
constructor(appConfigService: AppConfigService, logService: LogService);
|
|
5
6
|
debug(status: string): Promise<void>;
|
|
6
7
|
debugCompletion(): Promise<string[]>;
|
|
7
8
|
}
|
|
@@ -13,8 +13,9 @@ exports.DebugController = void 0;
|
|
|
13
13
|
const core_1 = require("@wocker/core");
|
|
14
14
|
const services_1 = require("../services");
|
|
15
15
|
let DebugController = class DebugController {
|
|
16
|
-
constructor(appConfigService) {
|
|
16
|
+
constructor(appConfigService, logService) {
|
|
17
17
|
this.appConfigService = appConfigService;
|
|
18
|
+
this.logService = logService;
|
|
18
19
|
}
|
|
19
20
|
async debug(status) {
|
|
20
21
|
const config = await this.appConfigService.getConfig();
|
|
@@ -40,5 +41,6 @@ __decorate([
|
|
|
40
41
|
], DebugController.prototype, "debugCompletion", null);
|
|
41
42
|
exports.DebugController = DebugController = __decorate([
|
|
42
43
|
(0, core_1.Controller)(),
|
|
43
|
-
__metadata("design:paramtypes", [services_1.AppConfigService
|
|
44
|
+
__metadata("design:paramtypes", [services_1.AppConfigService,
|
|
45
|
+
services_1.LogService])
|
|
44
46
|
], DebugController);
|
|
@@ -42,7 +42,6 @@ const utils_2 = require("@wocker/utils");
|
|
|
42
42
|
const Path = __importStar(require("path"));
|
|
43
43
|
const env_1 = require("../env");
|
|
44
44
|
const utils_3 = require("../utils");
|
|
45
|
-
const makes_1 = require("../makes");
|
|
46
45
|
const services_1 = require("../services");
|
|
47
46
|
let PresetController = class PresetController {
|
|
48
47
|
constructor(appConfigService, appEventsService, projectService, presetService, dockerService) {
|
|
@@ -166,37 +165,34 @@ let PresetController = class PresetController {
|
|
|
166
165
|
if (!confirm) {
|
|
167
166
|
return;
|
|
168
167
|
}
|
|
169
|
-
const
|
|
170
|
-
const destination = new makes_1.FS(this.appConfigService.getPWD());
|
|
171
|
-
const fs = new core_1.FSManager(this.appConfigService.presetPath(preset.name), this.appConfigService.getPWD());
|
|
168
|
+
const copier = new core_1.FSManager(this.appConfigService.presetPath(preset.name), this.appConfigService.getPWD());
|
|
172
169
|
if (preset.dockerfile) {
|
|
173
|
-
if (!destination.exists(preset.dockerfile)) {
|
|
174
|
-
await
|
|
170
|
+
if (!copier.destination.exists(preset.dockerfile)) {
|
|
171
|
+
await copier.copy(preset.dockerfile);
|
|
175
172
|
}
|
|
176
173
|
project.type = "dockerfile";
|
|
177
174
|
project.dockerfile = preset.dockerfile;
|
|
178
175
|
}
|
|
179
|
-
const files = await source.readdirFiles("", {
|
|
176
|
+
const files = await copier.source.readdirFiles("", {
|
|
180
177
|
recursive: true
|
|
181
178
|
});
|
|
182
179
|
for (const path of files) {
|
|
183
|
-
const stat = source.stat(path);
|
|
180
|
+
const stat = copier.source.stat(path), dir = Path.dirname(path);
|
|
184
181
|
if (stat.isFile() && path === "config.json") {
|
|
185
182
|
continue;
|
|
186
183
|
}
|
|
187
184
|
if (stat.isFile() && path === preset.dockerfile) {
|
|
188
185
|
continue;
|
|
189
186
|
}
|
|
190
|
-
if (destination.exists(path)) {
|
|
187
|
+
if (copier.destination.exists(path)) {
|
|
191
188
|
continue;
|
|
192
189
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
destination.mkdir(dir, {
|
|
190
|
+
if (!copier.destination.exists(dir)) {
|
|
191
|
+
copier.destination.mkdir(dir, {
|
|
196
192
|
recursive: true
|
|
197
193
|
});
|
|
198
194
|
}
|
|
199
|
-
await
|
|
195
|
+
await copier.copy(path);
|
|
200
196
|
}
|
|
201
197
|
delete project.preset;
|
|
202
198
|
delete project.imageName;
|
|
@@ -144,7 +144,7 @@ let ProjectController = class ProjectController {
|
|
|
144
144
|
const { State: { Status = "stopped" } = {} } = await container.inspect();
|
|
145
145
|
table.push([project.name, project.type, Status]);
|
|
146
146
|
}
|
|
147
|
-
return table.toString()
|
|
147
|
+
return table.toString();
|
|
148
148
|
}
|
|
149
149
|
async start(name, detach, rebuild, restart) {
|
|
150
150
|
if (name) {
|
|
@@ -203,8 +203,8 @@ let ProjectController = class ProjectController {
|
|
|
203
203
|
if (name) {
|
|
204
204
|
await this.projectService.cdProject(name);
|
|
205
205
|
}
|
|
206
|
-
const
|
|
207
|
-
await this.dockerService.attach(containerName);
|
|
206
|
+
const project = await this.projectService.get();
|
|
207
|
+
await this.dockerService.attach(project.containerName);
|
|
208
208
|
}
|
|
209
209
|
async configList(name, global) {
|
|
210
210
|
if (name) {
|
|
@@ -225,7 +225,7 @@ let ProjectController = class ProjectController {
|
|
|
225
225
|
for (const i in env) {
|
|
226
226
|
table.push([i, env[i]]);
|
|
227
227
|
}
|
|
228
|
-
return table.toString()
|
|
228
|
+
return table.toString();
|
|
229
229
|
}
|
|
230
230
|
async configGet(name, global, keys) {
|
|
231
231
|
if (name) {
|
|
@@ -244,7 +244,7 @@ let ProjectController = class ProjectController {
|
|
|
244
244
|
}
|
|
245
245
|
table.push([key, value]);
|
|
246
246
|
}
|
|
247
|
-
return table.toString()
|
|
247
|
+
return table.toString();
|
|
248
248
|
}
|
|
249
249
|
async configSet(name, global, variables) {
|
|
250
250
|
if (!global && name) {
|
|
@@ -262,6 +262,13 @@ let ProjectController = class ProjectController {
|
|
|
262
262
|
config.setEnv(key.trim(), value.trim());
|
|
263
263
|
}
|
|
264
264
|
await config.save();
|
|
265
|
+
if (!global) {
|
|
266
|
+
const project = await this.projectService.get();
|
|
267
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
268
|
+
if (container) {
|
|
269
|
+
await this.projectService.start(true);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
265
272
|
}
|
|
266
273
|
async configUnset(name, global, configs) {
|
|
267
274
|
const env = configs.reduce((env, config) => {
|
|
@@ -280,6 +287,13 @@ let ProjectController = class ProjectController {
|
|
|
280
287
|
project.unsetEnv(i);
|
|
281
288
|
}
|
|
282
289
|
await project.save();
|
|
290
|
+
if (!global) {
|
|
291
|
+
const project = await this.projectService.get();
|
|
292
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
293
|
+
if (container) {
|
|
294
|
+
await this.projectService.start(true);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
283
297
|
}
|
|
284
298
|
async buildArgsList(name) {
|
|
285
299
|
if (name) {
|
|
@@ -293,7 +307,7 @@ let ProjectController = class ProjectController {
|
|
|
293
307
|
for (const i in buildArgs) {
|
|
294
308
|
table.push([i, typeof buildArgs[i] === "string" ? buildArgs[i] : JSON.stringify(buildArgs[i])]);
|
|
295
309
|
}
|
|
296
|
-
return table.toString()
|
|
310
|
+
return table.toString();
|
|
297
311
|
}
|
|
298
312
|
async buildArgsGet(name, args) {
|
|
299
313
|
if (name) {
|
|
@@ -310,7 +324,7 @@ let ProjectController = class ProjectController {
|
|
|
310
324
|
table.push([key, value]);
|
|
311
325
|
}
|
|
312
326
|
}
|
|
313
|
-
return table.toString()
|
|
327
|
+
return table.toString();
|
|
314
328
|
}
|
|
315
329
|
async buildArgsSet(name, args) {
|
|
316
330
|
if (name) {
|
|
@@ -362,7 +376,7 @@ let ProjectController = class ProjectController {
|
|
|
362
376
|
for (const volume of volumes) {
|
|
363
377
|
table.push([volume]);
|
|
364
378
|
}
|
|
365
|
-
return table.toString()
|
|
379
|
+
return table.toString();
|
|
366
380
|
}
|
|
367
381
|
async volumeMount(name, volumes) {
|
|
368
382
|
if (name) {
|
package/lib/main.js
CHANGED
package/lib/makes/FS.d.ts
CHANGED
|
@@ -2,28 +2,16 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { FS as CoreFS } from "@wocker/core";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
-
import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions,
|
|
5
|
+
import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions, MakeDirectoryOptions } from "fs";
|
|
6
6
|
import { PassThrough } from "readable-stream";
|
|
7
|
-
type ReaddirOptions = ObjectEncodingOptions & {
|
|
8
|
-
recursive?: boolean;
|
|
9
|
-
};
|
|
10
7
|
type ReaddirFilesOptions = {
|
|
11
8
|
recursive?: boolean;
|
|
12
9
|
};
|
|
13
10
|
export declare class FS extends CoreFS {
|
|
14
|
-
protected source: string;
|
|
15
|
-
constructor(source: string);
|
|
16
|
-
path(...parts: string[]): string;
|
|
17
|
-
exists(...parts: string[]): boolean;
|
|
18
|
-
stat(...parts: string[]): fs.Stats;
|
|
19
|
-
mkdir(path: string, options?: MakeDirectoryOptions): void;
|
|
20
|
-
readdir(...parts: string[]): Promise<string[]>;
|
|
21
|
-
readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
|
|
22
11
|
static access(path: PathLike): Promise<any>;
|
|
23
12
|
static existsSync(path: PathLike): boolean;
|
|
24
13
|
static mkdir(dirPath: string, options?: MakeDirectoryOptions): Promise<void>;
|
|
25
14
|
static mkdirSync(path: string, options?: MakeDirectoryOptions): string;
|
|
26
|
-
static readdir(path: PathLike): Promise<string[]>;
|
|
27
15
|
static readdirFiles(path: string, options?: ReaddirFilesOptions): Promise<string[]>;
|
|
28
16
|
static appendFile(path: PathOrFileDescriptor, data: any, options?: WriteFileOptions): Promise<unknown>;
|
|
29
17
|
static appendFileSync(path: PathOrFileDescriptor, data: any, options?: WriteFileOptions): void;
|
package/lib/makes/FS.js
CHANGED
|
@@ -29,45 +29,6 @@ const fs = __importStar(require("fs"));
|
|
|
29
29
|
const Path = __importStar(require("path"));
|
|
30
30
|
const readable_stream_1 = require("readable-stream");
|
|
31
31
|
class FS extends core_1.FS {
|
|
32
|
-
constructor(source) {
|
|
33
|
-
super();
|
|
34
|
-
this.source = source;
|
|
35
|
-
}
|
|
36
|
-
path(...parts) {
|
|
37
|
-
return Path.join(this.source, ...parts);
|
|
38
|
-
}
|
|
39
|
-
exists(...parts) {
|
|
40
|
-
const fullPath = this.path(...parts);
|
|
41
|
-
return FS.existsSync(fullPath);
|
|
42
|
-
}
|
|
43
|
-
stat(...parts) {
|
|
44
|
-
const fullPath = this.path(...parts);
|
|
45
|
-
return fs.statSync(fullPath);
|
|
46
|
-
}
|
|
47
|
-
mkdir(path, options) {
|
|
48
|
-
const fullPath = this.path(path);
|
|
49
|
-
fs.mkdirSync(fullPath, options);
|
|
50
|
-
}
|
|
51
|
-
async readdir(...parts) {
|
|
52
|
-
const fullPath = this.path(...parts);
|
|
53
|
-
return FS.readdir(fullPath);
|
|
54
|
-
}
|
|
55
|
-
async readdirFiles(path, options) {
|
|
56
|
-
const fullPath = this.path(path);
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
fs.readdir(fullPath, options, (err, files) => {
|
|
59
|
-
if (err) {
|
|
60
|
-
reject(err);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
files = files.filter((path) => {
|
|
64
|
-
const stat = this.stat(path);
|
|
65
|
-
return stat.isFile();
|
|
66
|
-
});
|
|
67
|
-
resolve(files);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
32
|
static async access(path) {
|
|
72
33
|
return new Promise((resolve, reject) => {
|
|
73
34
|
fs.access(path, (err) => {
|
|
@@ -98,18 +59,6 @@ class FS extends core_1.FS {
|
|
|
98
59
|
static mkdirSync(path, options) {
|
|
99
60
|
return fs.mkdirSync(path, options);
|
|
100
61
|
}
|
|
101
|
-
static async readdir(path) {
|
|
102
|
-
return new Promise((resolve, reject) => {
|
|
103
|
-
fs.readdir(path, (err, files) => {
|
|
104
|
-
if (!err) {
|
|
105
|
-
resolve(files);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
reject(err);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
62
|
static async readdirFiles(path, options) {
|
|
114
63
|
const { recursive = false } = options || {};
|
|
115
64
|
if (recursive) {
|
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();
|
|
@@ -96,10 +96,10 @@ let ProjectService = class ProjectService {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
await this.appEventsService.emit("project:beforeStart", project);
|
|
100
99
|
let container = await this.dockerService.getContainer(project.containerName);
|
|
101
100
|
if (container && restart) {
|
|
102
101
|
container = null;
|
|
102
|
+
await this.appEventsService.emit("project:stop", project);
|
|
103
103
|
await this.dockerService.removeContainer(project.containerName);
|
|
104
104
|
}
|
|
105
105
|
if (!container) {
|
|
@@ -120,10 +120,11 @@ let ProjectService = class ProjectService {
|
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
const { State: { Status } } = await container.inspect();
|
|
123
|
+
await this.appEventsService.emit("project:beforeStart", project);
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Docker workspace for web projects",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@kearisp/cli": "^1.0.7",
|
|
29
|
-
"@wocker/core": "^1.0.
|
|
30
|
-
"@wocker/utils": "^1.0.
|
|
29
|
+
"@wocker/core": "^1.0.10",
|
|
30
|
+
"@wocker/utils": "^1.0.4",
|
|
31
31
|
"async-mutex": "^0.4.0",
|
|
32
32
|
"axios": "^1.6.7",
|
|
33
33
|
"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