@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.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/lib/App.d.ts +4 -3
  3. package/lib/App.js +98 -77
  4. package/lib/controllers/ImageController.d.ts +2 -2
  5. package/lib/controllers/ImageController.js +27 -27
  6. package/lib/controllers/PluginController.d.ts +2 -2
  7. package/lib/controllers/PluginController.js +78 -56
  8. package/lib/controllers/PresetController.d.ts +3 -1
  9. package/lib/controllers/PresetController.js +155 -136
  10. package/lib/controllers/ProjectController.d.ts +5 -5
  11. package/lib/controllers/ProjectController.js +653 -603
  12. package/lib/controllers/ProxyController.d.ts +4 -1
  13. package/lib/controllers/ProxyController.js +269 -245
  14. package/lib/controllers/index.js +19 -58
  15. package/lib/env.js +33 -15
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +30 -16
  18. package/lib/makes/Controller.js +4 -8
  19. package/lib/makes/DI.d.ts +7 -0
  20. package/lib/makes/DI.js +27 -0
  21. package/lib/makes/Docker.js +298 -382
  22. package/lib/makes/FS.js +328 -304
  23. package/lib/makes/LineConvertStream.js +37 -40
  24. package/lib/makes/Logger.d.ts +9 -1
  25. package/lib/makes/Logger.js +22 -11
  26. package/lib/makes/Model.js +8 -12
  27. package/lib/makes/MySQL.js +6 -27
  28. package/lib/makes/Plugin.d.ts +1 -1
  29. package/lib/makes/Plugin.js +55 -37
  30. package/lib/makes/Preset.d.ts +46 -0
  31. package/lib/makes/Preset.js +33 -0
  32. package/lib/makes/Project.d.ts +45 -0
  33. package/lib/makes/Project.js +127 -0
  34. package/lib/makes/Repository.js +18 -21
  35. package/lib/makes/index.d.ts +3 -0
  36. package/lib/makes/index.js +23 -69
  37. package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
  38. package/lib/plugins/ElasticSearchPlugin.js +66 -66
  39. package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
  40. package/lib/plugins/LocaltunnelPlugin.js +256 -257
  41. package/lib/plugins/MaildevPlugin.d.ts +2 -2
  42. package/lib/plugins/MaildevPlugin.js +45 -44
  43. package/lib/plugins/MongodbPlugin.d.ts +2 -2
  44. package/lib/plugins/MongodbPlugin.js +303 -248
  45. package/lib/plugins/NgrokPlugin.d.ts +2 -2
  46. package/lib/plugins/NgrokPlugin.js +221 -231
  47. package/lib/plugins/PageKitePlugin.d.ts +2 -2
  48. package/lib/plugins/PageKitePlugin.js +150 -149
  49. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  50. package/lib/plugins/PostgresPlugin.js +115 -89
  51. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  52. package/lib/plugins/ProxmoxPlugin.js +50 -38
  53. package/lib/plugins/RedisPlugin.d.ts +3 -1
  54. package/lib/plugins/RedisPlugin.js +73 -72
  55. package/lib/plugins/index.js +25 -103
  56. package/lib/services/AppConfigService.d.ts +3 -3
  57. package/lib/services/AppConfigService.js +162 -157
  58. package/lib/services/AppEventsService.js +26 -24
  59. package/lib/services/DockerService.d.ts +37 -2
  60. package/lib/services/DockerService.js +185 -205
  61. package/lib/services/LogService.d.ts +3 -2
  62. package/lib/services/LogService.js +33 -34
  63. package/lib/services/PluginService.d.ts +2 -1
  64. package/lib/services/PluginService.js +11 -14
  65. package/lib/services/PresetService.d.ts +8 -3
  66. package/lib/services/PresetService.js +60 -59
  67. package/lib/services/ProjectService.d.ts +11 -4
  68. package/lib/services/ProjectService.js +140 -129
  69. package/lib/services/index.js +21 -80
  70. package/lib/types/Config.d.ts +4 -3
  71. package/lib/types/Config.js +1 -4
  72. package/lib/types/EnvConfig.js +1 -4
  73. package/lib/types/index.js +16 -25
  74. package/lib/utils/buildOptions.js +5 -8
  75. package/lib/utils/demuxOutput.js +16 -20
  76. package/lib/utils/escapeRegExp.js +4 -7
  77. package/lib/utils/exec.js +38 -39
  78. package/lib/utils/fetch.js +46 -30
  79. package/lib/utils/followProgress.js +66 -77
  80. package/lib/utils/format-size-units.js +16 -16
  81. package/lib/utils/get-config.d.ts +1 -1
  82. package/lib/utils/get-config.js +13 -16
  83. package/lib/utils/get-cursor-position.js +22 -29
  84. package/lib/utils/image-build.js +35 -23
  85. package/lib/utils/index.js +32 -191
  86. package/lib/utils/injectVariables.js +10 -13
  87. package/lib/utils/parse-table.js +20 -23
  88. package/lib/utils/set-config.d.ts +1 -1
  89. package/lib/utils/set-config.js +12 -15
  90. package/lib/utils/spawn.js +17 -20
  91. package/lib/utils/tty.js +2 -6
  92. package/lib/utils/volumeFormat.js +5 -12
  93. package/lib/utils/volumeParse.js +10 -13
  94. package/package.json +13 -39
  95. package/presets/bun/Dockerfile +11 -0
  96. package/presets/bun/config.json +3 -0
  97. package/presets/node/Dockerfile +4 -2
  98. package/presets/php-apache/Dockerfile +3 -2
  99. package/.github/workflows/publish.yml +0 -31
  100. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
