@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.
Files changed (136) hide show
  1. package/README.md +11 -137
  2. package/bin/ws.js +7 -3
  3. package/lib/App.d.ts +10 -7
  4. package/lib/App.js +99 -44
  5. package/lib/controllers/ImageController.d.ts +4 -2
  6. package/lib/controllers/ImageController.js +27 -25
  7. package/lib/controllers/PluginController.d.ts +14 -0
  8. package/lib/controllers/PluginController.js +84 -0
  9. package/lib/controllers/PresetController.d.ts +21 -0
  10. package/lib/controllers/PresetController.js +169 -0
  11. package/lib/controllers/ProjectController.d.ts +11 -3
  12. package/lib/controllers/ProjectController.js +653 -536
  13. package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
  14. package/lib/controllers/ProxyController.js +273 -0
  15. package/lib/controllers/index.d.ts +3 -0
  16. package/lib/controllers/index.js +19 -25
  17. package/lib/env.js +33 -22
  18. package/lib/index.d.ts +2 -0
  19. package/lib/index.js +29 -28
  20. package/lib/makes/Controller.js +4 -8
  21. package/lib/makes/DI.d.ts +7 -0
  22. package/lib/makes/DI.js +27 -0
  23. package/lib/makes/Docker.js +299 -397
  24. package/lib/makes/FS.d.ts +1 -1
  25. package/lib/makes/FS.js +328 -301
  26. package/lib/makes/LineConvertStream.js +37 -40
  27. package/lib/makes/Logger.d.ts +5 -3
  28. package/lib/makes/Logger.js +18 -34
  29. package/lib/makes/Model.js +8 -12
  30. package/lib/makes/MySQL.js +6 -27
  31. package/lib/makes/Plugin.d.ts +1 -1
  32. package/lib/makes/Plugin.js +55 -37
  33. package/lib/makes/Preset.d.ts +46 -0
  34. package/lib/makes/Preset.js +33 -0
  35. package/lib/{models → makes}/Project.d.ts +23 -16
  36. package/lib/makes/Project.js +127 -0
  37. package/lib/makes/Repository.js +18 -21
  38. package/lib/makes/index.d.ts +3 -0
  39. package/lib/makes/index.js +23 -69
  40. package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
  41. package/lib/plugins/ElasticSearchPlugin.js +72 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
  43. package/lib/plugins/LocaltunnelPlugin.js +256 -255
  44. package/lib/plugins/MaildevPlugin.d.ts +4 -2
  45. package/lib/plugins/MaildevPlugin.js +45 -41
  46. package/lib/plugins/MongodbPlugin.d.ts +6 -4
  47. package/lib/plugins/MongodbPlugin.js +303 -254
  48. package/lib/plugins/NgrokPlugin.d.ts +3 -4
  49. package/lib/plugins/NgrokPlugin.js +221 -230
  50. package/lib/plugins/PageKitePlugin.d.ts +3 -4
  51. package/lib/plugins/PageKitePlugin.js +150 -147
  52. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  53. package/lib/plugins/PostgresPlugin.js +115 -88
  54. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  55. package/lib/plugins/ProxmoxPlugin.js +50 -38
  56. package/lib/plugins/RedisPlugin.d.ts +10 -2
  57. package/lib/plugins/RedisPlugin.js +77 -39
  58. package/lib/plugins/index.d.ts +2 -6
  59. package/lib/plugins/index.js +25 -158
  60. package/lib/services/AppConfigService.d.ts +13 -3
  61. package/lib/services/AppConfigService.js +161 -71
  62. package/lib/services/AppEventsService.d.ts +5 -8
  63. package/lib/services/AppEventsService.js +26 -25
  64. package/lib/services/DockerService.d.ts +51 -0
  65. package/lib/services/DockerService.js +200 -0
  66. package/lib/services/LogService.d.ts +12 -0
  67. package/lib/services/LogService.js +38 -0
  68. package/lib/services/PluginService.d.ts +11 -0
  69. package/lib/services/PluginService.js +15 -0
  70. package/lib/services/PresetService.d.ts +14 -0
  71. package/lib/services/PresetService.js +64 -0
  72. package/lib/services/ProjectService.d.ts +12 -4
  73. package/lib/services/ProjectService.js +141 -78
  74. package/lib/services/index.d.ts +4 -0
  75. package/lib/services/index.js +21 -36
  76. package/lib/types/Config.d.ts +4 -3
  77. package/lib/types/Config.js +1 -4
  78. package/lib/types/EnvConfig.js +1 -4
  79. package/lib/types/index.js +16 -25
  80. package/lib/utils/buildOptions.js +5 -8
  81. package/lib/utils/demuxOutput.js +16 -22
  82. package/lib/utils/escapeRegExp.js +4 -7
  83. package/lib/utils/exec.d.ts +1 -1
  84. package/lib/utils/exec.js +38 -40
  85. package/lib/utils/fetch.js +45 -30
  86. package/lib/utils/followProgress.js +66 -77
  87. package/lib/utils/format-size-units.js +16 -16
  88. package/lib/utils/get-config.d.ts +1 -1
  89. package/lib/utils/get-config.js +13 -16
  90. package/lib/utils/get-cursor-position.js +22 -29
  91. package/lib/utils/image-build.js +35 -23
  92. package/lib/utils/index.d.ts +0 -4
  93. package/lib/utils/index.js +32 -235
  94. package/lib/utils/injectVariables.js +10 -13
  95. package/lib/utils/parse-table.js +20 -23
  96. package/lib/utils/set-config.d.ts +1 -1
  97. package/lib/utils/set-config.js +12 -15
  98. package/lib/utils/spawn.js +17 -20
  99. package/lib/utils/tty.js +2 -6
  100. package/lib/utils/volumeFormat.js +5 -12
  101. package/lib/utils/volumeParse.js +10 -13
  102. package/package.json +21 -47
  103. package/presets/bun/Dockerfile +11 -0
  104. package/presets/bun/config.json +3 -0
  105. package/presets/node/Dockerfile +4 -2
  106. package/presets/node/config.json +9 -7
  107. package/presets/php-apache/Dockerfile +40 -38
  108. package/presets/php-apache/config.json +10 -15
  109. package/presets/php-fpm/Dockerfile +21 -0
  110. package/presets/php-fpm/config.json +25 -0
  111. package/lib/models/Preset.d.ts +0 -19
  112. package/lib/models/Preset.js +0 -60
  113. package/lib/models/Project.js +0 -151
  114. package/lib/models/index.d.ts +0 -2
  115. package/lib/models/index.js +0 -27
  116. package/lib/plugins/MariadbPlugin.d.ts +0 -25
  117. package/lib/plugins/MariadbPlugin.js +0 -297
  118. package/lib/plugins/PresetPlugin.d.ts +0 -19
  119. package/lib/plugins/PresetPlugin.js +0 -164
  120. package/lib/plugins/ProjectPlugin.d.ts +0 -12
  121. package/lib/plugins/ProjectPlugin.js +0 -54
  122. package/lib/plugins/ProxyPlugin.js +0 -257
  123. package/lib/plugins/ServeoPlugin.d.ts +0 -36
  124. package/lib/plugins/ServeoPlugin.js +0 -260
  125. package/lib/plugins/TestPlugin.d.ts +0 -10
  126. package/lib/plugins/TestPlugin.js +0 -75
  127. package/lib/utils/promptConfirm.d.ts +0 -6
  128. package/lib/utils/promptConfirm.js +0 -21
  129. package/lib/utils/promptGroup.d.ts +0 -16
  130. package/lib/utils/promptGroup.js +0 -39
  131. package/lib/utils/promptSelect.d.ts +0 -12
  132. package/lib/utils/promptSelect.js +0 -47
  133. package/lib/utils/promptText.d.ts +0 -13
  134. package/lib/utils/promptText.js +0 -53
  135. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
  136. package/plugins/serveo/Dockerfile +0 -17
