@wocker/ws 1.0.7 → 1.0.9
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/bin/ws.js +2 -13
- package/lib/AppModule.d.ts +6 -0
- package/lib/AppModule.js +100 -0
- package/lib/controllers/CompletionController.d.ts +6 -0
- package/lib/controllers/CompletionController.js +32 -0
- package/lib/controllers/DebugController.d.ts +7 -0
- package/lib/controllers/DebugController.js +44 -0
- package/lib/controllers/ImageController.d.ts +5 -8
- package/lib/controllers/ImageController.js +27 -12
- package/lib/controllers/PluginController.d.ts +11 -13
- package/lib/controllers/PluginController.js +93 -54
- package/lib/controllers/PresetController.d.ts +10 -15
- package/lib/controllers/PresetController.js +111 -27
- package/lib/controllers/ProjectController.d.ts +27 -70
- package/lib/controllers/ProjectController.js +357 -306
- package/lib/controllers/ProxyController.d.ts +15 -25
- package/lib/controllers/ProxyController.js +157 -102
- package/lib/controllers/index.d.ts +2 -0
- package/lib/controllers/index.js +2 -0
- package/lib/main.d.ts +3 -0
- package/lib/main.js +30 -0
- package/lib/makes/FS.d.ts +15 -5
- package/lib/makes/FS.js +42 -9
- package/lib/makes/Http.d.ts +18 -0
- package/lib/makes/{Plugin.js → Http.js} +45 -34
- package/lib/makes/Logger.d.ts +2 -2
- package/lib/makes/Logger.js +19 -8
- package/lib/makes/Preset.d.ts +5 -6
- package/lib/makes/Preset.js +19 -8
- package/lib/makes/index.d.ts +1 -6
- package/lib/makes/index.js +1 -6
- package/lib/plugins/ElasticSearchPlugin.d.ts +5 -6
- package/lib/plugins/ElasticSearchPlugin.js +19 -8
- package/lib/plugins/LocaltunnelPlugin.d.ts +8 -8
- package/lib/plugins/LocaltunnelPlugin.js +25 -10
- package/lib/plugins/MaildevPlugin.d.ts +5 -6
- package/lib/plugins/MaildevPlugin.js +21 -8
- package/lib/plugins/MongodbPlugin.d.ts +5 -5
- package/lib/plugins/MongodbPlugin.js +26 -11
- package/lib/plugins/NgrokPlugin.d.ts +7 -6
- package/lib/plugins/NgrokPlugin.js +32 -17
- package/lib/plugins/PageKitePlugin.d.ts +10 -8
- package/lib/plugins/PageKitePlugin.js +36 -20
- package/lib/plugins/ProxmoxPlugin.d.ts +8 -5
- package/lib/plugins/ProxmoxPlugin.js +25 -9
- package/lib/plugins/RedisPlugin.d.ts +4 -6
- package/lib/plugins/RedisPlugin.js +19 -8
- package/lib/plugins/index.d.ts +0 -2
- package/lib/plugins/index.js +0 -2
- package/lib/services/AppConfigService.d.ts +7 -17
- package/lib/services/AppConfigService.js +44 -114
- package/lib/services/AppEventsService.d.ts +1 -2
- package/lib/services/AppEventsService.js +11 -2
- package/lib/services/DockerService.d.ts +9 -39
- package/lib/services/DockerService.js +122 -4
- package/lib/services/LogService.d.ts +3 -5
- package/lib/services/LogService.js +19 -4
- package/lib/services/PluginService.d.ts +11 -9
- package/lib/services/PluginService.js +100 -8
- package/lib/services/PresetService.d.ts +4 -5
- package/lib/services/PresetService.js +26 -5
- package/lib/services/ProjectService.d.ts +9 -6
- package/lib/services/ProjectService.js +72 -37
- package/lib/utils/exec.d.ts +4 -1
- package/lib/utils/exec.js +16 -31
- package/lib/utils/followProgress.js +49 -45
- package/lib/utils/index.d.ts +0 -7
- package/lib/utils/index.js +0 -7
- package/lib/utils/spawn.d.ts +1 -1
- package/lib/utils/spawn.js +20 -12
- package/package.json +5 -7
- package/presets/node/config.json +1 -1
- package/presets/php-apache/Dockerfile +1 -1
- package/presets/php-apache/config.json +2 -1
- package/presets/php-fpm/Dockerfile +1 -1
- package/lib/App.d.ts +0 -16
- package/lib/App.js +0 -107
- package/lib/decorators/Inject.d.ts +0 -1
- package/lib/decorators/Inject.js +0 -8
- package/lib/decorators/Injectable.d.ts +0 -4
- package/lib/decorators/Injectable.js +0 -17
- package/lib/decorators/index.d.ts +0 -1
- package/lib/decorators/index.js +0 -17
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -33
- package/lib/makes/Controller.d.ts +0 -5
- package/lib/makes/Controller.js +0 -8
- package/lib/makes/DI.d.ts +0 -7
- package/lib/makes/DI.js +0 -27
- package/lib/makes/Docker.d.ts +0 -58
- package/lib/makes/Docker.js +0 -320
- package/lib/makes/Plugin.d.ts +0 -13
- package/lib/makes/Project.d.ts +0 -45
- package/lib/makes/Project.js +0 -127
- package/lib/makes/Repository.d.ts +0 -11
- package/lib/makes/Repository.js +0 -22
- package/lib/plugins/PostgresPlugin.d.ts +0 -16
- package/lib/plugins/PostgresPlugin.js +0 -121
- package/lib/types/Config.d.ts +0 -12
- package/lib/types/Config.js +0 -2
- package/lib/types/EnvConfig.d.ts +0 -3
- package/lib/types/EnvConfig.js +0 -2
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -18
- package/lib/utils/buildOptions.d.ts +0 -1
- package/lib/utils/buildOptions.js +0 -9
- package/lib/utils/demuxOutput.d.ts +0 -2
- package/lib/utils/demuxOutput.js +0 -19
- package/lib/utils/fetch.d.ts +0 -5
- package/lib/utils/fetch.js +0 -52
- package/lib/utils/get-config.d.ts +0 -2
- package/lib/utils/get-config.js +0 -17
- package/lib/utils/image-build.d.ts +0 -13
- package/lib/utils/image-build.js +0 -46
- package/lib/utils/set-config.d.ts +0 -2
- package/lib/utils/set-config.js +0 -15
- package/lib/utils/tty.d.ts +0 -2
- package/lib/utils/tty.js +0 -6
package/lib/App.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Controller } from "@wocker/core";
|
|
2
|
-
import { Cli } from "@kearisp/cli";
|
|
3
|
-
import { DI } from "./makes";
|
|
4
|
-
import { AppConfigService } from "./services";
|
|
5
|
-
export declare class App {
|
|
6
|
-
protected di: DI;
|
|
7
|
-
protected cli: Cli;
|
|
8
|
-
protected appConfigService: AppConfigService;
|
|
9
|
-
constructor();
|
|
10
|
-
install(): void;
|
|
11
|
-
use(Constructor: {
|
|
12
|
-
new (...params: any[]): Controller;
|
|
13
|
-
}): void;
|
|
14
|
-
setDebug(status: string): Promise<string>;
|
|
15
|
-
run(): Promise<string>;
|
|
16
|
-
}
|
package/lib/App.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.App = void 0;
|
|
27
|
-
const cli_1 = require("@kearisp/cli");
|
|
28
|
-
const Path = __importStar(require("path"));
|
|
29
|
-
const env_1 = require("./env");
|
|
30
|
-
const utils_1 = require("./utils");
|
|
31
|
-
const makes_1 = require("./makes");
|
|
32
|
-
const services_1 = require("./services");
|
|
33
|
-
const controllers_1 = require("./controllers");
|
|
34
|
-
class App {
|
|
35
|
-
constructor() {
|
|
36
|
-
this.di = new makes_1.DI();
|
|
37
|
-
this.appConfigService = new services_1.AppConfigService();
|
|
38
|
-
this.di.registerService(services_1.AppConfigService, this.appConfigService);
|
|
39
|
-
this.di.registerService(services_1.AppEventsService, new services_1.AppEventsService());
|
|
40
|
-
this.di.registerService(services_1.DockerService, new services_1.DockerService(this.di));
|
|
41
|
-
this.di.registerService(services_1.PresetService, new services_1.PresetService(this.di));
|
|
42
|
-
this.di.registerService(services_1.PluginService, new services_1.PluginService(this.di));
|
|
43
|
-
this.di.registerService(services_1.ProjectService, new services_1.ProjectService(this.di));
|
|
44
|
-
this.di.registerService(services_1.LogService, new services_1.LogService(this.di));
|
|
45
|
-
this.di.registerService(cli_1.Cli, this.cli);
|
|
46
|
-
this.cli = new cli_1.Cli(makes_1.Logger);
|
|
47
|
-
makes_1.Preset.install(this.di);
|
|
48
|
-
makes_1.Project.install(this.di);
|
|
49
|
-
makes_1.Logger.install(this.di);
|
|
50
|
-
this.install();
|
|
51
|
-
this.use(controllers_1.ImageController);
|
|
52
|
-
this.use(controllers_1.PluginController);
|
|
53
|
-
this.use(controllers_1.PresetController);
|
|
54
|
-
this.use(controllers_1.ProjectController);
|
|
55
|
-
this.use(controllers_1.ProxyController);
|
|
56
|
-
}
|
|
57
|
-
install() {
|
|
58
|
-
this.cli.command("completion script")
|
|
59
|
-
.help(false)
|
|
60
|
-
.action(() => this.cli.completionScript());
|
|
61
|
-
this.cli.command("log [...items]")
|
|
62
|
-
.action((options, items) => {
|
|
63
|
-
makes_1.Logger.log(...items);
|
|
64
|
-
return "";
|
|
65
|
-
});
|
|
66
|
-
this.cli.command("debug <status>")
|
|
67
|
-
.completion("status", () => ["on", "off"])
|
|
68
|
-
.action(async (options, status) => this.setDebug(status));
|
|
69
|
-
}
|
|
70
|
-
use(Constructor) {
|
|
71
|
-
const controller = new Constructor(this.di);
|
|
72
|
-
controller.install(this.cli);
|
|
73
|
-
}
|
|
74
|
-
async setDebug(status) {
|
|
75
|
-
makes_1.Logger.info(`Set debug ${status}`);
|
|
76
|
-
await (0, utils_1.setConfig)({
|
|
77
|
-
debug: status === "on"
|
|
78
|
-
});
|
|
79
|
-
return "";
|
|
80
|
-
}
|
|
81
|
-
async run() {
|
|
82
|
-
const mapDir = Path.dirname(env_1.MAP_PATH);
|
|
83
|
-
if (!makes_1.FS.existsSync(mapDir)) {
|
|
84
|
-
await makes_1.FS.mkdir(mapDir);
|
|
85
|
-
}
|
|
86
|
-
if (!makes_1.FS.existsSync(env_1.MAP_PATH)) {
|
|
87
|
-
await makes_1.FS.writeJSON(env_1.MAP_PATH, {
|
|
88
|
-
projects: []
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (!makes_1.FS.existsSync(`${env_1.DATA_DIR}/projects`)) {
|
|
92
|
-
await makes_1.FS.mkdir(`${env_1.DATA_DIR}/projects`);
|
|
93
|
-
}
|
|
94
|
-
const { plugins = [] } = await this.appConfigService.getAppConfig();
|
|
95
|
-
for (const plugin of plugins) {
|
|
96
|
-
try {
|
|
97
|
-
const { default: Plugin } = await Promise.resolve(`${plugin}`).then(s => __importStar(require(s)));
|
|
98
|
-
this.use(Plugin);
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
makes_1.Logger.error(err.message);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return this.cli.run(process.argv);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.App = App;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const Inject: () => (target: any) => void;
|
package/lib/decorators/Inject.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Injectable = void 0;
|
|
4
|
-
const Injectable = () => {
|
|
5
|
-
return (Target) => {
|
|
6
|
-
return class extends Target {
|
|
7
|
-
constructor(di) {
|
|
8
|
-
const types = Reflect.getMetadata("design:paramtypes", Target);
|
|
9
|
-
const params = types.map((type) => {
|
|
10
|
-
return (di).resolveService(type);
|
|
11
|
-
});
|
|
12
|
-
super(...params);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
exports.Injectable = Injectable;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Injectable";
|
package/lib/decorators/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Injectable"), exports);
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.app = void 0;
|
|
18
|
-
const App_1 = require("./App");
|
|
19
|
-
const plugins_1 = require("./plugins");
|
|
20
|
-
const app = new App_1.App();
|
|
21
|
-
exports.app = app;
|
|
22
|
-
app.use(plugins_1.ElasticSearchPlugin);
|
|
23
|
-
app.use(plugins_1.LocaltunnelPlugin);
|
|
24
|
-
app.use(plugins_1.MaildevPlugin);
|
|
25
|
-
app.use(plugins_1.MongodbPlugin);
|
|
26
|
-
app.use(plugins_1.NgrokPlugin);
|
|
27
|
-
app.use(plugins_1.PageKitePlugin);
|
|
28
|
-
app.use(plugins_1.PostgresPlugin);
|
|
29
|
-
app.use(plugins_1.ProxmoxPlugin);
|
|
30
|
-
app.use(plugins_1.RedisPlugin);
|
|
31
|
-
__exportStar(require("./decorators"), exports);
|
|
32
|
-
__exportStar(require("./makes"), exports);
|
|
33
|
-
__exportStar(require("./services"), exports);
|
package/lib/makes/Controller.js
DELETED
package/lib/makes/DI.d.ts
DELETED
package/lib/makes/DI.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DI = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
class DI {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.services = new Map();
|
|
8
|
-
}
|
|
9
|
-
resolveService(key) {
|
|
10
|
-
let res = this.services.get(key);
|
|
11
|
-
if (!res) {
|
|
12
|
-
const types = Reflect.getMetadata("design:paramtypes", key);
|
|
13
|
-
if (types && types.length > 0) {
|
|
14
|
-
types.forEach((type) => {
|
|
15
|
-
this.resolveService(type);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
res = new key(this);
|
|
19
|
-
this.services.set(key, res);
|
|
20
|
-
}
|
|
21
|
-
return res;
|
|
22
|
-
}
|
|
23
|
-
registerService(key, service) {
|
|
24
|
-
this.services.set(key, service);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.DI = DI;
|
package/lib/makes/Docker.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import Dockerode from "dockerode";
|
|
4
|
-
type ContainerRunOptions = {
|
|
5
|
-
name: string;
|
|
6
|
-
image: string;
|
|
7
|
-
restart?: "always";
|
|
8
|
-
projectId?: string;
|
|
9
|
-
tty?: boolean;
|
|
10
|
-
links?: string[];
|
|
11
|
-
env?: {
|
|
12
|
-
[key: string]: string;
|
|
13
|
-
};
|
|
14
|
-
networkMode?: string;
|
|
15
|
-
extraHosts?: any;
|
|
16
|
-
volumes?: string[];
|
|
17
|
-
ports?: string[];
|
|
18
|
-
cmd?: string[];
|
|
19
|
-
};
|
|
20
|
-
type ImageBuildOptions = {
|
|
21
|
-
tag: string;
|
|
22
|
-
buildArgs?: {
|
|
23
|
-
[key: string]: string;
|
|
24
|
-
};
|
|
25
|
-
labels?: {
|
|
26
|
-
[key: string]: string;
|
|
27
|
-
};
|
|
28
|
-
context: string;
|
|
29
|
-
src: string;
|
|
30
|
-
};
|
|
31
|
-
declare class Docker {
|
|
32
|
-
static docker: Dockerode;
|
|
33
|
-
static exec(name: string, args: string[], tty?: boolean): Promise<import("stream").Duplex>;
|
|
34
|
-
static getImage(name: string): Promise<Dockerode.Image>;
|
|
35
|
-
static getContainer(name: any): Promise<Dockerode.Container>;
|
|
36
|
-
static removeContainer(name: string): Promise<void>;
|
|
37
|
-
static getContainerList(options?: {
|
|
38
|
-
name?: string;
|
|
39
|
-
projectId?: string;
|
|
40
|
-
}): Promise<Dockerode.ContainerInfo[]>;
|
|
41
|
-
static attach(name: string): Promise<void>;
|
|
42
|
-
static attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
|
|
43
|
-
static imageExists(tag: string): Promise<boolean>;
|
|
44
|
-
static imageLs(options?: {
|
|
45
|
-
tag?: string;
|
|
46
|
-
reference?: string;
|
|
47
|
-
labels?: {
|
|
48
|
-
[key: string]: string;
|
|
49
|
-
};
|
|
50
|
-
}): Promise<Dockerode.ImageInfo[]>;
|
|
51
|
-
static imageBuild(options: ImageBuildOptions): Promise<void>;
|
|
52
|
-
static imageBuild2(options: ImageBuildOptions): Promise<NodeJS.ReadableStream>;
|
|
53
|
-
static imageRm(name: string): Promise<void>;
|
|
54
|
-
static pullImage(tag: string): Promise<void>;
|
|
55
|
-
static createContainer(options: ContainerRunOptions): Promise<Dockerode.Container>;
|
|
56
|
-
static containerRun(options: ContainerRunOptions, attach?: boolean): Promise<Dockerode.Container>;
|
|
57
|
-
}
|
|
58
|
-
export { Docker };
|
package/lib/makes/Docker.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Docker = void 0;
|
|
7
|
-
const dockerode_1 = __importDefault(require("dockerode"));
|
|
8
|
-
const image_build_1 = require("../utils/image-build");
|
|
9
|
-
const followProgress_1 = require("../utils/followProgress");
|
|
10
|
-
const FS_1 = require("./FS");
|
|
11
|
-
const Logger_1 = require("./Logger");
|
|
12
|
-
const docker = new dockerode_1.default({
|
|
13
|
-
socketPath: "/var/run/docker.sock"
|
|
14
|
-
});
|
|
15
|
-
class Docker {
|
|
16
|
-
static async exec(name, args, tty = true) {
|
|
17
|
-
const container = docker.getContainer(name);
|
|
18
|
-
const exec = await container.exec({
|
|
19
|
-
AttachStdin: true,
|
|
20
|
-
AttachStdout: true,
|
|
21
|
-
AttachStderr: tty,
|
|
22
|
-
Tty: tty,
|
|
23
|
-
Cmd: args
|
|
24
|
-
});
|
|
25
|
-
const stream = await exec.start({
|
|
26
|
-
hijack: true,
|
|
27
|
-
stdin: tty,
|
|
28
|
-
Tty: tty
|
|
29
|
-
});
|
|
30
|
-
if (tty) {
|
|
31
|
-
stream.setEncoding("utf-8");
|
|
32
|
-
process.stdin.resume();
|
|
33
|
-
if (process.stdin.setRawMode) {
|
|
34
|
-
process.stdin.setRawMode(true);
|
|
35
|
-
}
|
|
36
|
-
process.stdin.setEncoding("utf-8");
|
|
37
|
-
process.stdin.pipe(stream);
|
|
38
|
-
stream.pipe(process.stdout);
|
|
39
|
-
stream.on("error", (err) => {
|
|
40
|
-
Logger_1.Logger.error(err.message);
|
|
41
|
-
});
|
|
42
|
-
stream.on("end", async () => {
|
|
43
|
-
process.stdin.setRawMode(false);
|
|
44
|
-
});
|
|
45
|
-
stream.on("end", async () => {
|
|
46
|
-
process.exit();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return stream;
|
|
50
|
-
}
|
|
51
|
-
static async getImage(name) {
|
|
52
|
-
return docker.getImage(name);
|
|
53
|
-
}
|
|
54
|
-
static async getContainer(name) {
|
|
55
|
-
const containers = await docker.listContainers({
|
|
56
|
-
all: true,
|
|
57
|
-
filters: {
|
|
58
|
-
name: [name]
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const container = containers.find((container) => {
|
|
62
|
-
return container.Names.indexOf("/" + name) >= 0;
|
|
63
|
-
});
|
|
64
|
-
if (container) {
|
|
65
|
-
return docker.getContainer(container.Id);
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
static async removeContainer(name) {
|
|
70
|
-
const container = await Docker.getContainer(name);
|
|
71
|
-
if (!container) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const { State: { Status } } = await container.inspect();
|
|
75
|
-
if (Status === "running") {
|
|
76
|
-
try {
|
|
77
|
-
await container.stop();
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
Logger_1.Logger.error("Docker.removeContainer: ", err.message);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
await container.remove();
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
Logger_1.Logger.error("Docker.removeContainer: ", err.message);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
static async getContainerList(options) {
|
|
91
|
-
const { name, projectId } = options || {};
|
|
92
|
-
const filters = {};
|
|
93
|
-
if (name) {
|
|
94
|
-
filters.name = [`/${name}`];
|
|
95
|
-
}
|
|
96
|
-
if (projectId) {
|
|
97
|
-
if (!filters.label) {
|
|
98
|
-
filters.label = [];
|
|
99
|
-
}
|
|
100
|
-
filters.label.push(`projectId=${projectId}`);
|
|
101
|
-
}
|
|
102
|
-
return docker.listContainers({
|
|
103
|
-
all: true,
|
|
104
|
-
filters: JSON.stringify(filters)
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
static async attach(name) {
|
|
108
|
-
const container = await Docker.getContainer(name);
|
|
109
|
-
const stream = await container.attach({
|
|
110
|
-
logs: true,
|
|
111
|
-
stream: true,
|
|
112
|
-
hijack: true,
|
|
113
|
-
stdin: true,
|
|
114
|
-
stdout: true,
|
|
115
|
-
stderr: true
|
|
116
|
-
});
|
|
117
|
-
process.stdin.resume();
|
|
118
|
-
process.stdin.setEncoding("utf8");
|
|
119
|
-
process.stdin.setRawMode(true);
|
|
120
|
-
process.stdin.pipe(stream);
|
|
121
|
-
process.stdin.on("data", (data) => {
|
|
122
|
-
if (data.toString() === "\u0003") {
|
|
123
|
-
process.stdin.setRawMode(false);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
stream.setEncoding("utf8");
|
|
127
|
-
stream.pipe(process.stdout);
|
|
128
|
-
const [width, height] = process.stdout.getWindowSize();
|
|
129
|
-
await container.resize({
|
|
130
|
-
w: width,
|
|
131
|
-
h: height
|
|
132
|
-
});
|
|
133
|
-
stream.on("end", async () => {
|
|
134
|
-
process.exit();
|
|
135
|
-
});
|
|
136
|
-
process.stdout.on("resize", () => {
|
|
137
|
-
const [width, height] = process.stdout.getWindowSize();
|
|
138
|
-
container.resize({
|
|
139
|
-
w: width,
|
|
140
|
-
h: height
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
static async attachStream(stream) {
|
|
145
|
-
process.stdin.resume();
|
|
146
|
-
process.stdin.setEncoding("utf8");
|
|
147
|
-
process.stdin.pipe(stream);
|
|
148
|
-
if (process.stdin.isTTY) {
|
|
149
|
-
process.stdin.setRawMode(true);
|
|
150
|
-
}
|
|
151
|
-
stream.setEncoding("utf8");
|
|
152
|
-
stream.pipe(process.stdout);
|
|
153
|
-
const end = () => {
|
|
154
|
-
process.stdin.pause();
|
|
155
|
-
process.stdin.unpipe(stream);
|
|
156
|
-
if (process.stdin.isTTY) {
|
|
157
|
-
process.stdin.setRawMode(false);
|
|
158
|
-
}
|
|
159
|
-
stream.unpipe(process.stdout);
|
|
160
|
-
};
|
|
161
|
-
await new Promise((resolve, reject) => {
|
|
162
|
-
stream.on("end", end);
|
|
163
|
-
stream.on("error", end);
|
|
164
|
-
stream.on("end", resolve);
|
|
165
|
-
stream.on("error", reject);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
static async imageExists(tag) {
|
|
169
|
-
const image = docker.getImage(tag);
|
|
170
|
-
try {
|
|
171
|
-
await image.inspect();
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
catch (ignore) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
static async imageLs(options) {
|
|
179
|
-
const { tag, reference, labels } = options || {};
|
|
180
|
-
const filters = {};
|
|
181
|
-
if (reference) {
|
|
182
|
-
filters.reference = [
|
|
183
|
-
...filters.reference || [],
|
|
184
|
-
reference
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
if (tag) {
|
|
188
|
-
filters.reference = [
|
|
189
|
-
...filters.reference || [],
|
|
190
|
-
tag
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
if (labels) {
|
|
194
|
-
filters.label = [];
|
|
195
|
-
for (const i in labels) {
|
|
196
|
-
filters.label.push(`${i}=${labels[i]}`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return docker.listImages({
|
|
200
|
-
filters: JSON.stringify(filters)
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
static async imageBuild(options) {
|
|
204
|
-
await (0, image_build_1.imageBuild)(options);
|
|
205
|
-
}
|
|
206
|
-
static async imageBuild2(options) {
|
|
207
|
-
const { tag, labels = {}, buildArgs = {}, context, src } = options;
|
|
208
|
-
const files = await FS_1.FS.readdirFiles(context, {
|
|
209
|
-
recursive: true
|
|
210
|
-
});
|
|
211
|
-
const stream = await docker.buildImage({
|
|
212
|
-
context,
|
|
213
|
-
src: files
|
|
214
|
-
}, {
|
|
215
|
-
t: tag,
|
|
216
|
-
labels,
|
|
217
|
-
dockerfile: src,
|
|
218
|
-
buildargs: buildArgs
|
|
219
|
-
});
|
|
220
|
-
return stream;
|
|
221
|
-
}
|
|
222
|
-
static async imageRm(name) {
|
|
223
|
-
const image = await docker.getImage(name);
|
|
224
|
-
if (!image) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
await image.remove();
|
|
228
|
-
}
|
|
229
|
-
static async pullImage(tag) {
|
|
230
|
-
const isExists = await this.imageExists(tag);
|
|
231
|
-
if (isExists) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const stream = await docker.pull(tag, {});
|
|
235
|
-
await (0, followProgress_1.followProgress)(stream);
|
|
236
|
-
}
|
|
237
|
-
static async createContainer(options) {
|
|
238
|
-
const { name, tty, image, projectId, restart, extraHosts, networkMode, links = [], env = {}, volumes = [], ports = [], cmd = [] } = options;
|
|
239
|
-
const network = docker.getNetwork("workspace");
|
|
240
|
-
try {
|
|
241
|
-
await network.inspect();
|
|
242
|
-
}
|
|
243
|
-
catch (err) {
|
|
244
|
-
if (err.statusCode === 404) {
|
|
245
|
-
await docker.createNetwork({
|
|
246
|
-
Name: "workspace"
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
await this.pullImage(image);
|
|
251
|
-
return await docker.createContainer({
|
|
252
|
-
name,
|
|
253
|
-
Image: image,
|
|
254
|
-
Hostname: name,
|
|
255
|
-
Labels: {
|
|
256
|
-
...projectId ? { projectId } : {}
|
|
257
|
-
},
|
|
258
|
-
AttachStdin: true,
|
|
259
|
-
AttachStdout: true,
|
|
260
|
-
AttachStderr: true,
|
|
261
|
-
OpenStdin: true,
|
|
262
|
-
StdinOnce: false,
|
|
263
|
-
Tty: tty,
|
|
264
|
-
Cmd: cmd,
|
|
265
|
-
Env: Object.keys(env).map((key) => {
|
|
266
|
-
const value = env[key];
|
|
267
|
-
return `${key}=${value}`;
|
|
268
|
-
}),
|
|
269
|
-
ExposedPorts: ports.reduce((res, value) => {
|
|
270
|
-
const [, , containerPort] = /(\d+):(\d+)/.exec(value) || [];
|
|
271
|
-
if (containerPort) {
|
|
272
|
-
res[`${containerPort}/tcp`] = {};
|
|
273
|
-
}
|
|
274
|
-
return res;
|
|
275
|
-
}, {}),
|
|
276
|
-
HostConfig: {
|
|
277
|
-
NetworkMode: networkMode,
|
|
278
|
-
ExtraHosts: extraHosts,
|
|
279
|
-
...restart ? {
|
|
280
|
-
RestartPolicy: {
|
|
281
|
-
Name: restart
|
|
282
|
-
}
|
|
283
|
-
} : {},
|
|
284
|
-
Binds: volumes,
|
|
285
|
-
PortBindings: ports.reduce((res, value) => {
|
|
286
|
-
const [, hostPort, containerPort] = /(\d+):(\d+)/.exec(value) || [];
|
|
287
|
-
if (hostPort && containerPort) {
|
|
288
|
-
res[`${containerPort}/tcp`] = [
|
|
289
|
-
{ HostPort: hostPort }
|
|
290
|
-
];
|
|
291
|
-
}
|
|
292
|
-
return res;
|
|
293
|
-
}, {})
|
|
294
|
-
},
|
|
295
|
-
NetworkingConfig: {
|
|
296
|
-
EndpointsConfig: networkMode === "host" ? {} : {
|
|
297
|
-
workspace: {
|
|
298
|
-
Links: links
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
static async containerRun(options, attach = false) {
|
|
305
|
-
const container = await Docker.createContainer(options);
|
|
306
|
-
if (attach) {
|
|
307
|
-
const stdout = await container.attach({
|
|
308
|
-
stream: true,
|
|
309
|
-
stdin: true,
|
|
310
|
-
stdout: true,
|
|
311
|
-
stderr: true
|
|
312
|
-
});
|
|
313
|
-
stdout.pipe(process.stdout);
|
|
314
|
-
}
|
|
315
|
-
await container.start();
|
|
316
|
-
return container;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
exports.Docker = Docker;
|
|
320
|
-
Docker.docker = docker;
|
package/lib/makes/Plugin.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Controller } from "../makes/Controller";
|
|
3
|
-
declare class Plugin extends Controller {
|
|
4
|
-
protected certsDir: string;
|
|
5
|
-
protected dataDir: string;
|
|
6
|
-
protected pluginDir: string;
|
|
7
|
-
constructor(name: string);
|
|
8
|
-
install(cli: Cli): void;
|
|
9
|
-
certsPath(...paths: string[]): string;
|
|
10
|
-
dataPath(...paths: string[]): string;
|
|
11
|
-
pluginPath(...paths: string[]): string;
|
|
12
|
-
}
|
|
13
|
-
export { Plugin };
|