@@ -1,404 +1,320 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Docker = void 0;
7
- var _dockerode = _interopRequireDefault(require("dockerode"));
8
- var _imageBuild = require("../utils/image-build");
9
- var _followProgress = require("../utils/followProgress");
10
- var _FS = require("./FS");
11
- var _Logger = require("./Logger");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- const docker = new _dockerode.default({
14
- socketPath: "/var/run/docker.sock"
7
+ const dockerode_1 = __importDefault(require("dockerode"));
8
+ const image_build_1 = require("../utils/image-build");
9
+ const followProgress_1 = require("../utils/followProgress");
10
+ const FS_1 = require("./FS");
11
+ const Logger_1 = require("./Logger");
12
+ const docker = new dockerode_1.default({
13
+ socketPath: "/var/run/docker.sock"
15
14
  });
16
15
  class Docker {
17
- static docker = docker;
18
- static async exec(name, args, tty = true) {
19
- const container = docker.getContainer(name);
20
- const exec = await container.exec({
21
- AttachStdin: true,
22
- AttachStdout: true,
23
- AttachStderr: tty,
24
- Tty: tty,
25
- Cmd: args
26
- });
27
- const stream = await exec.start({
28
- hijack: true,
29
- stdin: tty,
30
- Tty: tty
31
- });
32
- if (tty) {
33
- stream.setEncoding("utf-8");
34
- process.stdin.resume();
35
- if (process.stdin.setRawMode) {
36
- process.stdin.setRawMode(true);
37
- }
38
- process.stdin.setEncoding("utf-8");
39
- process.stdin.pipe(stream);
40
- stream.pipe(process.stdout);
41
- stream.on("error", err => {
42
- _Logger.Logger.error(err.message);
43
- });
44
- stream.on("end", async () => {
45
- process.stdin.setRawMode(false);
46
- });
47
- stream.on("end", async () => {
48
- process.exit();
49
- });
50
- }
51
-
52
- // setTimeout(() => {
53
- // Logger.info("Exit");
54
- //
55
- // process.exit();
56
- // }, 4000);
57
-
58
- return stream;
59
- }
60
- static async getImage(name) {
61
- // let images = await exec(
62
- // "docker image ls" +
63
- // " --filter=reference=\"" + name + "\""
64
- // ).then((res:any) => {
65
- // let pos = {
66
- // 0: "repository",
67
- // 1: "tag",
68
- // 2: "imageId",
69
- // 3: "created",
70
- // 4: "size"
71
- // };
72
- //
73
- // res = res.stdout.split("\n").filter((line) => {
74
- // return line.split(new RegExp("\\s\\s+")).filter((item) => {
75
- // return item !== "";
76
- // }).length > 0;
77
- // }).map((line, index) => {
78
- // if(index === 0) {
79
- // return null;
80
- // }
81
- //
82
- // let data = line.split(new RegExp("\\s\\s+"));
83
- //
84
- // let row = {};
85
- //
86
- // for(let i in data) {
87
- // let name = pos[i];
88
- //
89
- // row[name] = data[i];
90
- // }
91
- //
92
- // return row;
93
- // }).filter((line) => {
94
- // if(!line) {
95
- // return false;
96
- // }
97
- //
98
- // return true;
99
- // });
100
- //
101
- // return res;
102
- // }).catch((err:any) => {
103
- // console.error(err);
104
- //
105
- // return [];
106
- // });
107
- //
108
- // return lodash.get(images, "[0]", null);
109
-
110
- return docker.getImage(name);
111
- }
112
- static async getContainer(name) {
113
- const containers = await docker.listContainers({
114
- all: true,
115
- filters: {
116
- name: [name]
117
- }
118
- });
119
- const container = containers.find(container => {
120
- return container.Names.indexOf("/" + name) >= 0;
121
- });
122
- if (container) {
123
- return docker.getContainer(container.Id);
16
+ static async exec(name, args, tty = true) {
17
+ const container = docker.getContainer(name);
18
+ const exec = await container.exec({
19
+ AttachStdin: true,
20
+ AttachStdout: true,
21
+ AttachStderr: tty,
22
+ Tty: tty,
23
+ Cmd: args
24
+ });
25
+ const stream = await exec.start({
26
+ hijack: true,
27
+ stdin: tty,
28
+ Tty: tty
29
+ });
30
+ if (tty) {
31
+ stream.setEncoding("utf-8");
32
+ process.stdin.resume();
33
+ if (process.stdin.setRawMode) {
34
+ process.stdin.setRawMode(true);
35
+ }
36
+ process.stdin.setEncoding("utf-8");
37
+ process.stdin.pipe(stream);
38
+ stream.pipe(process.stdout);
39
+ stream.on("error", (err) => {
40
+ Logger_1.Logger.error(err.message);
41
+ });
42
+ stream.on("end", async () => {
43
+ process.stdin.setRawMode(false);
44
+ });
45
+ stream.on("end", async () => {
46
+ process.exit();
47
+ });
48
+ }
49
+ return stream;
124
50
  }
125
- return null;
126
- }
127
- static async removeContainer(name) {
128
- const container = await Docker.getContainer(name);
129
- if (!container) {
130
- return;
51
+ static async getImage(name) {
52
+ return docker.getImage(name);
131
53
  }
132
- const {
133
- State: {
134
- Status
135
- }
136
- } = await container.inspect();
137
- if (Status === "running") {
138
- try {
139
- await container.stop();
140
- } catch (err) {
141
- _Logger.Logger.error("Docker.removeContainer: ", err.message);
142
- }
54
+ static async getContainer(name) {
55
+ const containers = await docker.listContainers({
56
+ all: true,
57
+ filters: {
58
+ name: [name]
59
+ }
60
+ });
61
+ const container = containers.find((container) => {
62
+ return container.Names.indexOf("/" + name) >= 0;
63
+ });
64
+ if (container) {
65
+ return docker.getContainer(container.Id);
66
+ }
67
+ return null;
143
68
  }
144
- try {
145
- await container.remove();
146
- } catch (err) {
147
- _Logger.Logger.error("Docker.removeContainer: ", err.message);
69
+ static async removeContainer(name) {
70
+ const container = await Docker.getContainer(name);
71
+ if (!container) {
72
+ return;
73
+ }
74
+ const { State: { Status } } = await container.inspect();
75
+ if (Status === "running") {
76
+ try {
77
+ await container.stop();
78
+ }
79
+ catch (err) {
80
+ Logger_1.Logger.error("Docker.removeContainer: ", err.message);
81
+ }
82
+ }
83
+ try {
84
+ await container.remove();
85
+ }
86
+ catch (err) {
87
+ Logger_1.Logger.error("Docker.removeContainer: ", err.message);
88
+ }
148
89
  }
149
- }
150
- static async getContainerList(options) {
151
- const {
152
- name,
153
- projectId
154
- } = options || {};
155
- const filters = {};
156
- if (name) {
157
- filters.name = [`/${name}`];
90
+ static async getContainerList(options) {
91
+ const { name, projectId } = options || {};
92
+ const filters = {};
93
+ if (name) {
94
+ filters.name = [`/${name}`];
95
+ }
96
+ if (projectId) {
97
+ if (!filters.label) {
98
+ filters.label = [];
99
+ }
100
+ filters.label.push(`projectId=${projectId}`);
101
+ }
102
+ return docker.listContainers({
103
+ all: true,
104
+ filters: JSON.stringify(filters)
105
+ });
158
106
  }
159
- if (projectId) {
160
- if (!filters.label) {
161
- filters.label = [];
162
- }
163
- filters.label.push(`projectId=${projectId}`);
107
+ static async attach(name) {
108
+ const container = await Docker.getContainer(name);
109
+ const stream = await container.attach({
110
+ logs: true,
111
+ stream: true,
112
+ hijack: true,
113
+ stdin: true,
114
+ stdout: true,
115
+ stderr: true
116
+ });
117
+ process.stdin.resume();
118
+ process.stdin.setEncoding("utf8");
119
+ process.stdin.setRawMode(true);
120
+ process.stdin.pipe(stream);
121
+ process.stdin.on("data", (data) => {
122
+ if (data.toString() === "\u0003") {
123
+ process.stdin.setRawMode(false);
124
+ }
125
+ });
126
+ stream.setEncoding("utf8");
127
+ stream.pipe(process.stdout);
128
+ const [width, height] = process.stdout.getWindowSize();
129
+ await container.resize({
130
+ w: width,
131
+ h: height
132
+ });
133
+ stream.on("end", async () => {
134
+ process.exit();
135
+ });
136
+ process.stdout.on("resize", () => {
137
+ const [width, height] = process.stdout.getWindowSize();
138
+ container.resize({
139
+ w: width,
140
+ h: height
141
+ });
142
+ });
164
143
  }
165
- return docker.listContainers({
166
- all: true,
167
- filters: JSON.stringify(filters)
168
- });
169
- }
170
- static async attach(name) {
171
- const container = await Docker.getContainer(name);
172
- const stream = await container.attach({
173
- logs: true,
174
- stream: true,
175
- hijack: true,
176
- stdin: true,
177
- stdout: true,
178
- stderr: true
179
- });
180
- process.stdin.resume();
181
- process.stdin.setEncoding("utf8");
182
- process.stdin.setRawMode(true);
183
- process.stdin.pipe(stream);
184
- process.stdin.on("data", data => {
185
- if (data.toString() === "\u0003") {
186
- process.stdin.setRawMode(false);
187
- }
188
- });
189
- stream.setEncoding("utf8");
190
- stream.pipe(process.stdout);
191
- const [width, height] = process.stdout.getWindowSize();
192
- await container.resize({
193
- w: width,
194
- h: height
195
- });
196
- stream.on("end", async () => {
197
- process.exit();
198
- });
199
- process.stdout.on("resize", () => {
200
- const [width, height] = process.stdout.getWindowSize();
201
- container.resize({
202
- w: width,
203
- h: height
204
- });
205
- });
206
- }
207
- static async attachStream(stream) {
208
- process.stdin.resume();
209
- process.stdin.setEncoding("utf8");
210
- process.stdin.pipe(stream);
211
- if (process.stdin.isTTY) {
212
- process.stdin.setRawMode(true);
144
+ static async attachStream(stream) {
145
+ process.stdin.resume();
146
+ process.stdin.setEncoding("utf8");
147
+ process.stdin.pipe(stream);
148
+ if (process.stdin.isTTY) {
149
+ process.stdin.setRawMode(true);
150
+ }
151
+ stream.setEncoding("utf8");
152
+ stream.pipe(process.stdout);
153
+ const end = () => {
154
+ process.stdin.pause();
155
+ process.stdin.unpipe(stream);
156
+ if (process.stdin.isTTY) {
157
+ process.stdin.setRawMode(false);
158
+ }
159
+ stream.unpipe(process.stdout);
160
+ };
161
+ await new Promise((resolve, reject) => {
162
+ stream.on("end", end);
163
+ stream.on("error", end);
164
+ stream.on("end", resolve);
165
+ stream.on("error", reject);
166
+ });
213
167
  }
214
- stream.setEncoding("utf8");
215
- stream.pipe(process.stdout);
216
- const end = () => {
217
- process.stdin.pause();
218
- process.stdin.unpipe(stream);
219
- if (process.stdin.isTTY) {
220
- process.stdin.setRawMode(false);
221
- }
222
- stream.unpipe(process.stdout);
223
- };
224
- await new Promise((resolve, reject) => {
225
- stream.on("end", end);
226
- stream.on("error", end);
227
- stream.on("end", resolve);
228
- stream.on("error", reject);
229
- });
230
- }
231
- static async imageExists(tag) {
232
- const image = docker.getImage(tag);
233
- try {
234
- await image.inspect();
235
- return true;
236
- } catch (ignore) {
237
- return false;
168
+ static async imageExists(tag) {
169
+ const image = docker.getImage(tag);
170
+ try {
171
+ await image.inspect();
172
+ return true;
173
+ }
174
+ catch (ignore) {
175
+ return false;
176
+ }
238
177
  }
239
- }
240
- static async imageLs(options) {
241
- const {
242
- tag,
243
- reference,
244
- labels
245
- } = options || {};
246
- const filters = {};
247
- if (reference) {
248
- filters.reference = [...(filters.reference || []), reference];
178
+ static async imageLs(options) {
179
+ const { tag, reference, labels } = options || {};
180
+ const filters = {};
181
+ if (reference) {
182
+ filters.reference = [
183
+ ...filters.reference || [],
184
+ reference
185
+ ];
186
+ }
187
+ if (tag) {
188
+ filters.reference = [
189
+ ...filters.reference || [],
190
+ tag
191
+ ];
192
+ }
193
+ if (labels) {
194
+ filters.label = [];
195
+ for (const i in labels) {
196
+ filters.label.push(`${i}=${labels[i]}`);
197
+ }
198
+ }
199
+ return docker.listImages({
200
+ filters: JSON.stringify(filters)
201
+ });
249
202
  }
250
- if (tag) {
251
- filters.reference = [...(filters.reference || []), tag];
203
+ static async imageBuild(options) {
204
+ await (0, image_build_1.imageBuild)(options);
252
205
  }
253
- if (labels) {
254
- filters.label = [];
255
- for (const i in labels) {
256
- filters.label.push(`${i}=${labels[i]}`);
257
- }
206
+ static async imageBuild2(options) {
207
+ const { tag, labels = {}, buildArgs = {}, context, src } = options;
208
+ const files = await FS_1.FS.readdirFiles(context, {
209
+ recursive: true
210
+ });
211
+ const stream = await docker.buildImage({
212
+ context,
213
+ src: files
214
+ }, {
215
+ t: tag,
216
+ labels,
217
+ dockerfile: src,
218
+ buildargs: buildArgs
219
+ });
220
+ return stream;
258
221
  }
259
- return docker.listImages({
260
- filters: JSON.stringify(filters)
261
- });
262
- }
263
- static async imageBuild(options) {
264
- // await docker.buildImage({
265
- // context:
266
- // });
267
-
268
- await (0, _imageBuild.imageBuild)(options);
269
- }
270
- static async imageBuild2(options) {
271
- const {
272
- tag,
273
- labels = {},
274
- buildArgs = {},
275
- context,
276
- src
277
- } = options;
278
- const files = await _FS.FS.readdirFiles(context, {
279
- recursive: true
280
- });
281
- const stream = await docker.buildImage({
282
- context,
283
- src: files
284
- }, {
285
- t: tag,
286
- labels,
287
- dockerfile: src,
288
- buildargs: buildArgs
289
- });
290
- return stream;
291
- }
292
- static async imageRm(name) {
293
- const image = await docker.getImage(name);
294
- if (!image) {
295
- return;
222
+ static async imageRm(name) {
223
+ const image = await docker.getImage(name);
224
+ if (!image) {
225
+ return;
226
+ }
227
+ await image.remove();
296
228
  }
297
- await image.remove();
298
- }
299
- static async pullImage(tag) {
300
- const isExists = await this.imageExists(tag);
301
- if (isExists) {
302
- return;
229
+ static async pullImage(tag) {
230
+ const isExists = await this.imageExists(tag);
231
+ if (isExists) {
232
+ return;
233
+ }
234
+ const stream = await docker.pull(tag, {});
235
+ await (0, followProgress_1.followProgress)(stream);
303
236
  }
304
- const stream = await docker.pull(tag, {});
305
- await (0, _followProgress.followProgress)(stream);
306
- }
307
- static async createContainer(options) {
308
- const {
309
- name,
310
- tty,
311
- image,
312
- projectId,
313
- restart,
314
- extraHosts,
315
- networkMode,
316
- links = [],
317
- env = {},
318
- volumes = [],
319
- ports = [],
320
- cmd = []
321
- } = options;
322
- const network = docker.getNetwork("workspace");
323
- try {
324
- await network.inspect();
325
- } catch (err) {
326
- if (err.statusCode === 404) {
327
- await docker.createNetwork({
328
- Name: "workspace"
237
+ static async createContainer(options) {
238
+ const { name, tty, image, projectId, restart, extraHosts, networkMode, links = [], env = {}, volumes = [], ports = [], cmd = [] } = options;
239
+ const network = docker.getNetwork("workspace");
240
+ try {
241
+ await network.inspect();
242
+ }
243
+ catch (err) {
244
+ if (err.statusCode === 404) {
245
+ await docker.createNetwork({
246
+ Name: "workspace"
247
+ });
248
+ }
249
+ }
250
+ await this.pullImage(image);
251
+ return await docker.createContainer({
252
+ name,
253
+ Image: image,
254
+ Hostname: name,
255
+ Labels: {
256
+ ...projectId ? { projectId } : {}
257
+ },
258
+ AttachStdin: true,
259
+ AttachStdout: true,
260
+ AttachStderr: true,
261
+ OpenStdin: true,
262
+ StdinOnce: false,
263
+ Tty: tty,
264
+ Cmd: cmd,
265
+ Env: Object.keys(env).map((key) => {
266
+ const value = env[key];
267
+ return `${key}=${value}`;
268
+ }),
269
+ ExposedPorts: ports.reduce((res, value) => {
270
+ const [, , containerPort] = /(\d+):(\d+)/.exec(value) || [];
271
+ if (containerPort) {
272
+ res[`${containerPort}/tcp`] = {};
273
+ }
274
+ return res;
275
+ }, {}),
276
+ HostConfig: {
277
+ NetworkMode: networkMode,
278
+ ExtraHosts: extraHosts,
279
+ ...restart ? {
280
+ RestartPolicy: {
281
+ Name: restart
282
+ }
283
+ } : {},
284
+ Binds: volumes,
285
+ PortBindings: ports.reduce((res, value) => {
286
+ const [, hostPort, containerPort] = /(\d+):(\d+)/.exec(value) || [];
287
+ if (hostPort && containerPort) {
288
+ res[`${containerPort}/tcp`] = [
289
+ { HostPort: hostPort }
290
+ ];
291
+ }
292
+ return res;
293
+ }, {})
294
+ },
295
+ NetworkingConfig: {
296
+ EndpointsConfig: networkMode === "host" ? {} : {
297
+ workspace: {
298
+ Links: links
299
+ }
300
+ }
301
+ }
329
302
  });
330
- }
331
303
  }
332
- await this.pullImage(image);
333
- return await docker.createContainer({
334
- name,
335
- Image: image,
336
- Hostname: name,
337
- Labels: {
338
- ...(projectId ? {
339
- projectId
340
- } : {})
341
- },
342
- AttachStdin: true,
343
- AttachStdout: true,
344
- AttachStderr: true,
345
- OpenStdin: true,
346
- StdinOnce: false,
347
- Tty: tty,
348
- Cmd: cmd,
349
- Env: Object.keys(env).map(key => {
350
- const value = env[key];
351
- return `${key}=${value}`;
352
- }),
353
- ExposedPorts: ports.reduce((res, value) => {
354
- const [,, containerPort] = /(\d+):(\d+)/.exec(value) || [];
355
- if (containerPort) {
356
- res[`${containerPort}/tcp`] = {};
357
- }
358
- return res;
359
- }, {}),
360
- HostConfig: {
361
- NetworkMode: networkMode,
362
- ExtraHosts: extraHosts,
363
- ...(restart ? {
364
- RestartPolicy: {
365
- Name: restart
366
- }
367
- } : {}),
368
- Binds: volumes,
369
- PortBindings: ports.reduce((res, value) => {
370
- const [, hostPort, containerPort] = /(\d+):(\d+)/.exec(value) || [];
371
- if (hostPort && containerPort) {
372
- res[`${containerPort}/tcp`] = [{
373
- HostPort: hostPort
374
- }];
375
- }
376
- return res;
377
- }, {})
378
- },
379
- NetworkingConfig: {
380
- EndpointsConfig: networkMode === "host" ? {} : {
381
- workspace: {
382
- Links: links
383
- }
304
+ static async containerRun(options, attach = false) {
305
+ const container = await Docker.createContainer(options);
306
+ if (attach) {
307
+ const stdout = await container.attach({
308
+ stream: true,
309
+ stdin: true,
310
+ stdout: true,
311
+ stderr: true
312
+ });
313
+ stdout.pipe(process.stdout);
384
314
  }
385
- }
386
- });
387
- }
388
- static async containerRun(options, attach = false) {
389
- const container = await Docker.createContainer(options);
390
- if (attach) {
391
- const stdout = await container.attach({
392
- // logs: true,
393
- stream: true,
394
- stdin: true,
395
- stdout: true,
396
- stderr: true
397
- });
398
- stdout.pipe(process.stdout);
315
+ await container.start();
316
+ return container;
399
317
  }
400
- await container.start();
401
- return container;
402
- }
403
318
  }
404
- exports.Docker = Docker;
319
+ exports.Docker = Docker;
320
+ Docker.docker = docker;