@@ -1,158 +1,161 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.PageKitePlugin = void 0;
7
- var _makes = require("../makes");
8
- var _utils = require("../utils");
9
- class PageKitePlugin extends _makes.Plugin {
10
- constructor(appConfigService, appEventsService, projectService) {
11
- super("pagekite");
12
- this.appConfigService = appConfigService;
13
- this.appEventsService = appEventsService;
14
- this.projectService = projectService;
15
- }
16
- install(cli) {
17
- super.install(cli);
18
- this.appEventsService.on("project:start", project => this.onProjectStart(project));
19
- this.appEventsService.on("project:stop", project => this.onProjectStop(project));
20
- cli.command("pagekite:init").action(options => this.init(options));
21
- cli.command("pagekite:start").option("name", {
22
- type: "string",
23
- alias: "n",
24
- description: "Project name"
25
- }).option("restart", {
26
- type: "boolean",
27
- alias: "r",
28
- description: "Restart"
29
- }).action(options => this.start(options));
30
- cli.command("pagekite:stop").option("name", {
31
- type: "string",
32
- alias: "n",
33
- description: "Project name"
34
- }).action(options => this.stop(options));
35
- cli.command("pagekite:build").option("rebuild", {
36
- type: "boolean",
37
- alias: "r",
38
- description: "Rebuild"
39
- }).action(options => this.build(options));
40
- }
41
- async onProjectStart(project) {
42
- if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
43
- return;
4
+ const utils_1 = require("@wocker/utils");
5
+ const makes_1 = require("../makes");
6
+ const utils_2 = require("../utils");
7
+ const services_1 = require("../services");
8
+ class PageKitePlugin extends makes_1.Plugin {
9
+ constructor(di) {
10
+ super("pagekite");
11
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
12
+ this.appEventsService = di.resolveService(services_1.AppEventsService);
13
+ this.projectService = di.resolveService(services_1.ProjectService);
44
14
  }
45
- console.info("Pagekite starting...");
46
- await this.build();
47
- let container = await _makes.Docker.getContainer(`pagekite-${project.name}`);
48
- if (container) {
49
- const {
50
- State: {
51
- Running
52
- }
53
- } = await container.inspect();
54
- if (Running) {
55
- console.info("Pagekite is already running");
56
- return;
57
- } else {
58
- await _makes.Docker.removeContainer(`pagekite-${project.name}`);
59
- }
60
- }
61
- const subdomain = project.getEnv("PAGEKITE_SUBDOMAIN");
62
- container = await _makes.Docker.createContainer({
63
- name: `pagekite-${project.name}`,
64
- image: "ws-pagekite",
65
- tty: true,
66
- restart: "always",
67
- cmd: ["python", "pagekite.py", `${project.name}.workspace:80`, `${subdomain}.pagekite.me`]
68
- });
69
- await container.start();
70
- await container.resize({
71
- w: process.stdout.columns,
72
- h: process.stdout.rows
73
- });
74
- const stream = await container.attach({
75
- stream: true,
76
- stdin: true,
77
- stdout: true,
78
- stderr: true,
79
- hijack: true,
80
- logs: true
81
- });
82
- stream.on("data", data => {
83
- if (/Kites are flying and all is well\./.test(data.toString())) {
84
- stream.end();
85
- }
86
- });
87
- await _makes.Docker.attachStream(stream);
88
- }
89
- async onProjectStop(project) {
90
- if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
91
- return;
15
+ install(cli) {
16
+ super.install(cli);
17
+ this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
18
+ this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
19
+ cli.command("pagekite:init")
20
+ .action((options) => this.init(options));
21
+ cli.command("pagekite:start")
22
+ .option("name", {
23
+ type: "string",
24
+ alias: "n",
25
+ description: "Project name"
26
+ })
27
+ .option("restart", {
28
+ type: "boolean",
29
+ alias: "r",
30
+ description: "Restart"
31
+ })
32
+ .action((options) => this.start(options));
33
+ cli.command("pagekite:stop")
34
+ .option("name", {
35
+ type: "string",
36
+ alias: "n",
37
+ description: "Project name"
38
+ })
39
+ .action((options) => this.stop(options));
40
+ cli.command("pagekite:build")
41
+ .option("rebuild", {
42
+ type: "boolean",
43
+ alias: "r",
44
+ description: "Rebuild"
45
+ })
46
+ .action((options) => this.build(options));
92
47
  }
93
- console.info("Pagekite stopping...");
94
- await _makes.Docker.removeContainer(`pagekite-${project.name}`);
95
- }
96
- async init(options) {
97
- const project = await this.projectService.get();
98
- const enabled = await (0, _utils.promptConfirm)({
99
- message: "Enable pagekite",
100
- default: project.getEnv("PAGEKITE_ENABLE", "true") === "true"
101
- });
102
- if (enabled) {
103
- project.setEnv("PAGEKITE_ENABLE", "true");
104
- const subdomain = await (0, _utils.promptText)({
105
- message: "Subdomain",
106
- prefix: "https://",
107
- suffix: ".pagekite.me",
108
- default: project.getEnv("PAGEKITE_SUBDOMAIN", project.name)
109
- });
110
- project.setEnv("PAGEKITE_SUBDOMAIN", subdomain);
111
- } else {
112
- project.setEnv("PAGEKITE_ENABLE", "false");
48
+ async onProjectStart(project) {
49
+ if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
50
+ return;
51
+ }
52
+ console.info("Pagekite starting...");
53
+ await this.build();
54
+ let container = await makes_1.Docker.getContainer(`pagekite-${project.name}`);
55
+ if (container) {
56
+ const { State: { Running } } = await container.inspect();
57
+ if (Running) {
58
+ console.info("Pagekite is already running");
59
+ return;
60
+ }
61
+ else {
62
+ await makes_1.Docker.removeContainer(`pagekite-${project.name}`);
63
+ }
64
+ }
65
+ const subdomain = project.getEnv("PAGEKITE_SUBDOMAIN");
66
+ container = await makes_1.Docker.createContainer({
67
+ name: `pagekite-${project.name}`,
68
+ image: "ws-pagekite",
69
+ tty: true,
70
+ restart: "always",
71
+ cmd: [
72
+ "python",
73
+ "pagekite.py",
74
+ `${project.name}.workspace:80`,
75
+ `${subdomain}.pagekite.me`
76
+ ]
77
+ });
78
+ await container.start();
79
+ await container.resize({
80
+ w: process.stdout.columns,
81
+ h: process.stdout.rows
82
+ });
83
+ const stream = await container.attach({
84
+ stream: true,
85
+ stdin: true,
86
+ stdout: true,
87
+ stderr: true,
88
+ hijack: true,
89
+ logs: true
90
+ });
91
+ stream.on("data", (data) => {
92
+ if (/Kites are flying and all is well\./.test(data.toString())) {
93
+ stream.end();
94
+ }
95
+ });
96
+ await makes_1.Docker.attachStream(stream);
113
97
  }
114
- await project.save();
115
- }
116
- async start(options) {
117
- const {
118
- name,
119
- restart
120
- } = options;
121
- if (name) {
122
- await this.projectService.cdProject(name);
98
+ async onProjectStop(project) {
99
+ if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
100
+ return;
101
+ }
102
+ console.info("Pagekite stopping...");
103
+ await makes_1.Docker.removeContainer(`pagekite-${project.name}`);
123
104
  }
124
- const project = await this.projectService.get();
125
- if (restart) {
126
- await _makes.Docker.removeContainer(`pagekite-${project.name}`);
105
+ async init(options) {
106
+ const project = await this.projectService.get();
107
+ const enabled = await (0, utils_1.promptConfirm)({
108
+ message: "Enable pagekite",
109
+ default: project.getEnv("PAGEKITE_ENABLE", "true") === "true"
110
+ });
111
+ if (enabled) {
112
+ project.setEnv("PAGEKITE_ENABLE", "true");
113
+ const subdomain = await (0, utils_1.promptText)({
114
+ message: "Subdomain",
115
+ prefix: "https://",
116
+ suffix: ".pagekite.me",
117
+ default: project.getEnv("PAGEKITE_SUBDOMAIN", project.name)
118
+ });
119
+ project.setEnv("PAGEKITE_SUBDOMAIN", subdomain);
120
+ }
121
+ else {
122
+ project.setEnv("PAGEKITE_ENABLE", "false");
123
+ }
124
+ await project.save();
127
125
  }
128
- await this.onProjectStart(project);
129
- }
130
- async stop(options) {
131
- const {
132
- name
133
- } = options;
134
- if (name) {
135
- await this.projectService.cdProject(name);
126
+ async start(options) {
127
+ const { name, restart } = options;
128
+ if (name) {
129
+ await this.projectService.cdProject(name);
130
+ }
131
+ const project = await this.projectService.get();
132
+ if (restart) {
133
+ await makes_1.Docker.removeContainer(`pagekite-${project.name}`);
134
+ }
135
+ await this.onProjectStart(project);
136
136
  }
137
- const project = await this.projectService.get();
138
- await this.onProjectStop(project);
139
- }
140
- async build(options = {}) {
141
- const {
142
- rebuild
143
- } = options;
144
- const exists = await _makes.Docker.imageExists("ws-pagekite");
145
- if (rebuild) {
146
- await _makes.Docker.removeContainer("ws-pagekite");
137
+ async stop(options) {
138
+ const { name } = options;
139
+ if (name) {
140
+ await this.projectService.cdProject(name);
141
+ }
142
+ const project = await this.projectService.get();
143
+ await this.onProjectStop(project);
147
144
  }
148
- if (!exists || rebuild) {
149
- const stream = await _makes.Docker.imageBuild2({
150
- tag: "ws-pagekite",
151
- context: this.pluginPath(),
152
- src: "./Dockerfile"
153
- });
154
- await (0, _utils.followProgress)(stream);
145
+ async build(options = {}) {
146
+ const { rebuild } = options;
147
+ const exists = await makes_1.Docker.imageExists("ws-pagekite");
148
+ if (rebuild) {
149
+ await makes_1.Docker.removeContainer("ws-pagekite");
150
+ }
151
+ if (!exists || rebuild) {
152
+ const stream = await makes_1.Docker.imageBuild2({
153
+ tag: "ws-pagekite",
154
+ context: this.pluginPath(),
155
+ src: "./Dockerfile"
156
+ });
157
+ await (0, utils_2.followProgress)(stream);
158
+ }
155
159
  }
156
- }
157
160
  }
158
- exports.PageKitePlugin = PageKitePlugin;
161
+ exports.PageKitePlugin = PageKitePlugin;
@@ -1,5 +1,5 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
2
+ import { Plugin } from "../makes";
3
3
  declare class PostgresPlugin extends Plugin {
4
4
  protected container: string;
5
5
  protected adminContainer: string;
@@ -1,94 +1,121 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.PostgresPlugin = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _env = require("../env");
9
- var _makes = require("../makes");
10
- 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); }
11
- 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; }
12
- class PostgresPlugin extends _makes.Plugin {
13
- container = "postgres.workspace";
14
- adminContainer = "dbadmin-postgres.workspace";
15
- constructor() {
16
- super("postgres");
17
- this.dataDir = Path.join(_env.DATA_DIR, "db/postgres");
18
- }
19
- install(cli) {
20
- super.install(cli);
21
- cli.command("postgres:start").action(() => this.start());
22
- cli.command("postgres:stop").action(() => this.stop());
23
- cli.command("postgres:restart").action(() => this.restart());
24
- }
25
- async start() {
26
- await this.startDB();
27
- await this.startAdmin();
28
- }
29
- async startDB() {
30
- console.log("Postgres starting...");
31
- await _makes.Docker.pullImage("postgres:latest");
32
- const container = await _makes.Docker.createContainer({
33
- name: this.container,
34
- restart: "always",
35
- image: "postgres:latest",
36
- volumes: [`${this.dataPath()}:/var/lib/postgresql/data`],
37
- ports: ["5432:5432"],
38
- env: {
39
- POSTGRES_USER: "root",
40
- POSTGRES_PASSWORD: "toor"
41
- }
42
- });
43
- await container.start();
44
- }
45
- async startAdmin() {
46
- console.log("Postgres Admin starting...");
47
- await _makes.Docker.pullImage("dpage/pgadmin4:latest");
48
- const container = await _makes.Docker.createContainer({
49
- name: this.adminContainer,
50
- restart: "always",
51
- links: [`${this.container}:postgres`],
52
- env: {
53
- PGADMIN_DEFAULT_EMAIL: "postgres@workspace.com.ua",
54
- PGADMIN_DEFAULT_PASSWORD: "toor",
55
- VIRTUAL_HOST: this.adminContainer
56
- },
57
- image: "dpage/pgadmin4:latest"
58
- });
59
- await container.start();
60
- }
61
- async stop() {
62
- await this.stopDB();
63
- await this.stopAdmin();
64
- }
65
- async stopDB() {
66
- console.log("Postgres stopping...");
67
- const container = await _makes.Docker.getContainer(this.container);
68
- if (container) {
69
- try {
70
- await container.stop();
71
- await container.remove();
72
- } catch (err) {
73
- _makes.Logger.error(err.message);
74
- }
27
+ const Path = __importStar(require("path"));
28
+ const env_1 = require("../env");
29
+ const makes_1 = require("../makes");
30
+ class PostgresPlugin extends makes_1.Plugin {
31
+ constructor() {
32
+ super("postgres");
33
+ this.container = "postgres.workspace";
34
+ this.adminContainer = "dbadmin-postgres.workspace";
35
+ this.dataDir = Path.join(env_1.DATA_DIR, "db/postgres");
36
+ }
37
+ install(cli) {
38
+ super.install(cli);
39
+ cli.command("postgres:start")
40
+ .action(() => this.start());
41
+ cli.command("postgres:stop")
42
+ .action(() => this.stop());
43
+ cli.command("postgres:restart")
44
+ .action(() => this.restart());
45
+ }
46
+ async start() {
47
+ await this.startDB();
48
+ await this.startAdmin();
49
+ }
50
+ async startDB() {
51
+ console.log("Postgres starting...");
52
+ await makes_1.Docker.pullImage("postgres:latest");
53
+ const container = await makes_1.Docker.createContainer({
54
+ name: this.container,
55
+ restart: "always",
56
+ image: "postgres:latest",
57
+ volumes: [
58
+ `${this.dataPath()}:/var/lib/postgresql/data`
59
+ ],
60
+ ports: ["5432:5432"],
61
+ env: {
62
+ POSTGRES_USER: "root",
63
+ POSTGRES_PASSWORD: "toor"
64
+ }
65
+ });
66
+ await container.start();
67
+ }
68
+ async startAdmin() {
69
+ console.log("Postgres Admin starting...");
70
+ await makes_1.Docker.pullImage("dpage/pgadmin4:latest");
71
+ const container = await makes_1.Docker.createContainer({
72
+ name: this.adminContainer,
73
+ restart: "always",
74
+ links: [
75
+ `${this.container}:postgres`
76
+ ],
77
+ env: {
78
+ PGADMIN_DEFAULT_EMAIL: "postgres@workspace.com.ua",
79
+ PGADMIN_DEFAULT_PASSWORD: "toor",
80
+ VIRTUAL_HOST: this.adminContainer
81
+ },
82
+ image: "dpage/pgadmin4:latest"
83
+ });
84
+ await container.start();
85
+ }
86
+ async stop() {
87
+ await this.stopDB();
88
+ await this.stopAdmin();
89
+ }
90
+ async stopDB() {
91
+ console.log("Postgres stopping...");
92
+ const container = await makes_1.Docker.getContainer(this.container);
93
+ if (container) {
94
+ try {
95
+ await container.stop();
96
+ await container.remove();
97
+ }
98
+ catch (err) {
99
+ makes_1.Logger.error(err.message);
100
+ }
101
+ }
102
+ }
103
+ async stopAdmin() {
104
+ console.log("Stopping postgres admin...");
105
+ const container = await makes_1.Docker.getContainer(this.adminContainer);
106
+ if (container) {
107
+ try {
108
+ await container.stop();
109
+ await container.remove();
110
+ }
111
+ catch (err) {
112
+ makes_1.Logger.error(err.message);
113
+ }
114
+ }
75
115
  }
76
- }
77
- async stopAdmin() {
78
- console.log("Stopping postgres admin...");
79
- const container = await _makes.Docker.getContainer(this.adminContainer);
80
- if (container) {
81
- try {
82
- await container.stop();
83
- await container.remove();
84
- } catch (err) {
85
- _makes.Logger.error(err.message);
86
- }
116
+ async restart() {
117
+ await this.stop();
118
+ await this.start();
87
119
  }
88
- }
89
- async restart() {
90
- await this.stop();
91
- await this.start();
92
- }
93
120
  }
94
- exports.PostgresPlugin = PostgresPlugin;
121
+ exports.PostgresPlugin = PostgresPlugin;
@@ -1,5 +1,5 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
2
+ import { Plugin } from "../makes";
3
3
  export declare class ProxmoxPlugin extends Plugin {
4
4
  protected configDir: string;
5
5
  constructor();
@@ -1,37 +1,52 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.ProxmoxPlugin = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _makes = require("../makes");
9
- var _utils = require("../utils");
10
- 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); }
11
- 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; }
12
- class ProxmoxPlugin extends _makes.Plugin {
13
- constructor() {
14
- super("proxmox");
15
- this.configDir = Path.join(__dirname, "../../services/proxmox");
16
- }
17
- install(cli) {
18
- super.install(cli);
19
- }
20
- async up() {
21
- const container = await _makes.Docker.getContainer("proxmox.workspace");
22
- if (container) {
23
- await this.down();
27
+ const Path = __importStar(require("path"));
28
+ const makes_1 = require("../makes");
29
+ const utils_1 = require("../utils");
30
+ class ProxmoxPlugin extends makes_1.Plugin {
31
+ constructor() {
32
+ super("proxmox");
33
+ this.configDir = Path.join(__dirname, "../../services/proxmox");
34
+ }
35
+ install(cli) {
36
+ super.install(cli);
24
37
  }
25
- await (0, _utils.exec)(`
38
+ async up() {
39
+ const container = await makes_1.Docker.getContainer("proxmox.workspace");
40
+ if (container) {
41
+ await this.down();
42
+ }
43
+ await (0, utils_1.exec)(`
26
44
  docker build \
27
45
  --tag "ws-proxmox" \
28
46
  --file "${this.pluginPath("./Dockerfile")}" \
29
47
  ${this.pluginPath()}
30
48
  `);
31
-
32
- // --add-host=""
33
-
34
- await (0, _utils.exec)(`
49
+ await (0, utils_1.exec)(`
35
50
  docker run -d \
36
51
  --name proxmox.workspace \
37
52
  --network workspace \
@@ -39,17 +54,14 @@ class ProxmoxPlugin extends _makes.Plugin {
39
54
  -p 8006:8006 \
40
55
  ws-proxmox
41
56
  `);
42
- }
43
- async down() {
44
- await (0, _utils.exec)("docker stop proxmox.workspace").catch(() => {
45
- //
46
- });
47
- await (0, _utils.exec)("docker rm proxmox.workspace").catch(() => {
48
- //
49
- });
50
- await (0, _utils.exec)("docker image rm ws-proxmox").catch(() => {
51
- //
52
- });
53
- }
57
+ }
58
+ async down() {
59
+ await (0, utils_1.exec)("docker stop proxmox.workspace").catch(() => {
60
+ });
61
+ await (0, utils_1.exec)("docker rm proxmox.workspace").catch(() => {
62
+ });
63
+ await (0, utils_1.exec)("docker image rm ws-proxmox").catch(() => {
64
+ });
65
+ }
54
66
  }
55
- exports.ProxmoxPlugin = ProxmoxPlugin;
67
+ exports.ProxmoxPlugin = ProxmoxPlugin;