@wocker/ws 1.0.2 → 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 +1 -1
- package/lib/App.d.ts +4 -3
- package/lib/App.js +98 -77
- package/lib/controllers/ImageController.d.ts +2 -2
- package/lib/controllers/ImageController.js +27 -27
- package/lib/controllers/PluginController.d.ts +2 -2
- package/lib/controllers/PluginController.js +78 -56
- package/lib/controllers/PresetController.d.ts +3 -1
- package/lib/controllers/PresetController.js +155 -136
- package/lib/controllers/ProjectController.d.ts +5 -5
- package/lib/controllers/ProjectController.js +653 -603
- package/lib/controllers/ProxyController.d.ts +4 -1
- package/lib/controllers/ProxyController.js +269 -245
- package/lib/controllers/index.js +19 -58
- package/lib/env.js +33 -15
- package/lib/index.d.ts +2 -0
- package/lib/index.js +30 -16
- 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 +298 -382
- package/lib/makes/FS.js +328 -304
- package/lib/makes/LineConvertStream.js +37 -40
- package/lib/makes/Logger.d.ts +9 -1
- package/lib/makes/Logger.js +22 -11
- 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/makes/Project.d.ts +45 -0
- 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 +3 -1
- package/lib/plugins/ElasticSearchPlugin.js +66 -66
- package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
- package/lib/plugins/LocaltunnelPlugin.js +256 -257
- package/lib/plugins/MaildevPlugin.d.ts +2 -2
- package/lib/plugins/MaildevPlugin.js +45 -44
- package/lib/plugins/MongodbPlugin.d.ts +2 -2
- package/lib/plugins/MongodbPlugin.js +303 -248
- package/lib/plugins/NgrokPlugin.d.ts +2 -2
- package/lib/plugins/NgrokPlugin.js +221 -231
- package/lib/plugins/PageKitePlugin.d.ts +2 -2
- package/lib/plugins/PageKitePlugin.js +150 -149
- package/lib/plugins/PostgresPlugin.d.ts +1 -1
- package/lib/plugins/PostgresPlugin.js +115 -89
- package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
- package/lib/plugins/ProxmoxPlugin.js +50 -38
- package/lib/plugins/RedisPlugin.d.ts +3 -1
- package/lib/plugins/RedisPlugin.js +73 -72
- package/lib/plugins/index.js +25 -103
- package/lib/services/AppConfigService.d.ts +3 -3
- package/lib/services/AppConfigService.js +162 -157
- package/lib/services/AppEventsService.js +26 -24
- package/lib/services/DockerService.d.ts +37 -2
- package/lib/services/DockerService.js +185 -205
- package/lib/services/LogService.d.ts +3 -2
- package/lib/services/LogService.js +33 -34
- package/lib/services/PluginService.d.ts +2 -1
- package/lib/services/PluginService.js +11 -14
- package/lib/services/PresetService.d.ts +8 -3
- package/lib/services/PresetService.js +60 -59
- package/lib/services/ProjectService.d.ts +11 -4
- package/lib/services/ProjectService.js +140 -129
- package/lib/services/index.js +21 -80
- 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 -20
- package/lib/utils/escapeRegExp.js +4 -7
- package/lib/utils/exec.js +38 -39
- package/lib/utils/fetch.js +46 -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.js +32 -191
- 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 +13 -39
- package/presets/bun/Dockerfile +11 -0
- package/presets/bun/config.json +3 -0
- package/presets/node/Dockerfile +4 -2
- package/presets/php-apache/Dockerfile +3 -2
- package/.github/workflows/publish.yml +0 -31
- package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
|
@@ -1,265 +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
|
-
this.dockerService = di.resolveService(_core.DockerService);
|
|
21
|
-
this.dataDir = Path.join(_env.DATA_DIR, "db/mongodb");
|
|
22
|
-
}
|
|
23
|
-
install(cli) {
|
|
24
|
-
super.install(cli);
|
|
25
|
-
cli.command("mongodb:start").action(() => {
|
|
26
|
-
return this.start();
|
|
27
|
-
});
|
|
28
|
-
cli.command("mongodb:stop").action(() => {
|
|
29
|
-
return this.stop();
|
|
30
|
-
});
|
|
31
|
-
cli.command("mongodb:restart").action(() => {
|
|
32
|
-
return this.restart();
|
|
33
|
-
});
|
|
34
|
-
cli.command("mongodb:backup [database]").completion("database", () => {
|
|
35
|
-
return this.getDatabases();
|
|
36
|
-
}).action((options, database) => {
|
|
37
|
-
return this.backup(database);
|
|
38
|
-
});
|
|
39
|
-
cli.command("mongodb:restore [database] [filename]").completion("database", () => {
|
|
40
|
-
const dumpPath = this.dataPath("dump");
|
|
41
|
-
return _makes.FS.readdir(dumpPath);
|
|
42
|
-
}).completion("filename", (options, database) => {
|
|
43
|
-
if (!database) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const dirPath = this.dataPath("dump", database);
|
|
47
|
-
if (!_makes.FS.existsSync(dirPath)) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
return _makes.FS.readdir(dirPath);
|
|
51
|
-
}).action((options, database, filename) => {
|
|
52
|
-
return this.restore(database, filename);
|
|
53
|
-
});
|
|
54
|
-
cli.command("mongodb:delete-backup [database] [filename]").option("yes", {
|
|
55
|
-
type: "boolean",
|
|
56
|
-
alias: "y"
|
|
57
|
-
}).completion("database", () => {
|
|
58
|
-
return this.getDatabasesDumps();
|
|
59
|
-
}).completion("filename", (options, database) => {
|
|
60
|
-
if (!database) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
const dumpPath = this.dataPath("dump", database);
|
|
64
|
-
if (!_makes.FS.existsSync(dumpPath)) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
return _makes.FS.readdirFiles(dumpPath);
|
|
68
|
-
}).action((options, database, filename) => {
|
|
69
|
-
return this.deleteBackup(database, filename, options.yes);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async getDatabases() {
|
|
73
|
-
const stream = await _makes.Docker.exec(this.container, ["mongosh", "--username", "root", "--password", "toor", "--quiet", "--eval", "db.getMongo().getDBNames().forEach(function(i){print(i)})"], false);
|
|
74
|
-
let res = "";
|
|
75
|
-
stream.on("data", data => {
|
|
76
|
-
res += (0, _utils.demuxOutput)(data).toString();
|
|
77
|
-
});
|
|
78
|
-
await new Promise((resolve, reject) => {
|
|
79
|
-
stream.on("end", resolve);
|
|
80
|
-
stream.on("error", reject);
|
|
81
|
-
});
|
|
82
|
-
return res.split(/\r?\n/).filter(database => {
|
|
83
|
-
return !!database;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async getDatabasesDumps() {
|
|
87
|
-
const dumpDir = this.dataPath("dump");
|
|
88
|
-
return _makes.FS.readdir(dumpDir);
|
|
89
|
-
}
|
|
90
|
-
async start() {
|
|
91
|
-
console.log("Mongidb starting...");
|
|
92
|
-
await _makes.Docker.pullImage("mongo:latest");
|
|
93
|
-
const container = await this.dockerService.createContainer({
|
|
94
|
-
name: this.container,
|
|
95
|
-
restart: "always",
|
|
96
|
-
image: "mongo:latest",
|
|
97
|
-
volumes: [`${this.dataPath()}:/data/db`],
|
|
98
|
-
ports: ["27017:27017"],
|
|
99
|
-
env: {
|
|
100
|
-
MONGO_INITDB_ROOT_USERNAME: "root",
|
|
101
|
-
MONGO_INITDB_ROOT_PASSWORD: "toor",
|
|
102
|
-
MONGO_ROOT_USER: "root",
|
|
103
|
-
MONGO_ROOT_PASSWORD: "toor"
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
await container.start();
|
|
107
|
-
await this.startAdmin();
|
|
108
|
-
}
|
|
109
|
-
async startAdmin() {
|
|
110
|
-
console.log("Mongodb Admin starting...");
|
|
111
|
-
await _makes.Docker.pullImage("mongo-express:latest");
|
|
112
|
-
const container = await this.dockerService.createContainer({
|
|
113
|
-
name: this.adminContainer,
|
|
114
|
-
restart: "always",
|
|
115
|
-
env: {
|
|
116
|
-
ME_CONFIG_MONGODB_SERVER: this.container,
|
|
117
|
-
ME_CONFIG_MONGODB_PORT: "27017",
|
|
118
|
-
MONGO_ROOT_USER: "root",
|
|
119
|
-
MONGO_ROOT_PASSWORD: "toor",
|
|
120
|
-
ME_CONFIG_MONGODB_ADMINUSERNAME: "root",
|
|
121
|
-
ME_CONFIG_MONGODB_ADMINPASSWORD: "toor",
|
|
122
|
-
ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
|
|
123
|
-
ME_CONFIG_MONGODB_AUTH_DATABASE: "admin",
|
|
124
|
-
ME_CONFIG_MONGODB_AUTH_USERNAME: "root",
|
|
125
|
-
ME_CONFIG_MONGODB_AUTH_PASSWORD: "toor",
|
|
126
|
-
VIRTUAL_HOST: this.adminContainer,
|
|
127
|
-
VIRTUAL_PORT: "8081"
|
|
128
|
-
},
|
|
129
|
-
image: "mongo-express:latest"
|
|
130
|
-
});
|
|
131
|
-
await container.start();
|
|
132
|
-
}
|
|
133
|
-
async stop() {
|
|
134
|
-
await this.stopDB();
|
|
135
|
-
await this.stopAdmin();
|
|
136
|
-
}
|
|
137
|
-
async stopDB() {
|
|
138
|
-
console.log("Mongodb stopping...");
|
|
139
|
-
const container = await this.dockerService.getContainer(this.container);
|
|
140
|
-
if (container) {
|
|
141
|
-
try {
|
|
142
|
-
await container.stop();
|
|
143
|
-
await container.remove();
|
|
144
|
-
} catch (err) {
|
|
145
|
-
_makes.Logger.error(err.message);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async stopAdmin() {
|
|
150
|
-
console.log("Mongodb Admin stopping...");
|
|
151
|
-
await this.dockerService.removeContainer(this.adminContainer);
|
|
152
|
-
}
|
|
153
|
-
async restart() {
|
|
154
|
-
await this.stop();
|
|
155
|
-
await this.start();
|
|
156
|
-
}
|
|
157
|
-
async backup(database) {
|
|
158
|
-
if (!database) {
|
|
159
|
-
database = await (0, _utils.promptSelect)({
|
|
160
|
-
message: "Database",
|
|
161
|
-
options: await this.getDatabases()
|
|
162
|
-
});
|
|
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");
|
|
163
40
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
});
|
|
171
98
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
+
});
|
|
188
118
|
}
|
|
189
|
-
|
|
190
|
-
|
|
119
|
+
async getDatabasesDumps() {
|
|
120
|
+
const dumpDir = this.dataPath("dump");
|
|
121
|
+
return makes_1.FS.readdir(dumpDir);
|
|
191
122
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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();
|
|
195
143
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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();
|
|
205
167
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
168
|
+
async stop() {
|
|
169
|
+
await this.stopDB();
|
|
170
|
+
await this.stopAdmin();
|
|
209
171
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
+
}
|
|
215
184
|
}
|
|
216
|
-
|
|
217
|
-
|
|
185
|
+
async stopAdmin() {
|
|
186
|
+
console.log("Mongodb Admin stopping...");
|
|
187
|
+
await this.dockerService.removeContainer(this.adminContainer);
|
|
218
188
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
await _makes.FS.rm(dirPath, {
|
|
223
|
-
force: true,
|
|
224
|
-
recursive: true
|
|
225
|
-
});
|
|
189
|
+
async restart() {
|
|
190
|
+
await this.stop();
|
|
191
|
+
await this.start();
|
|
226
192
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
+
});
|
|
238
226
|
}
|
|
239
|
-
|
|
240
|
-
|
|
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
|
+
}
|
|
241
272
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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);
|
|
248
318
|
}
|
|
249
|
-
const path = this.dataPath("dump", database, filename);
|
|
250
|
-
const file = _makes.FS.createReadStream(path);
|
|
251
|
-
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);
|
|
252
|
-
file.on("data", data => {
|
|
253
|
-
stream.write(data);
|
|
254
|
-
});
|
|
255
|
-
file.on("end", () => {
|
|
256
|
-
throw new Error("File end");
|
|
257
|
-
});
|
|
258
|
-
stream.on("error", err => {
|
|
259
|
-
file.close();
|
|
260
|
-
throw err;
|
|
261
|
-
});
|
|
262
|
-
console.log(path);
|
|
263
|
-
}
|
|
264
319
|
}
|
|
265
|
-
exports.MongodbPlugin = MongodbPlugin;
|
|
320
|
+
exports.MongodbPlugin = MongodbPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DI, Project, AppEventsService, ProjectService } from "@wocker/core";
|
|
2
1
|
import { Cli } from "@kearisp/cli";
|
|
3
|
-
import { Plugin } from "
|
|
2
|
+
import { DI, Plugin, Project } from "../makes";
|
|
3
|
+
import { AppEventsService, ProjectService } from "../services";
|
|
4
4
|
type StartOptions = {
|
|
5
5
|
name?: string;
|
|
6
6
|
detach?: string;
|