@wocker/ws 1.0.1 → 1.0.3
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/README.md +11 -137
- package/bin/ws.js +7 -3
- package/lib/App.d.ts +10 -7
- package/lib/App.js +99 -44
- package/lib/controllers/ImageController.d.ts +4 -2
- package/lib/controllers/ImageController.js +27 -25
- package/lib/controllers/PluginController.d.ts +14 -0
- package/lib/controllers/PluginController.js +84 -0
- package/lib/controllers/PresetController.d.ts +21 -0
- package/lib/controllers/PresetController.js +169 -0
- package/lib/controllers/ProjectController.d.ts +11 -3
- package/lib/controllers/ProjectController.js +653 -536
- package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
- package/lib/controllers/ProxyController.js +273 -0
- package/lib/controllers/index.d.ts +3 -0
- package/lib/controllers/index.js +19 -25
- package/lib/env.js +33 -22
- package/lib/index.d.ts +2 -0
- package/lib/index.js +29 -28
- package/lib/makes/Controller.js +4 -8
- package/lib/makes/DI.d.ts +7 -0
- package/lib/makes/DI.js +27 -0
- package/lib/makes/Docker.js +299 -397
- package/lib/makes/FS.d.ts +1 -1
- package/lib/makes/FS.js +328 -301
- package/lib/makes/LineConvertStream.js +37 -40
- package/lib/makes/Logger.d.ts +5 -3
- package/lib/makes/Logger.js +18 -34
- package/lib/makes/Model.js +8 -12
- package/lib/makes/MySQL.js +6 -27
- package/lib/makes/Plugin.d.ts +1 -1
- package/lib/makes/Plugin.js +55 -37
- package/lib/makes/Preset.d.ts +46 -0
- package/lib/makes/Preset.js +33 -0
- package/lib/{models → makes}/Project.d.ts +23 -16
- package/lib/makes/Project.js +127 -0
- package/lib/makes/Repository.js +18 -21
- package/lib/makes/index.d.ts +3 -0
- package/lib/makes/index.js +23 -69
- package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
- package/lib/plugins/ElasticSearchPlugin.js +72 -0
- package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
- package/lib/plugins/LocaltunnelPlugin.js +256 -255
- package/lib/plugins/MaildevPlugin.d.ts +4 -2
- package/lib/plugins/MaildevPlugin.js +45 -41
- package/lib/plugins/MongodbPlugin.d.ts +6 -4
- package/lib/plugins/MongodbPlugin.js +303 -254
- package/lib/plugins/NgrokPlugin.d.ts +3 -4
- package/lib/plugins/NgrokPlugin.js +221 -230
- package/lib/plugins/PageKitePlugin.d.ts +3 -4
- package/lib/plugins/PageKitePlugin.js +150 -147
- package/lib/plugins/PostgresPlugin.d.ts +1 -1
- package/lib/plugins/PostgresPlugin.js +115 -88
- package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
- package/lib/plugins/ProxmoxPlugin.js +50 -38
- package/lib/plugins/RedisPlugin.d.ts +10 -2
- package/lib/plugins/RedisPlugin.js +77 -39
- package/lib/plugins/index.d.ts +2 -6
- package/lib/plugins/index.js +25 -158
- package/lib/services/AppConfigService.d.ts +13 -3
- package/lib/services/AppConfigService.js +161 -71
- package/lib/services/AppEventsService.d.ts +5 -8
- package/lib/services/AppEventsService.js +26 -25
- package/lib/services/DockerService.d.ts +51 -0
- package/lib/services/DockerService.js +200 -0
- package/lib/services/LogService.d.ts +12 -0
- package/lib/services/LogService.js +38 -0
- package/lib/services/PluginService.d.ts +11 -0
- package/lib/services/PluginService.js +15 -0
- package/lib/services/PresetService.d.ts +14 -0
- package/lib/services/PresetService.js +64 -0
- package/lib/services/ProjectService.d.ts +12 -4
- package/lib/services/ProjectService.js +141 -78
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.js +21 -36
- package/lib/types/Config.d.ts +4 -3
- package/lib/types/Config.js +1 -4
- package/lib/types/EnvConfig.js +1 -4
- package/lib/types/index.js +16 -25
- package/lib/utils/buildOptions.js +5 -8
- package/lib/utils/demuxOutput.js +16 -22
- package/lib/utils/escapeRegExp.js +4 -7
- package/lib/utils/exec.d.ts +1 -1
- package/lib/utils/exec.js +38 -40
- package/lib/utils/fetch.js +45 -30
- package/lib/utils/followProgress.js +66 -77
- package/lib/utils/format-size-units.js +16 -16
- package/lib/utils/get-config.d.ts +1 -1
- package/lib/utils/get-config.js +13 -16
- package/lib/utils/get-cursor-position.js +22 -29
- package/lib/utils/image-build.js +35 -23
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +32 -235
- package/lib/utils/injectVariables.js +10 -13
- package/lib/utils/parse-table.js +20 -23
- package/lib/utils/set-config.d.ts +1 -1
- package/lib/utils/set-config.js +12 -15
- package/lib/utils/spawn.js +17 -20
- package/lib/utils/tty.js +2 -6
- package/lib/utils/volumeFormat.js +5 -12
- package/lib/utils/volumeParse.js +10 -13
- package/package.json +21 -47
- package/presets/bun/Dockerfile +11 -0
- package/presets/bun/config.json +3 -0
- package/presets/node/Dockerfile +4 -2
- package/presets/node/config.json +9 -7
- package/presets/php-apache/Dockerfile +40 -38
- package/presets/php-apache/config.json +10 -15
- package/presets/php-fpm/Dockerfile +21 -0
- package/presets/php-fpm/config.json +25 -0
- package/lib/models/Preset.d.ts +0 -19
- package/lib/models/Preset.js +0 -60
- package/lib/models/Project.js +0 -151
- package/lib/models/index.d.ts +0 -2
- package/lib/models/index.js +0 -27
- package/lib/plugins/MariadbPlugin.d.ts +0 -25
- package/lib/plugins/MariadbPlugin.js +0 -297
- package/lib/plugins/PresetPlugin.d.ts +0 -19
- package/lib/plugins/PresetPlugin.js +0 -164
- package/lib/plugins/ProjectPlugin.d.ts +0 -12
- package/lib/plugins/ProjectPlugin.js +0 -54
- package/lib/plugins/ProxyPlugin.js +0 -257
- package/lib/plugins/ServeoPlugin.d.ts +0 -36
- package/lib/plugins/ServeoPlugin.js +0 -260
- package/lib/plugins/TestPlugin.d.ts +0 -10
- package/lib/plugins/TestPlugin.js +0 -75
- package/lib/utils/promptConfirm.d.ts +0 -6
- package/lib/utils/promptConfirm.js +0 -21
- package/lib/utils/promptGroup.d.ts +0 -16
- package/lib/utils/promptGroup.js +0 -39
- package/lib/utils/promptSelect.d.ts +0 -12
- package/lib/utils/promptSelect.js +0 -47
- package/lib/utils/promptText.d.ts +0 -13
- package/lib/utils/promptText.js +0 -53
- package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
- package/plugins/serveo/Dockerfile +0 -17
|
@@ -1,271 +1,320 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
5
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 });
|
|
6
26
|
exports.MongodbPlugin = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
install(cli) {
|
|
22
|
-
super.install(cli);
|
|
23
|
-
cli.command("mongodb:start").action(() => {
|
|
24
|
-
return this.start();
|
|
25
|
-
});
|
|
26
|
-
cli.command("mongodb:stop").action(() => {
|
|
27
|
-
return this.stop();
|
|
28
|
-
});
|
|
29
|
-
cli.command("mongodb:restart").action(() => {
|
|
30
|
-
return this.restart();
|
|
31
|
-
});
|
|
32
|
-
cli.command("mongodb:backup [database]").completion("database", () => {
|
|
33
|
-
return this.getDatabases();
|
|
34
|
-
}).action((options, database) => {
|
|
35
|
-
return this.backup(database);
|
|
36
|
-
});
|
|
37
|
-
cli.command("mongodb:restore [database] [filename]").completion("database", () => {
|
|
38
|
-
const dumpPath = this.dataPath("dump");
|
|
39
|
-
return _makes.FS.readdir(dumpPath);
|
|
40
|
-
}).completion("filename", (options, database) => {
|
|
41
|
-
if (!database) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const dirPath = this.dataPath("dump", database);
|
|
45
|
-
if (!_makes.FS.existsSync(dirPath)) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
return _makes.FS.readdir(dirPath);
|
|
49
|
-
}).action((options, database, filename) => {
|
|
50
|
-
return this.restore(database, filename);
|
|
51
|
-
});
|
|
52
|
-
cli.command("mongodb:delete-backup [database] [filename]").option("yes", {
|
|
53
|
-
type: "boolean",
|
|
54
|
-
alias: "y"
|
|
55
|
-
}).completion("database", () => {
|
|
56
|
-
return this.getDatabasesDumps();
|
|
57
|
-
}).completion("filename", (options, database) => {
|
|
58
|
-
if (!database) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
const dumpPath = this.dataPath("dump", database);
|
|
62
|
-
if (!_makes.FS.existsSync(dumpPath)) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
return _makes.FS.readdirFiles(dumpPath);
|
|
66
|
-
}).action((options, database, filename) => {
|
|
67
|
-
return this.deleteBackup(database, filename, options.yes);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async getDatabases() {
|
|
71
|
-
const stream = await _makes.Docker.exec(this.container, ["mongosh", "--username", "root", "--password", "toor", "--quiet", "--eval", "db.getMongo().getDBNames().forEach(function(i){print(i)})"], false);
|
|
72
|
-
let res = "";
|
|
73
|
-
stream.on("data", data => {
|
|
74
|
-
res += (0, _utils.demuxOutput)(data).toString();
|
|
75
|
-
});
|
|
76
|
-
await new Promise((resolve, reject) => {
|
|
77
|
-
stream.on("end", resolve);
|
|
78
|
-
stream.on("error", reject);
|
|
79
|
-
});
|
|
80
|
-
return res.split(/\r?\n/).filter(database => {
|
|
81
|
-
return !!database;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async getDatabasesDumps() {
|
|
85
|
-
const dumpDir = this.dataPath("dump");
|
|
86
|
-
return _makes.FS.readdir(dumpDir);
|
|
87
|
-
}
|
|
88
|
-
async start() {
|
|
89
|
-
console.log("Mongidb starting...");
|
|
90
|
-
await _makes.Docker.pullImage("mongo:latest");
|
|
91
|
-
const container = await _makes.Docker.createContainer({
|
|
92
|
-
name: this.container,
|
|
93
|
-
restart: "always",
|
|
94
|
-
image: "mongo:latest",
|
|
95
|
-
volumes: [`${this.dataPath()}:/data/db`],
|
|
96
|
-
ports: ["27017:27017"],
|
|
97
|
-
env: {
|
|
98
|
-
MONGO_INITDB_ROOT_USERNAME: "root",
|
|
99
|
-
MONGO_INITDB_ROOT_PASSWORD: "toor",
|
|
100
|
-
MONGO_ROOT_USER: "root",
|
|
101
|
-
MONGO_ROOT_PASSWORD: "toor"
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
await container.start();
|
|
105
|
-
await this.startAdmin();
|
|
106
|
-
}
|
|
107
|
-
async startAdmin() {
|
|
108
|
-
console.log("Mongodb Admin starting...");
|
|
109
|
-
await _makes.Docker.pullImage("mongo-express:latest");
|
|
110
|
-
const container = await _makes.Docker.createContainer({
|
|
111
|
-
name: this.adminContainer,
|
|
112
|
-
restart: "always",
|
|
113
|
-
env: {
|
|
114
|
-
ME_CONFIG_MONGODB_SERVER: this.container,
|
|
115
|
-
ME_CONFIG_MONGODB_PORT: "27017",
|
|
116
|
-
MONGO_ROOT_USER: "root",
|
|
117
|
-
MONGO_ROOT_PASSWORD: "toor",
|
|
118
|
-
ME_CONFIG_MONGODB_ADMINUSERNAME: "root",
|
|
119
|
-
ME_CONFIG_MONGODB_ADMINPASSWORD: "toor",
|
|
120
|
-
ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
|
|
121
|
-
ME_CONFIG_MONGODB_AUTH_DATABASE: "admin",
|
|
122
|
-
ME_CONFIG_MONGODB_AUTH_USERNAME: "root",
|
|
123
|
-
ME_CONFIG_MONGODB_AUTH_PASSWORD: "toor",
|
|
124
|
-
VIRTUAL_HOST: this.adminContainer,
|
|
125
|
-
VIRTUAL_PORT: "8081"
|
|
126
|
-
},
|
|
127
|
-
image: "mongo-express:latest"
|
|
128
|
-
});
|
|
129
|
-
await container.start();
|
|
130
|
-
}
|
|
131
|
-
async stop() {
|
|
132
|
-
await this.stopDB();
|
|
133
|
-
await this.stopAdmin();
|
|
134
|
-
}
|
|
135
|
-
async stopDB() {
|
|
136
|
-
console.log("Mongodb stopping...");
|
|
137
|
-
const container = await _makes.Docker.getContainer(this.container);
|
|
138
|
-
if (container) {
|
|
139
|
-
try {
|
|
140
|
-
await container.stop();
|
|
141
|
-
await container.remove();
|
|
142
|
-
} catch (err) {
|
|
143
|
-
_makes.Logger.error(err.message);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async stopAdmin() {
|
|
148
|
-
console.log("Mongodb Admin stopping...");
|
|
149
|
-
const container = await _makes.Docker.getContainer(this.adminContainer);
|
|
150
|
-
if (container) {
|
|
151
|
-
await container.stop().catch(() => {
|
|
152
|
-
//
|
|
153
|
-
});
|
|
154
|
-
await container.remove().catch(() => {
|
|
155
|
-
//
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async restart() {
|
|
160
|
-
await this.stop();
|
|
161
|
-
await this.start();
|
|
162
|
-
}
|
|
163
|
-
async backup(database) {
|
|
164
|
-
if (!database) {
|
|
165
|
-
database = await (0, _utils.promptSelect)({
|
|
166
|
-
message: "Database",
|
|
167
|
-
options: await this.getDatabases()
|
|
168
|
-
});
|
|
27
|
+
const utils_1 = require("@wocker/utils");
|
|
28
|
+
const Path = __importStar(require("path"));
|
|
29
|
+
const dateFns = __importStar(require("date-fns"));
|
|
30
|
+
const env_1 = require("../env");
|
|
31
|
+
const makes_1 = require("../makes");
|
|
32
|
+
const services_1 = require("../services");
|
|
33
|
+
class MongodbPlugin extends makes_1.Plugin {
|
|
34
|
+
constructor(di) {
|
|
35
|
+
super("mongodb");
|
|
36
|
+
this.container = "mongodb.workspace";
|
|
37
|
+
this.adminContainer = "dbadmin-mongodb.workspace";
|
|
38
|
+
this.dockerService = di.resolveService(services_1.DockerService);
|
|
39
|
+
this.dataDir = Path.join(env_1.DATA_DIR, "db/mongodb");
|
|
169
40
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
41
|
+
install(cli) {
|
|
42
|
+
super.install(cli);
|
|
43
|
+
cli.command("mongodb:start").action(() => {
|
|
44
|
+
return this.start();
|
|
45
|
+
});
|
|
46
|
+
cli.command("mongodb:stop").action(() => {
|
|
47
|
+
return this.stop();
|
|
48
|
+
});
|
|
49
|
+
cli.command("mongodb:restart").action(() => {
|
|
50
|
+
return this.restart();
|
|
51
|
+
});
|
|
52
|
+
cli.command("mongodb:backup [database]")
|
|
53
|
+
.completion("database", () => {
|
|
54
|
+
return this.getDatabases();
|
|
55
|
+
})
|
|
56
|
+
.action((options, database) => {
|
|
57
|
+
return this.backup(database);
|
|
58
|
+
});
|
|
59
|
+
cli.command("mongodb:restore [database] [filename]")
|
|
60
|
+
.completion("database", () => {
|
|
61
|
+
const dumpPath = this.dataPath("dump");
|
|
62
|
+
return makes_1.FS.readdir(dumpPath);
|
|
63
|
+
})
|
|
64
|
+
.completion("filename", (options, database) => {
|
|
65
|
+
if (!database) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const dirPath = this.dataPath("dump", database);
|
|
69
|
+
if (!makes_1.FS.existsSync(dirPath)) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return makes_1.FS.readdir(dirPath);
|
|
73
|
+
})
|
|
74
|
+
.action((options, database, filename) => {
|
|
75
|
+
return this.restore(database, filename);
|
|
76
|
+
});
|
|
77
|
+
cli.command("mongodb:delete-backup [database] [filename]")
|
|
78
|
+
.option("yes", {
|
|
79
|
+
type: "boolean",
|
|
80
|
+
alias: "y"
|
|
81
|
+
})
|
|
82
|
+
.completion("database", () => {
|
|
83
|
+
return this.getDatabasesDumps();
|
|
84
|
+
})
|
|
85
|
+
.completion("filename", (options, database) => {
|
|
86
|
+
if (!database) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const dumpPath = this.dataPath("dump", database);
|
|
90
|
+
if (!makes_1.FS.existsSync(dumpPath)) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
return makes_1.FS.readdirFiles(dumpPath);
|
|
94
|
+
})
|
|
95
|
+
.action((options, database, filename) => {
|
|
96
|
+
return this.deleteBackup(database, filename, options.yes);
|
|
97
|
+
});
|
|
177
98
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
99
|
+
async getDatabases() {
|
|
100
|
+
const stream = await makes_1.Docker.exec(this.container, [
|
|
101
|
+
"mongosh",
|
|
102
|
+
"--username", "root",
|
|
103
|
+
"--password", "toor",
|
|
104
|
+
"--quiet",
|
|
105
|
+
"--eval", "db.getMongo().getDBNames().forEach(function(i){print(i)})"
|
|
106
|
+
], false);
|
|
107
|
+
let res = "";
|
|
108
|
+
stream.on("data", (data) => {
|
|
109
|
+
res += (0, utils_1.demuxOutput)(data).toString();
|
|
110
|
+
});
|
|
111
|
+
await new Promise((resolve, reject) => {
|
|
112
|
+
stream.on("end", resolve);
|
|
113
|
+
stream.on("error", reject);
|
|
114
|
+
});
|
|
115
|
+
return res.split(/\r?\n/).filter((database) => {
|
|
116
|
+
return !!database;
|
|
117
|
+
});
|
|
194
118
|
}
|
|
195
|
-
|
|
196
|
-
|
|
119
|
+
async getDatabasesDumps() {
|
|
120
|
+
const dumpDir = this.dataPath("dump");
|
|
121
|
+
return makes_1.FS.readdir(dumpDir);
|
|
197
122
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
123
|
+
async start() {
|
|
124
|
+
console.log("Mongidb starting...");
|
|
125
|
+
await makes_1.Docker.pullImage("mongo:latest");
|
|
126
|
+
const container = await this.dockerService.createContainer({
|
|
127
|
+
name: this.container,
|
|
128
|
+
restart: "always",
|
|
129
|
+
image: "mongo:latest",
|
|
130
|
+
volumes: [
|
|
131
|
+
`${this.dataPath()}:/data/db`
|
|
132
|
+
],
|
|
133
|
+
ports: ["27017:27017"],
|
|
134
|
+
env: {
|
|
135
|
+
MONGO_INITDB_ROOT_USERNAME: "root",
|
|
136
|
+
MONGO_INITDB_ROOT_PASSWORD: "toor",
|
|
137
|
+
MONGO_ROOT_USER: "root",
|
|
138
|
+
MONGO_ROOT_PASSWORD: "toor"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
await container.start();
|
|
142
|
+
await this.startAdmin();
|
|
201
143
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
144
|
+
async startAdmin() {
|
|
145
|
+
console.log("Mongodb Admin starting...");
|
|
146
|
+
await makes_1.Docker.pullImage("mongo-express:latest");
|
|
147
|
+
const container = await this.dockerService.createContainer({
|
|
148
|
+
name: this.adminContainer,
|
|
149
|
+
restart: "always",
|
|
150
|
+
env: {
|
|
151
|
+
ME_CONFIG_MONGODB_SERVER: this.container,
|
|
152
|
+
ME_CONFIG_MONGODB_PORT: "27017",
|
|
153
|
+
MONGO_ROOT_USER: "root",
|
|
154
|
+
MONGO_ROOT_PASSWORD: "toor",
|
|
155
|
+
ME_CONFIG_MONGODB_ADMINUSERNAME: "root",
|
|
156
|
+
ME_CONFIG_MONGODB_ADMINPASSWORD: "toor",
|
|
157
|
+
ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
|
|
158
|
+
ME_CONFIG_MONGODB_AUTH_DATABASE: "admin",
|
|
159
|
+
ME_CONFIG_MONGODB_AUTH_USERNAME: "root",
|
|
160
|
+
ME_CONFIG_MONGODB_AUTH_PASSWORD: "toor",
|
|
161
|
+
VIRTUAL_HOST: this.adminContainer,
|
|
162
|
+
VIRTUAL_PORT: "8081"
|
|
163
|
+
},
|
|
164
|
+
image: "mongo-express:latest"
|
|
165
|
+
});
|
|
166
|
+
await container.start();
|
|
211
167
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
168
|
+
async stop() {
|
|
169
|
+
await this.stopDB();
|
|
170
|
+
await this.stopAdmin();
|
|
215
171
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
172
|
+
async stopDB() {
|
|
173
|
+
console.log("Mongodb stopping...");
|
|
174
|
+
const container = await this.dockerService.getContainer(this.container);
|
|
175
|
+
if (container) {
|
|
176
|
+
try {
|
|
177
|
+
await container.stop();
|
|
178
|
+
await container.remove();
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
makes_1.Logger.error(err.message);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
221
184
|
}
|
|
222
|
-
|
|
223
|
-
|
|
185
|
+
async stopAdmin() {
|
|
186
|
+
console.log("Mongodb Admin stopping...");
|
|
187
|
+
await this.dockerService.removeContainer(this.adminContainer);
|
|
224
188
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
await _makes.FS.rm(dirPath, {
|
|
229
|
-
force: true,
|
|
230
|
-
recursive: true
|
|
231
|
-
});
|
|
189
|
+
async restart() {
|
|
190
|
+
await this.stop();
|
|
191
|
+
await this.start();
|
|
232
192
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
193
|
+
async backup(database) {
|
|
194
|
+
if (!database) {
|
|
195
|
+
database = await (0, utils_1.promptSelect)({
|
|
196
|
+
message: "Database",
|
|
197
|
+
options: await this.getDatabases()
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const date = dateFns.format(new Date(), "yyyy-MM-dd HH-mm");
|
|
201
|
+
const dirPath = this.dataPath("dump", database);
|
|
202
|
+
const filePath = this.dataPath("dump", database, `${date}.gz`);
|
|
203
|
+
if (!makes_1.FS.existsSync(dirPath)) {
|
|
204
|
+
makes_1.FS.mkdirSync(dirPath, {
|
|
205
|
+
recursive: true
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const stream = await makes_1.Docker.exec(this.container, [
|
|
209
|
+
"mongodump",
|
|
210
|
+
"--authenticationDatabase", "admin",
|
|
211
|
+
"--host", `${this.container}:27017`,
|
|
212
|
+
"--username", "root",
|
|
213
|
+
"--password", "toor",
|
|
214
|
+
"--db", database,
|
|
215
|
+
"--archive",
|
|
216
|
+
"--gzip"
|
|
217
|
+
], false);
|
|
218
|
+
const file = makes_1.FS.createWriteStream(filePath);
|
|
219
|
+
stream.on("data", (data) => {
|
|
220
|
+
file.write((0, utils_1.demuxOutput)(data));
|
|
221
|
+
});
|
|
222
|
+
await new Promise((resolve, reject) => {
|
|
223
|
+
stream.on("end", resolve);
|
|
224
|
+
stream.on("error", reject);
|
|
225
|
+
});
|
|
244
226
|
}
|
|
245
|
-
|
|
246
|
-
|
|
227
|
+
async deleteBackup(database, filename, yes) {
|
|
228
|
+
if (!database) {
|
|
229
|
+
database = await (0, utils_1.promptSelect)({
|
|
230
|
+
message: "Database",
|
|
231
|
+
options: await this.getDatabasesDumps()
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (!database) {
|
|
235
|
+
throw new Error("No database");
|
|
236
|
+
}
|
|
237
|
+
const dirPath = this.dataPath("dump", database);
|
|
238
|
+
if (!makes_1.FS.existsSync(dirPath)) {
|
|
239
|
+
throw new Error(`Backups dir for database "${database}" not found`);
|
|
240
|
+
}
|
|
241
|
+
if (!filename) {
|
|
242
|
+
const files = await makes_1.FS.readdirFiles(dirPath);
|
|
243
|
+
if (files.length === 0) {
|
|
244
|
+
throw new Error(`No backups for ${database}`);
|
|
245
|
+
}
|
|
246
|
+
filename = await (0, utils_1.promptSelect)({
|
|
247
|
+
message: "File",
|
|
248
|
+
options: files
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
const filePath = this.dataPath("dump", database, filename);
|
|
252
|
+
if (!makes_1.FS.existsSync(filePath)) {
|
|
253
|
+
throw new Error(`Backup "${filename}" not found`);
|
|
254
|
+
}
|
|
255
|
+
if (!yes) {
|
|
256
|
+
yes = await (0, utils_1.promptConfirm)({
|
|
257
|
+
message: `Delete ${filename}?`,
|
|
258
|
+
default: false
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (!yes) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
await makes_1.FS.rm(filePath);
|
|
265
|
+
const otherFiles = await makes_1.FS.readdir(dirPath);
|
|
266
|
+
if (otherFiles.length === 0) {
|
|
267
|
+
await makes_1.FS.rm(dirPath, {
|
|
268
|
+
force: true,
|
|
269
|
+
recursive: true
|
|
270
|
+
});
|
|
271
|
+
}
|
|
247
272
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
273
|
+
async restore(database, filename) {
|
|
274
|
+
if (!database) {
|
|
275
|
+
const dumps = await makes_1.FS.readdir(this.dataPath("dump"));
|
|
276
|
+
if (dumps.length === 0) {
|
|
277
|
+
throw new Error("No dumps found");
|
|
278
|
+
}
|
|
279
|
+
database = await (0, utils_1.promptSelect)({
|
|
280
|
+
message: "Database",
|
|
281
|
+
options: dumps
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (!database) {
|
|
285
|
+
throw new Error("Need database name");
|
|
286
|
+
}
|
|
287
|
+
if (!filename) {
|
|
288
|
+
const filenames = await makes_1.FS.readdir(this.dataPath("dump", database));
|
|
289
|
+
filename = await (0, utils_1.promptSelect)({
|
|
290
|
+
message: "File",
|
|
291
|
+
options: filenames
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
const path = this.dataPath("dump", database, filename);
|
|
295
|
+
const file = makes_1.FS.createReadStream(path);
|
|
296
|
+
const stream = await makes_1.Docker.exec(this.container, [
|
|
297
|
+
"mongorestore",
|
|
298
|
+
"--authenticationDatabase", "admin",
|
|
299
|
+
"--host", `${this.container}:27017`,
|
|
300
|
+
"--username", "root",
|
|
301
|
+
"--password", "toor",
|
|
302
|
+
"--db", database,
|
|
303
|
+
"--drop",
|
|
304
|
+
"--gzip",
|
|
305
|
+
"--archive"
|
|
306
|
+
], false);
|
|
307
|
+
file.on("data", (data) => {
|
|
308
|
+
stream.write(data);
|
|
309
|
+
});
|
|
310
|
+
file.on("end", () => {
|
|
311
|
+
throw new Error("File end");
|
|
312
|
+
});
|
|
313
|
+
stream.on("error", (err) => {
|
|
314
|
+
file.close();
|
|
315
|
+
throw err;
|
|
316
|
+
});
|
|
317
|
+
console.log(path);
|
|
254
318
|
}
|
|
255
|
-
const path = this.dataPath("dump", database, filename);
|
|
256
|
-
const file = _makes.FS.createReadStream(path);
|
|
257
|
-
const stream = await _makes.Docker.exec(this.container, ["mongorestore", "--authenticationDatabase", "admin", "--host", `${this.container}:27017`, "--username", "root", "--password", "toor", "--db", database, "--drop", "--gzip", "--archive"], false);
|
|
258
|
-
file.on("data", data => {
|
|
259
|
-
stream.write(data);
|
|
260
|
-
});
|
|
261
|
-
file.on("end", () => {
|
|
262
|
-
throw new Error("File end");
|
|
263
|
-
});
|
|
264
|
-
stream.on("error", err => {
|
|
265
|
-
file.close();
|
|
266
|
-
throw err;
|
|
267
|
-
});
|
|
268
|
-
console.log(path);
|
|
269
|
-
}
|
|
270
319
|
}
|
|
271
|
-
exports.MongodbPlugin = MongodbPlugin;
|
|
320
|
+
exports.MongodbPlugin = MongodbPlugin;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Plugin } from "
|
|
3
|
-
import {
|
|
4
|
-
import { AppEventsService, ProjectService } from "src/services";
|
|
2
|
+
import { DI, Plugin, Project } from "../makes";
|
|
3
|
+
import { AppEventsService, ProjectService } from "../services";
|
|
5
4
|
type StartOptions = {
|
|
6
5
|
name?: string;
|
|
7
6
|
detach?: string;
|
|
@@ -21,7 +20,7 @@ type ForwardingOptions = {
|
|
|
21
20
|
declare class NgrokPlugin extends Plugin {
|
|
22
21
|
protected appEventsService: AppEventsService;
|
|
23
22
|
protected projectService: ProjectService;
|
|
24
|
-
constructor(
|
|
23
|
+
constructor(di: DI);
|
|
25
24
|
install(cli: Cli): void;
|
|
26
25
|
init(options: any): Promise<void>;
|
|
27
26
|
getForwarding(project: Project): Promise<string | undefined>;
|