@wocker/ws 1.0.1 → 1.0.2
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/.github/workflows/publish.yml +31 -0
- package/README.md +11 -137
- package/bin/ws.js +7 -3
- package/lib/App.d.ts +7 -5
- package/lib/App.js +45 -11
- package/lib/controllers/ImageController.d.ts +3 -1
- package/lib/controllers/ImageController.js +3 -1
- package/lib/controllers/PluginController.d.ts +14 -0
- package/lib/controllers/PluginController.js +62 -0
- package/lib/controllers/PresetController.d.ts +19 -0
- package/lib/controllers/PresetController.js +150 -0
- package/lib/controllers/ProjectController.d.ts +13 -5
- package/lib/controllers/ProjectController.js +92 -25
- package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +9 -11
- package/lib/{plugins/ProxyPlugin.js → controllers/ProxyController.js} +120 -128
- package/lib/controllers/index.d.ts +3 -0
- package/lib/controllers/index.js +33 -0
- package/lib/env.js +9 -16
- package/lib/index.js +11 -24
- package/lib/makes/Docker.js +11 -25
- package/lib/makes/FS.d.ts +1 -1
- package/lib/makes/FS.js +13 -10
- package/lib/makes/Logger.d.ts +1 -7
- package/lib/makes/Logger.js +6 -33
- package/lib/makes/Plugin.js +2 -2
- package/lib/plugins/ElasticSearchPlugin.d.ts +16 -0
- package/lib/plugins/ElasticSearchPlugin.js +72 -0
- package/lib/plugins/LocaltunnelPlugin.d.ts +3 -3
- package/lib/plugins/LocaltunnelPlugin.js +17 -15
- package/lib/plugins/MaildevPlugin.d.ts +3 -1
- package/lib/plugins/MaildevPlugin.js +8 -5
- package/lib/plugins/MongodbPlugin.d.ts +5 -3
- package/lib/plugins/MongodbPlugin.js +10 -16
- package/lib/plugins/NgrokPlugin.d.ts +2 -3
- package/lib/plugins/NgrokPlugin.js +7 -6
- package/lib/plugins/PageKitePlugin.d.ts +2 -3
- package/lib/plugins/PageKitePlugin.js +8 -6
- package/lib/plugins/PostgresPlugin.js +5 -4
- package/lib/plugins/ProxmoxPlugin.js +2 -2
- package/lib/plugins/RedisPlugin.d.ts +8 -2
- package/lib/plugins/RedisPlugin.js +57 -20
- package/lib/plugins/index.d.ts +2 -6
- package/lib/plugins/index.js +11 -66
- package/lib/services/AppConfigService.d.ts +14 -4
- package/lib/services/AppConfigService.js +88 -3
- package/lib/services/AppEventsService.d.ts +5 -8
- package/lib/services/AppEventsService.js +2 -3
- package/lib/services/DockerService.d.ts +16 -0
- package/lib/services/DockerService.js +220 -0
- package/lib/services/LogService.d.ts +11 -0
- package/lib/services/LogService.js +39 -0
- package/lib/services/PluginService.d.ts +10 -0
- package/lib/services/PluginService.js +18 -0
- package/lib/services/PresetService.d.ts +9 -0
- package/lib/services/PresetService.js +63 -0
- package/lib/services/ProjectService.d.ts +8 -7
- package/lib/services/ProjectService.js +64 -12
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.js +44 -0
- package/lib/utils/demuxOutput.js +0 -2
- package/lib/utils/exec.d.ts +1 -1
- package/lib/utils/exec.js +4 -5
- package/lib/utils/fetch.js +3 -4
- package/lib/utils/image-build.js +2 -2
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +0 -44
- package/lib/utils/injectVariables.js +1 -1
- package/package.json +13 -13
- package/presets/node/config.json +9 -7
- package/presets/php-apache/Dockerfile +37 -36
- 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.d.ts +0 -38
- 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/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/serveo/Dockerfile +0 -17
package/lib/models/Project.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Project = exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = void 0;
|
|
7
|
-
var Path = _interopRequireWildcard(require("path"));
|
|
8
|
-
var _makes = require("../makes");
|
|
9
|
-
var _utils = require("../utils");
|
|
10
|
-
var _env = require("../env");
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
class Project {
|
|
14
|
-
setEnv(name, value) {
|
|
15
|
-
this.env = {
|
|
16
|
-
...(this.env || {}),
|
|
17
|
-
[name]: typeof value === "boolean" ? value ? "true" : "false" : value
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
getEnv(name, defaultValue) {
|
|
21
|
-
const {
|
|
22
|
-
[name]: value = defaultValue
|
|
23
|
-
} = this.env || {};
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
unsetEnv(name) {
|
|
27
|
-
if (this.env && this.env[name]) {
|
|
28
|
-
delete this.env[name];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
getMeta(name, defaultValue) {
|
|
32
|
-
const {
|
|
33
|
-
[name]: value = defaultValue
|
|
34
|
-
} = this.meta || {};
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
setMeta(name, value) {
|
|
38
|
-
if (!this.meta) {
|
|
39
|
-
this.meta = {};
|
|
40
|
-
}
|
|
41
|
-
this.meta[name] = value;
|
|
42
|
-
}
|
|
43
|
-
volumeMount(...volumes) {
|
|
44
|
-
if (volumes.length === 0) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const [volume, ...restVolumes] = volumes;
|
|
48
|
-
const {
|
|
49
|
-
destination
|
|
50
|
-
} = (0, _utils.volumeParse)(volume);
|
|
51
|
-
this.volumes = [...(this.volumes || []).filter(v => {
|
|
52
|
-
return v !== this.getVolumeByDestination(destination);
|
|
53
|
-
}), volume];
|
|
54
|
-
this.volumeMount(...restVolumes);
|
|
55
|
-
}
|
|
56
|
-
getVolumeBySource(source) {
|
|
57
|
-
return (this.volumes || []).find(volume => {
|
|
58
|
-
return (0, _utils.volumeParse)(volume).source === source;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
getVolumeByDestination(destination) {
|
|
62
|
-
return (this.volumes || []).find(volume => {
|
|
63
|
-
return (0, _utils.volumeParse)(volume).destination === destination;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
volumeUnmount(...volumes) {
|
|
67
|
-
this.volumes = this.volumes.filter(mounted => {
|
|
68
|
-
return !volumes.includes(mounted);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
static async get(id) {
|
|
72
|
-
//
|
|
73
|
-
}
|
|
74
|
-
async save() {
|
|
75
|
-
if (!this.name) {
|
|
76
|
-
throw new Error("Project should has a name");
|
|
77
|
-
}
|
|
78
|
-
if (!this.path) {
|
|
79
|
-
throw new Error("Project should has a path");
|
|
80
|
-
}
|
|
81
|
-
if (!this.id) {
|
|
82
|
-
this.id = this.name;
|
|
83
|
-
}
|
|
84
|
-
const projectDirPath = Path.join(_env.DATA_DIR, "projects", this.name);
|
|
85
|
-
if (!_makes.FS.existsSync(projectDirPath)) {
|
|
86
|
-
await _makes.FS.mkdir(projectDirPath);
|
|
87
|
-
}
|
|
88
|
-
const configPath = Path.join(_env.DATA_DIR, "projects", this.id, "config.json");
|
|
89
|
-
await _makes.FS.writeJSON(configPath, this);
|
|
90
|
-
const config = await (0, _utils.getConfig)();
|
|
91
|
-
await (0, _utils.setConfig)({
|
|
92
|
-
...config,
|
|
93
|
-
projects: [...(config.projects || []).filter(project => {
|
|
94
|
-
return project.id !== this.id;
|
|
95
|
-
}).filter(project => {
|
|
96
|
-
return project.src !== this.path;
|
|
97
|
-
}), {
|
|
98
|
-
id: this.id,
|
|
99
|
-
src: this.path
|
|
100
|
-
}]
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
static fromObject(data) {
|
|
104
|
-
const project = new Project();
|
|
105
|
-
for (const i in data) {
|
|
106
|
-
project[i] = data[i];
|
|
107
|
-
}
|
|
108
|
-
return project;
|
|
109
|
-
}
|
|
110
|
-
static async search(params = {}) {
|
|
111
|
-
const {
|
|
112
|
-
id,
|
|
113
|
-
name,
|
|
114
|
-
src
|
|
115
|
-
} = params;
|
|
116
|
-
const map = await _makes.FS.readJSON(_env.MAP_PATH);
|
|
117
|
-
const mapProjects = map.projects.filter(config => {
|
|
118
|
-
if (id) {
|
|
119
|
-
return config.id === id;
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
}).filter(config => {
|
|
123
|
-
if (src) {
|
|
124
|
-
return config.src === src;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
});
|
|
128
|
-
const projects = [];
|
|
129
|
-
for (const i in mapProjects) {
|
|
130
|
-
const projectConfig = await _makes.FS.readJSON(Path.join(_env.DATA_DIR, "projects", mapProjects[i].id, "config.json"));
|
|
131
|
-
const project = Project.fromObject({
|
|
132
|
-
...projectConfig,
|
|
133
|
-
id: projectConfig.id
|
|
134
|
-
});
|
|
135
|
-
if (name && project.name !== name) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
projects.push(project);
|
|
139
|
-
}
|
|
140
|
-
return projects;
|
|
141
|
-
}
|
|
142
|
-
static async searchOne(params = {}) {
|
|
143
|
-
const [project] = await Project.search(params);
|
|
144
|
-
return project || null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.Project = Project;
|
|
148
|
-
const PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
149
|
-
exports.PROJECT_TYPE_DOCKERFILE = PROJECT_TYPE_DOCKERFILE;
|
|
150
|
-
const PROJECT_TYPE_IMAGE = "image";
|
|
151
|
-
exports.PROJECT_TYPE_IMAGE = PROJECT_TYPE_IMAGE;
|
package/lib/models/index.d.ts
DELETED
package/lib/models/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Preset = require("./Preset");
|
|
7
|
-
Object.keys(_Preset).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Preset[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Preset[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _Project = require("./Project");
|
|
18
|
-
Object.keys(_Project).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _Project[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _Project[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Plugin } from "src/makes";
|
|
3
|
-
declare class MariadbPlugin extends Plugin {
|
|
4
|
-
protected dbDir: string;
|
|
5
|
-
protected user: string;
|
|
6
|
-
protected password: string;
|
|
7
|
-
constructor();
|
|
8
|
-
install(cli: Cli): void;
|
|
9
|
-
protected getDatabases(): Promise<string[]>;
|
|
10
|
-
protected getDumpDatabases(): Promise<string[]>;
|
|
11
|
-
protected getDumpFiles(database?: string): Promise<string[]>;
|
|
12
|
-
start(): Promise<void>;
|
|
13
|
-
protected startMariadb(): Promise<void>;
|
|
14
|
-
protected startAdmin(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
protected stopMariadb(): Promise<void>;
|
|
17
|
-
protected stopAdmin(): Promise<void>;
|
|
18
|
-
exec(options: any, command: string[]): Promise<void>;
|
|
19
|
-
backup(database?: string): Promise<void>;
|
|
20
|
-
deleteBackup(options: any, database?: string, filename?: string): Promise<void>;
|
|
21
|
-
restore(options: any, database?: string, filename?: string): Promise<void>;
|
|
22
|
-
dump(options: any, database?: string): Promise<void>;
|
|
23
|
-
import(options: any, database?: string): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
export { MariadbPlugin };
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.MariadbPlugin = void 0;
|
|
7
|
-
var Path = _interopRequireWildcard(require("path"));
|
|
8
|
-
var _format = _interopRequireDefault(require("date-fns/format"));
|
|
9
|
-
var _env = require("../env");
|
|
10
|
-
var _makes = require("../makes");
|
|
11
|
-
var _utils = require("../utils");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
class MariadbPlugin extends _makes.Plugin {
|
|
16
|
-
user = "root";
|
|
17
|
-
password = "toor";
|
|
18
|
-
constructor() {
|
|
19
|
-
super("mariadb");
|
|
20
|
-
this.dbDir = Path.join(_env.DATA_DIR, "db/mariadb");
|
|
21
|
-
// this.dataDir = Path.join(PLUGINS_DIR, "mariadb");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
install(cli) {
|
|
25
|
-
super.install(cli);
|
|
26
|
-
cli.command("mariadb:start").action(() => this.start());
|
|
27
|
-
cli.command("mariadb:stop").action(() => this.stop());
|
|
28
|
-
cli.command("mariadb:backup [database]").completion("database", () => this.getDatabases()).action((options, database) => this.backup(database));
|
|
29
|
-
cli.command("mariadb:delete-backup [database] [filename]").option("yes", {
|
|
30
|
-
type: "boolean",
|
|
31
|
-
alias: "y"
|
|
32
|
-
}).completion("database", () => this.getDumpDatabases()).completion("filename", (options, database) => this.getDumpFiles(database)).action((options, database, filename) => this.deleteBackup(options, database, filename));
|
|
33
|
-
cli.command("mariadb:restore [database] [filename]").completion("database", () => this.getDumpDatabases()).completion("filename", (options, database) => this.getDumpFiles(database)).action((options, database, filename) => this.restore(options, database, filename));
|
|
34
|
-
cli.command("mariadb:import <database>").completion("database", () => this.getDatabases()).action((options, database) => this.import(options, database));
|
|
35
|
-
cli.command("mariadb:dump <database>").completion("database", () => this.getDatabases()).action((options, database) => this.dump(options, database));
|
|
36
|
-
cli.command("mariadb:exec [...command]").action((options, command) => this.exec(options, command));
|
|
37
|
-
}
|
|
38
|
-
async getDatabases() {
|
|
39
|
-
const stream = await _makes.Docker.exec("mariadb.workspace", ["mysql", `-u${this.user}`, `-p${this.password}`, "-e", "SHOW DATABASES;"], false);
|
|
40
|
-
let res = "";
|
|
41
|
-
stream.on("data", data => {
|
|
42
|
-
res += (0, _utils.demuxOutput)(data).toString();
|
|
43
|
-
});
|
|
44
|
-
await new Promise((resolve, reject) => {
|
|
45
|
-
stream.on("end", resolve);
|
|
46
|
-
stream.on("error", reject);
|
|
47
|
-
});
|
|
48
|
-
return res.split(/\r?\n/).filter(database => {
|
|
49
|
-
return !/Database$/.test(database);
|
|
50
|
-
}).filter(database => {
|
|
51
|
-
return !/_schema/.test(database);
|
|
52
|
-
}).filter(database => {
|
|
53
|
-
return !!database;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
async getDumpDatabases() {
|
|
57
|
-
return _makes.FS.readdir(this.dataPath("dump"));
|
|
58
|
-
}
|
|
59
|
-
async getDumpFiles(database) {
|
|
60
|
-
if (!database) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
const dirPath = this.dataPath("dump", database);
|
|
64
|
-
if (!_makes.FS.existsSync(dirPath)) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
return _makes.FS.readdirFiles(dirPath);
|
|
68
|
-
}
|
|
69
|
-
async start() {
|
|
70
|
-
await this.startMariadb();
|
|
71
|
-
await this.startAdmin();
|
|
72
|
-
}
|
|
73
|
-
async startMariadb() {
|
|
74
|
-
console.info("Mariadb starting...");
|
|
75
|
-
await _makes.Docker.pullImage("mariadb:10.5");
|
|
76
|
-
await _makes.Docker.containerRun({
|
|
77
|
-
name: "mariadb.workspace",
|
|
78
|
-
restart: "always",
|
|
79
|
-
ports: ["3306:3306"],
|
|
80
|
-
env: {
|
|
81
|
-
MYSQL_ROOT_PASSWORD: "toor"
|
|
82
|
-
},
|
|
83
|
-
volumes: [`${this.dbDir}:/var/lib/mysql`],
|
|
84
|
-
image: "mariadb:10.5"
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
async startAdmin() {
|
|
88
|
-
console.info("Phpmyadmin starting...");
|
|
89
|
-
const configPath = "conf/config.user.inc.php";
|
|
90
|
-
if (!_makes.FS.existsSync(this.dataPath(configPath))) {
|
|
91
|
-
await _makes.FS.mkdir(Path.dirname(this.dataPath(configPath)), {
|
|
92
|
-
recursive: true
|
|
93
|
-
});
|
|
94
|
-
await _makes.FS.copyFile(this.pluginPath("admin", configPath), this.dataPath(configPath));
|
|
95
|
-
}
|
|
96
|
-
await _makes.FS.mkdir(this.dataPath("save"), {
|
|
97
|
-
recursive: true
|
|
98
|
-
});
|
|
99
|
-
await _makes.FS.mkdir(this.dataPath("upload"), {
|
|
100
|
-
recursive: true
|
|
101
|
-
});
|
|
102
|
-
await _makes.Docker.pullImage("phpmyadmin/phpmyadmin:latest");
|
|
103
|
-
await _makes.Docker.containerRun({
|
|
104
|
-
name: "dbadmin-mariadb.workspace",
|
|
105
|
-
restart: "always",
|
|
106
|
-
env: {
|
|
107
|
-
PMA_USER: "root",
|
|
108
|
-
PMA_PASSWORD: "toor",
|
|
109
|
-
VIRTUAL_HOST: "dbadmin-mariadb.workspace",
|
|
110
|
-
VIRTUAL_PORT: "80"
|
|
111
|
-
},
|
|
112
|
-
volumes: [`${this.dataPath("conf/config.user.inc.php")}:/etc/phpmyadmin/config.user.inc.php`, `${this.dataPath("save")}:/etc/phpmyadmin/save`, `${this.dataPath("upload")}:/etc/phpmyadmin/upload`],
|
|
113
|
-
links: ["mariadb.workspace:db"],
|
|
114
|
-
image: "phpmyadmin/phpmyadmin:latest"
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
async stop() {
|
|
118
|
-
await this.stopMariadb();
|
|
119
|
-
await this.stopAdmin();
|
|
120
|
-
}
|
|
121
|
-
async stopMariadb() {
|
|
122
|
-
console.info("Mariadb stopping...");
|
|
123
|
-
const container = await _makes.Docker.getContainer("mariadb.workspace");
|
|
124
|
-
if (container) {
|
|
125
|
-
try {
|
|
126
|
-
await container.stop();
|
|
127
|
-
} catch (err) {
|
|
128
|
-
_makes.Logger.warning(err.message, {
|
|
129
|
-
class: "MariadbPlugin"
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
await container.remove();
|
|
134
|
-
} catch (err) {
|
|
135
|
-
_makes.Logger.warning(err.message, {
|
|
136
|
-
class: "MariadbPlugin"
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async stopAdmin() {
|
|
142
|
-
console.info("Phpmyadmin stopping...");
|
|
143
|
-
const container = await _makes.Docker.getContainer("dbadmin-mariadb.workspace");
|
|
144
|
-
if (container) {
|
|
145
|
-
try {
|
|
146
|
-
await container.stop();
|
|
147
|
-
} catch (err) {
|
|
148
|
-
_makes.Logger.warning(err.message, {
|
|
149
|
-
class: "MariadbPlugin"
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
await container.remove();
|
|
154
|
-
} catch (err) {
|
|
155
|
-
_makes.Logger.warning(err.message, {
|
|
156
|
-
class: "MariadbPlugin"
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async exec(options, command) {
|
|
162
|
-
await _makes.Docker.exec("mariadb.workspace", command);
|
|
163
|
-
}
|
|
164
|
-
async backup(database) {
|
|
165
|
-
if (!database) {
|
|
166
|
-
database = await (0, _utils.promptSelect)({
|
|
167
|
-
message: "Database",
|
|
168
|
-
options: await this.getDatabases()
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
const date = (0, _format.default)(new Date(), "yyyy-MM-dd HH-mm");
|
|
172
|
-
const filePath = this.dataPath("dump", database, `${date}.sql`);
|
|
173
|
-
if (!_makes.FS.existsSync(Path.dirname(filePath))) {
|
|
174
|
-
_makes.FS.mkdirSync(Path.dirname(filePath), {
|
|
175
|
-
recursive: true
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const file = _makes.FS.createWriteStream(filePath);
|
|
179
|
-
const stream = await _makes.Docker.exec("mariadb.workspace", ["mysqldump", "--add-drop-table", `-u${this.user}`, `-p${this.password}`, database], false);
|
|
180
|
-
stream.on("data", data => {
|
|
181
|
-
file.write((0, _utils.demuxOutput)(data));
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
async deleteBackup(options, database, filename) {
|
|
185
|
-
const {
|
|
186
|
-
yes
|
|
187
|
-
} = options;
|
|
188
|
-
if (!database) {
|
|
189
|
-
const dumps = await this.getDumpDatabases();
|
|
190
|
-
if (dumps.length === 0) {
|
|
191
|
-
throw new Error("No dump databases");
|
|
192
|
-
}
|
|
193
|
-
database = await (0, _utils.promptSelect)({
|
|
194
|
-
message: "Database",
|
|
195
|
-
options: dumps
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
if (!filename) {
|
|
199
|
-
const files = await _makes.FS.readdirFiles(this.dataPath("dump", database));
|
|
200
|
-
if (files.length === 0) {
|
|
201
|
-
throw new Error(`No backups for ${database}`);
|
|
202
|
-
}
|
|
203
|
-
filename = await (0, _utils.promptSelect)({
|
|
204
|
-
message: "File",
|
|
205
|
-
options: files
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
if (!yes) {
|
|
209
|
-
const confirm = await (0, _utils.promptConfirm)({
|
|
210
|
-
message: `Delete ${filename}`,
|
|
211
|
-
default: false
|
|
212
|
-
});
|
|
213
|
-
if (!confirm) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
const filePath = this.dataPath("dump", database, filename);
|
|
218
|
-
await _makes.FS.rm(filePath);
|
|
219
|
-
const otherFiles = await _makes.FS.readdir(this.dataPath("dump", database));
|
|
220
|
-
if (otherFiles.length === 0) {
|
|
221
|
-
await _makes.FS.rm(this.dataPath("dump", database), {
|
|
222
|
-
force: true,
|
|
223
|
-
recursive: true
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async restore(options, database, filename) {
|
|
228
|
-
if (!database) {
|
|
229
|
-
const dumps = await _makes.FS.readdir(this.dataPath("dump"));
|
|
230
|
-
if (dumps.length === 0) {
|
|
231
|
-
throw new Error("No dumps found");
|
|
232
|
-
}
|
|
233
|
-
database = await (0, _utils.promptSelect)({
|
|
234
|
-
message: "Database",
|
|
235
|
-
options: dumps
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
if (!database) {
|
|
239
|
-
throw new Error("Need database name");
|
|
240
|
-
}
|
|
241
|
-
const dirs = await _makes.FS.readdir(this.dataPath("dump", database));
|
|
242
|
-
if (!filename) {
|
|
243
|
-
filename = await (0, _utils.promptSelect)({
|
|
244
|
-
message: "File",
|
|
245
|
-
options: dirs
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const path = this.dataPath("dump", database, filename);
|
|
249
|
-
const file = _makes.FS.createReadStream(path);
|
|
250
|
-
const stream = await _makes.Docker.exec("mariadb.workspace", ["mysql", "-uroot", "-ptoor", database], false);
|
|
251
|
-
file.on("data", data => {
|
|
252
|
-
stream.write(data);
|
|
253
|
-
});
|
|
254
|
-
file.on("end", () => {
|
|
255
|
-
stream.write("exit\n");
|
|
256
|
-
});
|
|
257
|
-
stream.on("error", data => {
|
|
258
|
-
process.stderr.write((0, _utils.demuxOutput)(data));
|
|
259
|
-
stream.write("exit\n");
|
|
260
|
-
file.close();
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
async dump(options, database) {
|
|
264
|
-
const date = (0, _format.default)(new Date(), "yyyy-MM-dd HH-mm");
|
|
265
|
-
const dirPath = this.dataPath("dump", database);
|
|
266
|
-
const filePath = this.dataPath("dump", database, `${date}.sql`);
|
|
267
|
-
if (!_makes.FS.existsSync(dirPath)) {
|
|
268
|
-
_makes.FS.mkdirSync(dirPath, {
|
|
269
|
-
recursive: true
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// const filePath = Path.join(DATA_DIR, `${database} ${date}.sql`);
|
|
274
|
-
// console.log(filePath);
|
|
275
|
-
|
|
276
|
-
const file = _makes.FS.createWriteStream(filePath);
|
|
277
|
-
const stream = await _makes.Docker.exec("mariadb.workspace", ["mysqldump", "-uroot", "-ptoor", database]);
|
|
278
|
-
stream.pipe(file);
|
|
279
|
-
}
|
|
280
|
-
async import(options, database) {
|
|
281
|
-
const container = await _makes.Docker.getContainer("mariadb.workspace");
|
|
282
|
-
const exec = await container.exec({
|
|
283
|
-
AttachStdin: true,
|
|
284
|
-
AttachStdout: true,
|
|
285
|
-
AttachStderr: true,
|
|
286
|
-
Tty: process.stdin.isTTY,
|
|
287
|
-
Cmd: ["mysql", `-u${this.user}`, `-p${this.password}`, database]
|
|
288
|
-
});
|
|
289
|
-
const stream = await exec.start({
|
|
290
|
-
hijack: true,
|
|
291
|
-
stdin: true,
|
|
292
|
-
Tty: process.stdin.isTTY
|
|
293
|
-
});
|
|
294
|
-
await _makes.Docker.attachStream(stream);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
exports.MariadbPlugin = MariadbPlugin;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Plugin } from "src/makes";
|
|
3
|
-
import { Project } from "src/models";
|
|
4
|
-
import { AppConfigService, AppEventsService } from "src/services";
|
|
5
|
-
type BuildOptions = {
|
|
6
|
-
rebuild?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare class PresetPlugin extends Plugin {
|
|
9
|
-
protected appConfigService: AppConfigService;
|
|
10
|
-
protected appEventsService: AppEventsService;
|
|
11
|
-
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService);
|
|
12
|
-
install(cli: Cli): void;
|
|
13
|
-
presets(): Promise<string[]>;
|
|
14
|
-
protected onInit(project: Project): Promise<void>;
|
|
15
|
-
protected onRebuild(project: Project): Promise<void>;
|
|
16
|
-
protected onBeforeStart(project: Project): Promise<void>;
|
|
17
|
-
build(options: BuildOptions, presetName: string): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export { PresetPlugin };
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PresetPlugin = void 0;
|
|
7
|
-
var Path = _interopRequireWildcard(require("path"));
|
|
8
|
-
var _env = require("../env");
|
|
9
|
-
var _makes = require("../makes");
|
|
10
|
-
var _models = require("../models");
|
|
11
|
-
var _utils = require("../utils");
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
class PresetPlugin extends _makes.Plugin {
|
|
15
|
-
constructor(appConfigService, appEventsService) {
|
|
16
|
-
super("preset");
|
|
17
|
-
this.appConfigService = appConfigService;
|
|
18
|
-
this.appEventsService = appEventsService;
|
|
19
|
-
this.pluginDir = Path.join(_env.ROOT_DIR, "presets");
|
|
20
|
-
}
|
|
21
|
-
install(cli) {
|
|
22
|
-
super.install(cli);
|
|
23
|
-
this.appConfigService.registerProjectType("preset", "Preset");
|
|
24
|
-
this.appEventsService.on("project:init", project => this.onInit(project));
|
|
25
|
-
this.appEventsService.on("project:rebuild", project => this.onRebuild(project));
|
|
26
|
-
this.appEventsService.on("project:beforeStart", project => this.onBeforeStart(project));
|
|
27
|
-
cli.command("preset:build <preset>").completion("preset", () => this.presets()).option("rebuild", {
|
|
28
|
-
alias: "r",
|
|
29
|
-
type: "boolean",
|
|
30
|
-
description: "Rebuild image"
|
|
31
|
-
}).action((options, preset) => this.build(options, preset));
|
|
32
|
-
}
|
|
33
|
-
async presets() {
|
|
34
|
-
return _makes.FS.readdir(this.pluginPath());
|
|
35
|
-
}
|
|
36
|
-
async onInit(project) {
|
|
37
|
-
if (project.type !== "preset") {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const presetName = await (0, _utils.promptSelect)({
|
|
41
|
-
message: "Select preset",
|
|
42
|
-
options: await _makes.FS.readdir(_env.PRESETS_DIR),
|
|
43
|
-
default: project.getEnv("PRESET_NAME")
|
|
44
|
-
});
|
|
45
|
-
const preset = await _models.Preset.get(presetName);
|
|
46
|
-
project.setEnv("PRESET_NAME", presetName);
|
|
47
|
-
if (preset.buildArgsOptions) {
|
|
48
|
-
project.buildArgs = await (0, _utils.promptGroup)(project.buildArgs || {}, preset.buildArgsOptions);
|
|
49
|
-
}
|
|
50
|
-
if (preset.envOptions) {
|
|
51
|
-
project.env = await (0, _utils.promptGroup)(project.env || {}, preset.envOptions);
|
|
52
|
-
}
|
|
53
|
-
if (preset.volumeOptions) {
|
|
54
|
-
for (let volume of preset.volumeOptions) {
|
|
55
|
-
volume = (0, _utils.injectVariables)(volume, {
|
|
56
|
-
...(project.buildArgs || {}),
|
|
57
|
-
...(project.env || {})
|
|
58
|
-
});
|
|
59
|
-
const {
|
|
60
|
-
destination,
|
|
61
|
-
options
|
|
62
|
-
} = (0, _utils.volumeParse)(volume);
|
|
63
|
-
let projectVolume = project.getVolumeByDestination(destination);
|
|
64
|
-
const source = await (0, _utils.promptText)({
|
|
65
|
-
message: "Volume",
|
|
66
|
-
suffix: `:${destination}`,
|
|
67
|
-
default: projectVolume ? (0, _utils.volumeParse)(projectVolume).source : "./"
|
|
68
|
-
});
|
|
69
|
-
projectVolume = (0, _utils.volumeFormat)({
|
|
70
|
-
source,
|
|
71
|
-
destination,
|
|
72
|
-
options
|
|
73
|
-
});
|
|
74
|
-
project.volumeMount(projectVolume);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (preset.dockerfile) {
|
|
78
|
-
project.imageName = preset.getImageName(project.buildArgs);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async onRebuild(project) {
|
|
82
|
-
if (project.type !== "preset") {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const presetName = project.getEnv("PRESET_NAME");
|
|
86
|
-
const preset = await _models.Preset.get(presetName);
|
|
87
|
-
if (!preset) {
|
|
88
|
-
throw new Error(`Preset ${presetName} not found`);
|
|
89
|
-
}
|
|
90
|
-
const imageName = preset.getImageName(project.buildArgs || {});
|
|
91
|
-
const exists = await _makes.Docker.imageExists(imageName);
|
|
92
|
-
if (exists) {
|
|
93
|
-
console.info(`Removing image: ${imageName}`);
|
|
94
|
-
await _makes.Docker.imageRm(imageName);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async onBeforeStart(project) {
|
|
98
|
-
if (project.type !== "preset") {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const presetName = project.getEnv("PRESET_NAME");
|
|
102
|
-
const preset = await _models.Preset.get(presetName);
|
|
103
|
-
const config = await _makes.FS.readJSON(this.pluginPath(project.getEnv("PRESET_NAME"), "config.json"));
|
|
104
|
-
|
|
105
|
-
// if(preset.volumes) {
|
|
106
|
-
// project.volumeMount(...preset.volumes);
|
|
107
|
-
// }
|
|
108
|
-
|
|
109
|
-
// if(preset.image) {
|
|
110
|
-
// project.imageName = config.image;
|
|
111
|
-
//
|
|
112
|
-
// return;
|
|
113
|
-
// }
|
|
114
|
-
|
|
115
|
-
if (preset.dockerfile) {
|
|
116
|
-
project.imageName = preset.getImageName(project.buildArgs);
|
|
117
|
-
_makes.Logger.info(project.imageName);
|
|
118
|
-
if (!(await _makes.Docker.imageExists(project.imageName))) {
|
|
119
|
-
const stream = await _makes.Docker.imageBuild2({
|
|
120
|
-
tag: project.imageName,
|
|
121
|
-
context: this.pluginPath(presetName),
|
|
122
|
-
src: config.dockerfile,
|
|
123
|
-
labels: {
|
|
124
|
-
presetName
|
|
125
|
-
},
|
|
126
|
-
buildArgs: project.buildArgs
|
|
127
|
-
});
|
|
128
|
-
await (0, _utils.followProgress)(stream);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async build(options, presetName) {
|
|
133
|
-
const {
|
|
134
|
-
rebuild
|
|
135
|
-
} = options;
|
|
136
|
-
const preset = await _models.Preset.get(presetName);
|
|
137
|
-
const presetPath = this.pluginPath(presetName);
|
|
138
|
-
let buildArgs = {};
|
|
139
|
-
if (preset.buildArgsOptions) {
|
|
140
|
-
buildArgs = await (0, _utils.promptGroup)(buildArgs, preset.buildArgsOptions);
|
|
141
|
-
}
|
|
142
|
-
const imageName = preset.getImageName(buildArgs);
|
|
143
|
-
_makes.Logger.info("Image name:", imageName);
|
|
144
|
-
_makes.Logger.info("Build args:", buildArgs);
|
|
145
|
-
if (rebuild) {
|
|
146
|
-
const exists = await _makes.Docker.imageExists(imageName);
|
|
147
|
-
if (exists) {
|
|
148
|
-
await _makes.Docker.imageRm(imageName);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const stream = await _makes.Docker.imageBuild2({
|
|
152
|
-
tag: imageName,
|
|
153
|
-
context: presetPath,
|
|
154
|
-
src: preset.dockerfile,
|
|
155
|
-
labels: {
|
|
156
|
-
presetName,
|
|
157
|
-
...buildArgs
|
|
158
|
-
},
|
|
159
|
-
buildArgs
|
|
160
|
-
});
|
|
161
|
-
await (0, _utils.followProgress)(stream);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.PresetPlugin = PresetPlugin;
|