@wocker/ws 1.0.13 → 1.0.14
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/lib/AppModule.js +2 -1
- package/lib/controllers/ProjectController.d.ts +12 -3
- package/lib/controllers/ProjectController.js +256 -48
- package/lib/controllers/ProxyController.d.ts +4 -11
- package/lib/controllers/ProxyController.js +21 -216
- package/lib/env.d.ts +1 -0
- package/lib/env.js +2 -1
- package/lib/services/DockerService.d.ts +1 -1
- package/lib/services/DockerService.js +20 -15
- package/lib/services/ProjectService.d.ts +3 -5
- package/lib/services/ProjectService.js +25 -36
- package/lib/services/ProxyService.d.ts +14 -0
- package/lib/services/ProxyService.js +97 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.js +1 -0
- package/package.json +2 -2
- package/presets/php-apache/Dockerfile +1 -1
package/lib/AppModule.js
CHANGED
|
@@ -88,7 +88,8 @@ exports.AppModule = AppModule = AppModule_1 = __decorate([
|
|
|
88
88
|
services_1.LogService,
|
|
89
89
|
services_1.PluginService,
|
|
90
90
|
services_1.PresetService,
|
|
91
|
-
services_1.ProjectService
|
|
91
|
+
services_1.ProjectService,
|
|
92
|
+
services_1.ProxyService
|
|
92
93
|
],
|
|
93
94
|
exports: [
|
|
94
95
|
services_1.AppConfigService,
|
|
@@ -12,8 +12,15 @@ export declare class ProjectController {
|
|
|
12
12
|
projectList(all: boolean): Promise<string>;
|
|
13
13
|
start(name?: string, detach?: boolean, attach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
|
|
14
14
|
stop(name: string): Promise<void>;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
domains(name?: string): Promise<string>;
|
|
16
|
+
addDomain(name: string, addDomains: string[]): Promise<void>;
|
|
17
|
+
setDomains(name: string, domains: string[]): Promise<void>;
|
|
18
|
+
removeDomain(name: string, removeDomains: string[]): Promise<void>;
|
|
19
|
+
clearDomain(name?: string): Promise<void>;
|
|
20
|
+
ports(name?: string): Promise<string>;
|
|
21
|
+
addPort(hostPort: string, containerPort: string, name?: string): Promise<void>;
|
|
22
|
+
removePort(hostPort: string, containerPort: string, name?: string): Promise<void>;
|
|
23
|
+
clearPorts(name?: string): Promise<void>;
|
|
17
24
|
configList(name?: string, global?: boolean): Promise<string>;
|
|
18
25
|
configGet(name: string, global: boolean, keys: string[]): Promise<string>;
|
|
19
26
|
configSet(name: string, global: boolean, variables: string[]): Promise<void>;
|
|
@@ -25,6 +32,8 @@ export declare class ProjectController {
|
|
|
25
32
|
volumeList(name?: string): Promise<string>;
|
|
26
33
|
volumeMount(name: string, volumes: string[]): Promise<void>;
|
|
27
34
|
volumeUnmount(name: string, volumes: string[]): Promise<void>;
|
|
28
|
-
logs(name
|
|
35
|
+
logs(name?: string, global?: boolean, detach?: boolean, follow?: boolean): Promise<void>;
|
|
29
36
|
exec(name?: string, command?: string[]): Promise<void>;
|
|
37
|
+
run(name: string, script: string, args?: string[]): Promise<void>;
|
|
38
|
+
attach(name?: string): Promise<void>;
|
|
30
39
|
}
|
|
@@ -90,6 +90,7 @@ let ProjectController = class ProjectController {
|
|
|
90
90
|
message: "Project name:",
|
|
91
91
|
default: project.name || Path.basename(project.path)
|
|
92
92
|
});
|
|
93
|
+
project.addDomain(project.containerName);
|
|
93
94
|
}
|
|
94
95
|
if (type) {
|
|
95
96
|
project.type = type;
|
|
@@ -160,10 +161,7 @@ let ProjectController = class ProjectController {
|
|
|
160
161
|
await this.projectService.cdProject(name);
|
|
161
162
|
}
|
|
162
163
|
const project = await this.projectService.get();
|
|
163
|
-
|
|
164
|
-
await this.projectService.rebuild(project);
|
|
165
|
-
}
|
|
166
|
-
await this.projectService.start(project, restart);
|
|
164
|
+
await this.projectService.start(project, rebuild, restart);
|
|
167
165
|
if (detach) {
|
|
168
166
|
console.info(chalk_1.default.yellow("Warning: Detach option is deprecated"));
|
|
169
167
|
}
|
|
@@ -185,38 +183,96 @@ let ProjectController = class ProjectController {
|
|
|
185
183
|
const project = await this.projectService.get();
|
|
186
184
|
await this.projectService.stop(project);
|
|
187
185
|
}
|
|
188
|
-
async
|
|
186
|
+
async domains(name) {
|
|
189
187
|
if (name) {
|
|
190
188
|
await this.projectService.cdProject(name);
|
|
191
189
|
}
|
|
192
190
|
const project = await this.projectService.get();
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
const table = new cli_table3_1.default({
|
|
192
|
+
head: [chalk_1.default.yellow("Domain")]
|
|
193
|
+
});
|
|
194
|
+
for (const domain of project.domains) {
|
|
195
|
+
table.push([domain]);
|
|
195
196
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
return table.toString();
|
|
198
|
+
}
|
|
199
|
+
async addDomain(name, addDomains) {
|
|
200
|
+
if (name) {
|
|
201
|
+
await this.projectService.cdProject(name);
|
|
199
202
|
}
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
203
|
+
const project = await this.projectService.get();
|
|
204
|
+
for (const domain of addDomains) {
|
|
205
|
+
project.addDomain(domain);
|
|
206
|
+
}
|
|
207
|
+
await project.save();
|
|
208
|
+
}
|
|
209
|
+
async setDomains(name, domains) {
|
|
210
|
+
if (name) {
|
|
211
|
+
await this.projectService.cdProject(name);
|
|
212
|
+
}
|
|
213
|
+
const project = await this.projectService.get();
|
|
214
|
+
project.clearDomains();
|
|
215
|
+
for (const domain of domains) {
|
|
216
|
+
project.addDomain(domain);
|
|
217
|
+
}
|
|
218
|
+
await project.save();
|
|
219
|
+
}
|
|
220
|
+
async removeDomain(name, removeDomains) {
|
|
221
|
+
if (name) {
|
|
222
|
+
await this.projectService.cdProject(name);
|
|
223
|
+
}
|
|
224
|
+
const project = await this.projectService.get();
|
|
225
|
+
for (const domain of removeDomains) {
|
|
226
|
+
project.removeDomain(domain);
|
|
227
|
+
}
|
|
228
|
+
await project.save();
|
|
229
|
+
}
|
|
230
|
+
async clearDomain(name) {
|
|
231
|
+
if (name) {
|
|
232
|
+
await this.projectService.cdProject(name);
|
|
233
|
+
}
|
|
234
|
+
const project = await this.projectService.get();
|
|
235
|
+
project.clearDomains();
|
|
236
|
+
await project.save();
|
|
237
|
+
}
|
|
238
|
+
async ports(name) {
|
|
239
|
+
if (name) {
|
|
240
|
+
await this.projectService.cdProject(name);
|
|
241
|
+
}
|
|
242
|
+
const project = await this.projectService.get();
|
|
243
|
+
const table = new cli_table3_1.default({
|
|
244
|
+
head: ["Ports"]
|
|
211
245
|
});
|
|
212
|
-
|
|
246
|
+
for (const port of project.ports || []) {
|
|
247
|
+
table.push([port]);
|
|
248
|
+
}
|
|
249
|
+
return table.toString();
|
|
213
250
|
}
|
|
214
|
-
async
|
|
251
|
+
async addPort(hostPort, containerPort, name) {
|
|
215
252
|
if (name) {
|
|
216
253
|
await this.projectService.cdProject(name);
|
|
217
254
|
}
|
|
218
255
|
const project = await this.projectService.get();
|
|
219
|
-
|
|
256
|
+
project.linkPort(parseInt(hostPort), parseInt(containerPort));
|
|
257
|
+
await project.save();
|
|
258
|
+
}
|
|
259
|
+
async removePort(hostPort, containerPort, name) {
|
|
260
|
+
if (name) {
|
|
261
|
+
await this.projectService.cdProject(name);
|
|
262
|
+
}
|
|
263
|
+
const project = await this.projectService.get();
|
|
264
|
+
project.unlinkPort(parseInt(hostPort), parseInt(containerPort));
|
|
265
|
+
await project.save();
|
|
266
|
+
}
|
|
267
|
+
async clearPorts(name) {
|
|
268
|
+
if (name) {
|
|
269
|
+
await this.projectService.cdProject(name);
|
|
270
|
+
}
|
|
271
|
+
const project = await this.projectService.get();
|
|
272
|
+
if (project.ports) {
|
|
273
|
+
delete project.ports;
|
|
274
|
+
await project.save();
|
|
275
|
+
}
|
|
220
276
|
}
|
|
221
277
|
async configList(name, global) {
|
|
222
278
|
if (name) {
|
|
@@ -473,7 +529,11 @@ let ProjectController = class ProjectController {
|
|
|
473
529
|
follow: true
|
|
474
530
|
});
|
|
475
531
|
stream.on("data", (data) => {
|
|
476
|
-
|
|
532
|
+
try {
|
|
533
|
+
data = (0, utils_1.demuxOutput)(data);
|
|
534
|
+
}
|
|
535
|
+
catch (err) { }
|
|
536
|
+
process.stdout.write(data);
|
|
477
537
|
});
|
|
478
538
|
}
|
|
479
539
|
else {
|
|
@@ -490,8 +550,40 @@ let ProjectController = class ProjectController {
|
|
|
490
550
|
await this.projectService.cdProject(name);
|
|
491
551
|
}
|
|
492
552
|
const project = await this.projectService.get();
|
|
493
|
-
|
|
494
|
-
|
|
553
|
+
await this.dockerService.exec(project.containerName, command);
|
|
554
|
+
}
|
|
555
|
+
async run(name, script, args) {
|
|
556
|
+
if (name) {
|
|
557
|
+
await this.projectService.cdProject(name);
|
|
558
|
+
}
|
|
559
|
+
const project = await this.projectService.get();
|
|
560
|
+
if (!project.scripts || !project.scripts[script]) {
|
|
561
|
+
throw new Error(`Script ${script} not found`);
|
|
562
|
+
}
|
|
563
|
+
const container = await this.dockerService.getContainer(`${project.name}.workspace`);
|
|
564
|
+
if (!container) {
|
|
565
|
+
throw new Error("The project is not started");
|
|
566
|
+
}
|
|
567
|
+
const exec = await container.exec({
|
|
568
|
+
Cmd: ["bash", "-i", "-c", [project.scripts[script], ...args || []].join(" ")],
|
|
569
|
+
AttachStdin: true,
|
|
570
|
+
AttachStdout: true,
|
|
571
|
+
AttachStderr: true,
|
|
572
|
+
Tty: process.stdin.isTTY
|
|
573
|
+
});
|
|
574
|
+
const stream = await exec.start({
|
|
575
|
+
hijack: true,
|
|
576
|
+
stdin: true,
|
|
577
|
+
Tty: process.stdin.isTTY
|
|
578
|
+
});
|
|
579
|
+
await this.dockerService.attachStream(stream);
|
|
580
|
+
}
|
|
581
|
+
async attach(name) {
|
|
582
|
+
if (name) {
|
|
583
|
+
await this.projectService.cdProject(name);
|
|
584
|
+
}
|
|
585
|
+
const project = await this.projectService.get();
|
|
586
|
+
await this.dockerService.attach(project.containerName);
|
|
495
587
|
}
|
|
496
588
|
};
|
|
497
589
|
exports.ProjectController = ProjectController;
|
|
@@ -512,7 +604,7 @@ __decorate([
|
|
|
512
604
|
__param(0, (0, core_1.Option)("name", {
|
|
513
605
|
type: "string",
|
|
514
606
|
alias: "n",
|
|
515
|
-
description: "
|
|
607
|
+
description: "The name of the project"
|
|
516
608
|
})),
|
|
517
609
|
__param(1, (0, core_1.Option)("type", {
|
|
518
610
|
type: "string",
|
|
@@ -545,7 +637,7 @@ __decorate([
|
|
|
545
637
|
__param(0, (0, core_1.Option)("name", {
|
|
546
638
|
type: "string",
|
|
547
639
|
alias: "n",
|
|
548
|
-
description: "
|
|
640
|
+
description: "The name of the project",
|
|
549
641
|
help: true
|
|
550
642
|
})),
|
|
551
643
|
__param(1, (0, core_1.Option)("detach", {
|
|
@@ -577,39 +669,121 @@ __decorate([
|
|
|
577
669
|
__param(0, (0, core_1.Option)("name", {
|
|
578
670
|
type: "string",
|
|
579
671
|
alias: "n",
|
|
580
|
-
description: "
|
|
672
|
+
description: "The name of the project"
|
|
581
673
|
})),
|
|
582
674
|
__metadata("design:type", Function),
|
|
583
675
|
__metadata("design:paramtypes", [String]),
|
|
584
676
|
__metadata("design:returntype", Promise)
|
|
585
677
|
], ProjectController.prototype, "stop", null);
|
|
586
678
|
__decorate([
|
|
587
|
-
(0, core_1.Command)("
|
|
679
|
+
(0, core_1.Command)("domains"),
|
|
680
|
+
__param(0, (0, core_1.Option)("name", {
|
|
681
|
+
type: "string",
|
|
682
|
+
alias: "n",
|
|
683
|
+
description: "The name of the project"
|
|
684
|
+
})),
|
|
685
|
+
__metadata("design:type", Function),
|
|
686
|
+
__metadata("design:paramtypes", [String]),
|
|
687
|
+
__metadata("design:returntype", Promise)
|
|
688
|
+
], ProjectController.prototype, "domains", null);
|
|
689
|
+
__decorate([
|
|
690
|
+
(0, core_1.Command)("domain:add [...domains]"),
|
|
691
|
+
__param(0, (0, core_1.Option)("name", {
|
|
692
|
+
type: "string",
|
|
693
|
+
alias: "n",
|
|
694
|
+
description: "The name of the project"
|
|
695
|
+
})),
|
|
696
|
+
__metadata("design:type", Function),
|
|
697
|
+
__metadata("design:paramtypes", [String, Array]),
|
|
698
|
+
__metadata("design:returntype", Promise)
|
|
699
|
+
], ProjectController.prototype, "addDomain", null);
|
|
700
|
+
__decorate([
|
|
701
|
+
(0, core_1.Command)("domain:set [...domains]"),
|
|
588
702
|
__param(0, (0, core_1.Option)("name", {
|
|
589
703
|
type: "string",
|
|
590
704
|
alias: "n",
|
|
591
705
|
description: "Project name"
|
|
592
706
|
})),
|
|
593
707
|
__metadata("design:type", Function),
|
|
594
|
-
__metadata("design:paramtypes", [String,
|
|
708
|
+
__metadata("design:paramtypes", [String, Array]),
|
|
709
|
+
__metadata("design:returntype", Promise)
|
|
710
|
+
], ProjectController.prototype, "setDomains", null);
|
|
711
|
+
__decorate([
|
|
712
|
+
(0, core_1.Command)("domain:remove [...domains]"),
|
|
713
|
+
__param(0, (0, core_1.Option)("name", {
|
|
714
|
+
type: "string",
|
|
715
|
+
alias: "n",
|
|
716
|
+
description: "The name of the project"
|
|
717
|
+
})),
|
|
718
|
+
__metadata("design:type", Function),
|
|
719
|
+
__metadata("design:paramtypes", [String, Array]),
|
|
595
720
|
__metadata("design:returntype", Promise)
|
|
596
|
-
], ProjectController.prototype, "
|
|
721
|
+
], ProjectController.prototype, "removeDomain", null);
|
|
597
722
|
__decorate([
|
|
598
|
-
(0, core_1.Command)("
|
|
723
|
+
(0, core_1.Command)("domain:clear"),
|
|
599
724
|
__param(0, (0, core_1.Option)("name", {
|
|
600
725
|
type: "string",
|
|
601
|
-
alias: "n"
|
|
726
|
+
alias: "n",
|
|
727
|
+
description: "The name of the project"
|
|
602
728
|
})),
|
|
603
729
|
__metadata("design:type", Function),
|
|
604
730
|
__metadata("design:paramtypes", [String]),
|
|
605
731
|
__metadata("design:returntype", Promise)
|
|
606
|
-
], ProjectController.prototype, "
|
|
732
|
+
], ProjectController.prototype, "clearDomain", null);
|
|
733
|
+
__decorate([
|
|
734
|
+
(0, core_1.Command)("ports"),
|
|
735
|
+
__param(0, (0, core_1.Option)("name", {
|
|
736
|
+
type: "string",
|
|
737
|
+
alias: "n",
|
|
738
|
+
description: "The name of the project"
|
|
739
|
+
})),
|
|
740
|
+
__metadata("design:type", Function),
|
|
741
|
+
__metadata("design:paramtypes", [String]),
|
|
742
|
+
__metadata("design:returntype", Promise)
|
|
743
|
+
], ProjectController.prototype, "ports", null);
|
|
744
|
+
__decorate([
|
|
745
|
+
(0, core_1.Command)("port:add <host-port>:<container-port>"),
|
|
746
|
+
__param(0, (0, core_1.Param)("host-port")),
|
|
747
|
+
__param(1, (0, core_1.Param)("container-port")),
|
|
748
|
+
__param(2, (0, core_1.Option)("name", {
|
|
749
|
+
type: "string",
|
|
750
|
+
alias: "n",
|
|
751
|
+
description: "The name of the project"
|
|
752
|
+
})),
|
|
753
|
+
__metadata("design:type", Function),
|
|
754
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
755
|
+
__metadata("design:returntype", Promise)
|
|
756
|
+
], ProjectController.prototype, "addPort", null);
|
|
757
|
+
__decorate([
|
|
758
|
+
(0, core_1.Command)("port:remove <host-port>:<container-port>"),
|
|
759
|
+
__param(0, (0, core_1.Param)("host-port")),
|
|
760
|
+
__param(1, (0, core_1.Param)("container-port")),
|
|
761
|
+
__param(2, (0, core_1.Option)("name", {
|
|
762
|
+
type: "string",
|
|
763
|
+
alias: "n",
|
|
764
|
+
description: "The name of the project"
|
|
765
|
+
})),
|
|
766
|
+
__metadata("design:type", Function),
|
|
767
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
768
|
+
__metadata("design:returntype", Promise)
|
|
769
|
+
], ProjectController.prototype, "removePort", null);
|
|
770
|
+
__decorate([
|
|
771
|
+
(0, core_1.Command)("port:clear"),
|
|
772
|
+
__param(0, (0, core_1.Option)("name", {
|
|
773
|
+
type: "string",
|
|
774
|
+
alias: "n",
|
|
775
|
+
description: "The name of the project"
|
|
776
|
+
})),
|
|
777
|
+
__metadata("design:type", Function),
|
|
778
|
+
__metadata("design:paramtypes", [String]),
|
|
779
|
+
__metadata("design:returntype", Promise)
|
|
780
|
+
], ProjectController.prototype, "clearPorts", null);
|
|
607
781
|
__decorate([
|
|
608
782
|
(0, core_1.Command)("config"),
|
|
609
783
|
__param(0, (0, core_1.Option)("name", {
|
|
610
784
|
type: "string",
|
|
611
785
|
alias: "n",
|
|
612
|
-
description: "
|
|
786
|
+
description: "The name of the project"
|
|
613
787
|
})),
|
|
614
788
|
__param(1, (0, core_1.Option)("global", {
|
|
615
789
|
type: "boolean",
|
|
@@ -623,7 +797,8 @@ __decorate([
|
|
|
623
797
|
(0, core_1.Command)("config:get [...key]"),
|
|
624
798
|
__param(0, (0, core_1.Option)("name", {
|
|
625
799
|
type: "string",
|
|
626
|
-
alias: "n"
|
|
800
|
+
alias: "n",
|
|
801
|
+
description: "The name of the project"
|
|
627
802
|
})),
|
|
628
803
|
__param(1, (0, core_1.Option)("global", {
|
|
629
804
|
type: "boolean",
|
|
@@ -638,7 +813,8 @@ __decorate([
|
|
|
638
813
|
(0, core_1.Command)("config:set [...configs]"),
|
|
639
814
|
__param(0, (0, core_1.Option)("name", {
|
|
640
815
|
type: "string",
|
|
641
|
-
alias: "n"
|
|
816
|
+
alias: "n",
|
|
817
|
+
description: "The name of the project"
|
|
642
818
|
})),
|
|
643
819
|
__param(1, (0, core_1.Option)("global", {
|
|
644
820
|
type: "boolean",
|
|
@@ -652,7 +828,8 @@ __decorate([
|
|
|
652
828
|
(0, core_1.Command)("config:unset [...configs]"),
|
|
653
829
|
__param(0, (0, core_1.Option)("name", {
|
|
654
830
|
type: "string",
|
|
655
|
-
alias: "n"
|
|
831
|
+
alias: "n",
|
|
832
|
+
description: "The name of the project"
|
|
656
833
|
})),
|
|
657
834
|
__param(1, (0, core_1.Option)("global", {
|
|
658
835
|
type: "boolean",
|
|
@@ -666,7 +843,8 @@ __decorate([
|
|
|
666
843
|
(0, core_1.Command)("build-args"),
|
|
667
844
|
__param(0, (0, core_1.Option)("name", {
|
|
668
845
|
type: "string",
|
|
669
|
-
alias: "n"
|
|
846
|
+
alias: "n",
|
|
847
|
+
description: "The name of the project"
|
|
670
848
|
})),
|
|
671
849
|
__metadata("design:type", Function),
|
|
672
850
|
__metadata("design:paramtypes", [String]),
|
|
@@ -677,6 +855,7 @@ __decorate([
|
|
|
677
855
|
__param(0, (0, core_1.Option)("name", {
|
|
678
856
|
type: "string",
|
|
679
857
|
alias: "n",
|
|
858
|
+
description: "The name of the project"
|
|
680
859
|
})),
|
|
681
860
|
__metadata("design:type", Function),
|
|
682
861
|
__metadata("design:paramtypes", [String, Array]),
|
|
@@ -686,7 +865,8 @@ __decorate([
|
|
|
686
865
|
(0, core_1.Command)("build-args:set [...buildArgs]"),
|
|
687
866
|
__param(0, (0, core_1.Option)("name", {
|
|
688
867
|
type: "string",
|
|
689
|
-
alias: "n"
|
|
868
|
+
alias: "n",
|
|
869
|
+
description: "The name of the project"
|
|
690
870
|
})),
|
|
691
871
|
__metadata("design:type", Function),
|
|
692
872
|
__metadata("design:paramtypes", [String, Array]),
|
|
@@ -696,7 +876,8 @@ __decorate([
|
|
|
696
876
|
(0, core_1.Command)("build-args:unset [...buildArgs]"),
|
|
697
877
|
__param(0, (0, core_1.Option)("name", {
|
|
698
878
|
type: "string",
|
|
699
|
-
alias: "n"
|
|
879
|
+
alias: "n",
|
|
880
|
+
description: "The name of the project"
|
|
700
881
|
})),
|
|
701
882
|
__metadata("design:type", Function),
|
|
702
883
|
__metadata("design:paramtypes", [String, Array]),
|
|
@@ -706,7 +887,8 @@ __decorate([
|
|
|
706
887
|
(0, core_1.Command)("volumes"),
|
|
707
888
|
__param(0, (0, core_1.Option)("name", {
|
|
708
889
|
type: "string",
|
|
709
|
-
alias: "n"
|
|
890
|
+
alias: "n",
|
|
891
|
+
description: "The name of the project"
|
|
710
892
|
})),
|
|
711
893
|
__metadata("design:type", Function),
|
|
712
894
|
__metadata("design:paramtypes", [String]),
|
|
@@ -716,7 +898,8 @@ __decorate([
|
|
|
716
898
|
(0, core_1.Command)("volume:mount [...volumes]"),
|
|
717
899
|
__param(0, (0, core_1.Option)("name", {
|
|
718
900
|
type: "string",
|
|
719
|
-
alias: "n"
|
|
901
|
+
alias: "n",
|
|
902
|
+
description: "The name of the project"
|
|
720
903
|
})),
|
|
721
904
|
__metadata("design:type", Function),
|
|
722
905
|
__metadata("design:paramtypes", [String, Array]),
|
|
@@ -726,7 +909,8 @@ __decorate([
|
|
|
726
909
|
(0, core_1.Command)("volume:unmount [...volumes]"),
|
|
727
910
|
__param(0, (0, core_1.Option)("name", {
|
|
728
911
|
type: "string",
|
|
729
|
-
alias: "n"
|
|
912
|
+
alias: "n",
|
|
913
|
+
description: "The name of the project"
|
|
730
914
|
})),
|
|
731
915
|
__metadata("design:type", Function),
|
|
732
916
|
__metadata("design:paramtypes", [String, Array]),
|
|
@@ -737,7 +921,7 @@ __decorate([
|
|
|
737
921
|
__param(0, (0, core_1.Option)("name", {
|
|
738
922
|
type: "string",
|
|
739
923
|
alias: "n",
|
|
740
|
-
description: "
|
|
924
|
+
description: "The name of the project"
|
|
741
925
|
})),
|
|
742
926
|
__param(1, (0, core_1.Option)("global", {
|
|
743
927
|
type: "boolean",
|
|
@@ -760,12 +944,36 @@ __decorate([
|
|
|
760
944
|
__param(0, (0, core_1.Option)("name", {
|
|
761
945
|
type: "string",
|
|
762
946
|
alias: "n",
|
|
763
|
-
description: "
|
|
947
|
+
description: "The name of the project"
|
|
764
948
|
})),
|
|
765
949
|
__metadata("design:type", Function),
|
|
766
950
|
__metadata("design:paramtypes", [String, Array]),
|
|
767
951
|
__metadata("design:returntype", Promise)
|
|
768
952
|
], ProjectController.prototype, "exec", null);
|
|
953
|
+
__decorate([
|
|
954
|
+
(0, core_1.Command)("run <script> [...args]"),
|
|
955
|
+
__param(0, (0, core_1.Option)("name", {
|
|
956
|
+
type: "string",
|
|
957
|
+
alias: "n",
|
|
958
|
+
description: "The name of the project"
|
|
959
|
+
})),
|
|
960
|
+
__param(1, (0, core_1.Param)("script")),
|
|
961
|
+
__param(2, (0, core_1.Param)("args")),
|
|
962
|
+
__metadata("design:type", Function),
|
|
963
|
+
__metadata("design:paramtypes", [String, String, Array]),
|
|
964
|
+
__metadata("design:returntype", Promise)
|
|
965
|
+
], ProjectController.prototype, "run", null);
|
|
966
|
+
__decorate([
|
|
967
|
+
(0, core_1.Command)("attach"),
|
|
968
|
+
__param(0, (0, core_1.Option)("name", {
|
|
969
|
+
type: "string",
|
|
970
|
+
alias: "n",
|
|
971
|
+
description: "The name of the project"
|
|
972
|
+
})),
|
|
973
|
+
__metadata("design:type", Function),
|
|
974
|
+
__metadata("design:paramtypes", [String]),
|
|
975
|
+
__metadata("design:returntype", Promise)
|
|
976
|
+
], ProjectController.prototype, "attach", null);
|
|
769
977
|
exports.ProjectController = ProjectController = __decorate([
|
|
770
978
|
(0, core_1.Controller)(),
|
|
771
979
|
__metadata("design:paramtypes", [services_1.AppConfigService,
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { Project } from "@wocker/core";
|
|
2
|
-
import { AppConfigService, AppEventsService, ProjectService,
|
|
2
|
+
import { AppConfigService, AppEventsService, ProjectService, ProxyService } from "../services";
|
|
3
3
|
export declare class ProxyController {
|
|
4
4
|
protected readonly appConfigService: AppConfigService;
|
|
5
5
|
protected readonly appEventsService: AppEventsService;
|
|
6
6
|
protected readonly projectService: ProjectService;
|
|
7
|
-
protected readonly
|
|
7
|
+
protected readonly proxyService: ProxyService;
|
|
8
8
|
protected containerName: string;
|
|
9
|
-
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService,
|
|
9
|
+
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, proxyService: ProxyService);
|
|
10
10
|
onProjectStart(project: Project): Promise<void>;
|
|
11
11
|
onProjectStop(project: Project): Promise<void>;
|
|
12
12
|
getProjectNames(): Promise<string[]>;
|
|
13
|
-
getDomains(name: string | undefined, selected: string[]): Promise<string[]>;
|
|
14
13
|
init(httpPort: number, httpsPort: number): Promise<void>;
|
|
15
|
-
start(): Promise<void>;
|
|
14
|
+
start(restart?: boolean): Promise<void>;
|
|
16
15
|
stop(): Promise<void>;
|
|
17
|
-
restart(): Promise<void>;
|
|
18
|
-
domainList(name: string): Promise<string>;
|
|
19
|
-
setDomains(name: string, domains: string[]): Promise<void>;
|
|
20
|
-
addDomain(name: string, addDomains: string[]): Promise<void>;
|
|
21
|
-
removeDomain(name: string, removeDomains: string[]): Promise<void>;
|
|
22
|
-
clearDomains(name: string): Promise<void>;
|
|
23
16
|
logs(): Promise<void>;
|
|
24
17
|
}
|
|
@@ -18,23 +18,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.ProxyController = void 0;
|
|
19
19
|
const core_1 = require("@wocker/core");
|
|
20
20
|
const utils_1 = require("@wocker/utils");
|
|
21
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
22
21
|
const chalk_1 = __importDefault(require("chalk"));
|
|
23
|
-
const makes_1 = require("../makes");
|
|
24
22
|
const services_1 = require("../services");
|
|
25
23
|
let ProxyController = class ProxyController {
|
|
26
|
-
constructor(appConfigService, appEventsService, projectService,
|
|
24
|
+
constructor(appConfigService, appEventsService, projectService, proxyService) {
|
|
27
25
|
this.appConfigService = appConfigService;
|
|
28
26
|
this.appEventsService = appEventsService;
|
|
29
27
|
this.projectService = projectService;
|
|
30
|
-
this.
|
|
28
|
+
this.proxyService = proxyService;
|
|
31
29
|
this.containerName = "proxy.workspace";
|
|
32
|
-
this.appEventsService.on("project:
|
|
30
|
+
this.appEventsService.on("project:init", (project) => this.proxyService.init(project));
|
|
31
|
+
this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
|
|
33
32
|
this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
|
|
34
33
|
}
|
|
35
34
|
async onProjectStart(project) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
35
|
+
if (project.domains.length === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.info(chalk_1.default.green("Don't forget to add these lines into hosts file:"));
|
|
39
|
+
for (const domain of project.domains) {
|
|
40
|
+
console.info(chalk_1.default.gray(`127.0.0.1 ${domain}`));
|
|
38
41
|
}
|
|
39
42
|
await this.start();
|
|
40
43
|
}
|
|
@@ -44,15 +47,6 @@ let ProxyController = class ProxyController {
|
|
|
44
47
|
const projects = await this.projectService.search();
|
|
45
48
|
return projects.map((project) => project.name);
|
|
46
49
|
}
|
|
47
|
-
async getDomains(name, selected) {
|
|
48
|
-
if (name) {
|
|
49
|
-
await this.projectService.cdProject(name);
|
|
50
|
-
}
|
|
51
|
-
const project = await this.projectService.get();
|
|
52
|
-
return (project.getEnv("VIRTUAL_HOST") || "").split(",").filter((domain) => {
|
|
53
|
-
return !selected.includes(domain);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
50
|
async init(httpPort, httpsPort) {
|
|
57
51
|
const config = await this.appConfigService.getConfig();
|
|
58
52
|
if (typeof httpPort === "undefined" || isNaN(httpPort)) {
|
|
@@ -75,142 +69,15 @@ let ProxyController = class ProxyController {
|
|
|
75
69
|
config.setMeta("PROXY_HTTPS_PORT", httpsPort.toString());
|
|
76
70
|
await config.save();
|
|
77
71
|
}
|
|
78
|
-
async start() {
|
|
79
|
-
|
|
80
|
-
const config = await this.appConfigService.getConfig();
|
|
81
|
-
await this.dockerService.pullImage("nginxproxy/nginx-proxy");
|
|
82
|
-
const httpPort = config.getMeta("PROXY_HTTP_PORT", "80");
|
|
83
|
-
const httpsPort = config.getMeta("PROXY_HTTPS_PORT", "443");
|
|
84
|
-
let container = await this.dockerService.getContainer(this.containerName);
|
|
85
|
-
if (!container) {
|
|
86
|
-
const certsDir = this.appConfigService.dataPath("certs");
|
|
87
|
-
if (!makes_1.FS.existsSync(certsDir)) {
|
|
88
|
-
makes_1.FS.mkdirSync(certsDir, {
|
|
89
|
-
recursive: true
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
container = await this.dockerService.createContainer({
|
|
93
|
-
name: this.containerName,
|
|
94
|
-
image: "nginxproxy/nginx-proxy",
|
|
95
|
-
restart: "always",
|
|
96
|
-
env: {
|
|
97
|
-
DEFAULT_HOST: "index.workspace"
|
|
98
|
-
},
|
|
99
|
-
ports: [
|
|
100
|
-
`${httpPort}:80`,
|
|
101
|
-
`${httpsPort}:443`
|
|
102
|
-
],
|
|
103
|
-
volumes: [
|
|
104
|
-
"/var/run/docker.sock:/tmp/docker.sock:ro",
|
|
105
|
-
`${certsDir}:/etc/nginx/certs`
|
|
106
|
-
]
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const { State: { Status } } = await container.inspect();
|
|
110
|
-
if (["created", "exited"].includes(Status)) {
|
|
111
|
-
console.info("Starting...", Status);
|
|
112
|
-
await container.start();
|
|
113
|
-
}
|
|
72
|
+
async start(restart) {
|
|
73
|
+
await this.proxyService.start(restart);
|
|
114
74
|
}
|
|
115
75
|
async stop() {
|
|
116
76
|
console.info("Proxy stopping...");
|
|
117
|
-
await this.
|
|
118
|
-
}
|
|
119
|
-
async restart() {
|
|
120
|
-
await this.stop();
|
|
121
|
-
await this.start();
|
|
122
|
-
}
|
|
123
|
-
async domainList(name) {
|
|
124
|
-
if (name) {
|
|
125
|
-
await this.projectService.cdProject(name);
|
|
126
|
-
}
|
|
127
|
-
const project = await this.projectService.get();
|
|
128
|
-
const table = new cli_table3_1.default({
|
|
129
|
-
head: [chalk_1.default.yellow("Domain")]
|
|
130
|
-
});
|
|
131
|
-
const domains = project.getEnv("VIRTUAL_HOST", "").split(",");
|
|
132
|
-
for (const domain of domains) {
|
|
133
|
-
table.push([domain]);
|
|
134
|
-
}
|
|
135
|
-
return table.toString() + "\n";
|
|
136
|
-
}
|
|
137
|
-
async setDomains(name, domains) {
|
|
138
|
-
if (name) {
|
|
139
|
-
await this.projectService.cdProject(name);
|
|
140
|
-
}
|
|
141
|
-
const project = await this.projectService.get();
|
|
142
|
-
project.setEnv("VIRTUAL_HOST", domains.join(","));
|
|
143
|
-
await project.save();
|
|
144
|
-
const container = await this.dockerService.getContainer(`${project.name}.workspace`);
|
|
145
|
-
if (container) {
|
|
146
|
-
await this.projectService.stop(project);
|
|
147
|
-
await this.projectService.start(project);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async addDomain(name, addDomains) {
|
|
151
|
-
if (name) {
|
|
152
|
-
await this.projectService.cdProject(name);
|
|
153
|
-
}
|
|
154
|
-
const project = await this.projectService.get();
|
|
155
|
-
let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter((domain) => {
|
|
156
|
-
return !!domain;
|
|
157
|
-
});
|
|
158
|
-
domains = [
|
|
159
|
-
...domains,
|
|
160
|
-
...addDomains.filter((domain) => {
|
|
161
|
-
return !domains.find((existDomain) => {
|
|
162
|
-
return existDomain === domain;
|
|
163
|
-
});
|
|
164
|
-
})
|
|
165
|
-
];
|
|
166
|
-
project.setEnv("VIRTUAL_HOST", domains.join(","));
|
|
167
|
-
await project.save();
|
|
168
|
-
const container = await this.dockerService.getContainer(`${project.name}.workspace`);
|
|
169
|
-
if (container) {
|
|
170
|
-
await this.projectService.stop(project);
|
|
171
|
-
await this.projectService.start(project);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async removeDomain(name, removeDomains) {
|
|
175
|
-
if (name) {
|
|
176
|
-
await this.projectService.cdProject(name);
|
|
177
|
-
}
|
|
178
|
-
const project = await this.projectService.get();
|
|
179
|
-
let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter((domain) => {
|
|
180
|
-
return !!domain;
|
|
181
|
-
});
|
|
182
|
-
domains = domains.filter((domain) => {
|
|
183
|
-
return !removeDomains.includes(domain);
|
|
184
|
-
});
|
|
185
|
-
project.setEnv("VIRTUAL_HOST", domains.join(","));
|
|
186
|
-
await project.save();
|
|
187
|
-
}
|
|
188
|
-
async clearDomains(name) {
|
|
189
|
-
if (name) {
|
|
190
|
-
await this.projectService.cdProject(name);
|
|
191
|
-
}
|
|
192
|
-
const project = await this.projectService.get();
|
|
193
|
-
project.unsetEnv("VIRTUAL_HOST");
|
|
194
|
-
await project.save();
|
|
195
|
-
const container = await this.dockerService.getContainer(`${project.name}.workspace`);
|
|
196
|
-
if (container) {
|
|
197
|
-
await this.projectService.stop(project);
|
|
198
|
-
await this.projectService.start(project);
|
|
199
|
-
}
|
|
77
|
+
await this.proxyService.stop();
|
|
200
78
|
}
|
|
201
79
|
async logs() {
|
|
202
|
-
|
|
203
|
-
if (!container) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const stream = await container.logs({
|
|
207
|
-
follow: true,
|
|
208
|
-
stdout: true,
|
|
209
|
-
stderr: true
|
|
210
|
-
});
|
|
211
|
-
stream.on("data", (data) => {
|
|
212
|
-
process.stdout.write((0, utils_1.demuxOutput)(data));
|
|
213
|
-
});
|
|
80
|
+
await this.proxyService.logs();
|
|
214
81
|
}
|
|
215
82
|
};
|
|
216
83
|
exports.ProxyController = ProxyController;
|
|
@@ -220,12 +87,6 @@ __decorate([
|
|
|
220
87
|
__metadata("design:paramtypes", []),
|
|
221
88
|
__metadata("design:returntype", Promise)
|
|
222
89
|
], ProxyController.prototype, "getProjectNames", null);
|
|
223
|
-
__decorate([
|
|
224
|
-
(0, core_1.Command)("domains"),
|
|
225
|
-
__metadata("design:type", Function),
|
|
226
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
227
|
-
__metadata("design:returntype", Promise)
|
|
228
|
-
], ProxyController.prototype, "getDomains", null);
|
|
229
90
|
__decorate([
|
|
230
91
|
(0, core_1.Command)("proxy:init"),
|
|
231
92
|
__param(0, (0, core_1.Option)("http-port", {
|
|
@@ -242,8 +103,13 @@ __decorate([
|
|
|
242
103
|
], ProxyController.prototype, "init", null);
|
|
243
104
|
__decorate([
|
|
244
105
|
(0, core_1.Command)("proxy:start"),
|
|
106
|
+
__param(0, (0, core_1.Option)("restart", {
|
|
107
|
+
type: "boolean",
|
|
108
|
+
alias: "r",
|
|
109
|
+
description: "Restart"
|
|
110
|
+
})),
|
|
245
111
|
__metadata("design:type", Function),
|
|
246
|
-
__metadata("design:paramtypes", []),
|
|
112
|
+
__metadata("design:paramtypes", [Boolean]),
|
|
247
113
|
__metadata("design:returntype", Promise)
|
|
248
114
|
], ProxyController.prototype, "start", null);
|
|
249
115
|
__decorate([
|
|
@@ -252,67 +118,6 @@ __decorate([
|
|
|
252
118
|
__metadata("design:paramtypes", []),
|
|
253
119
|
__metadata("design:returntype", Promise)
|
|
254
120
|
], ProxyController.prototype, "stop", null);
|
|
255
|
-
__decorate([
|
|
256
|
-
(0, core_1.Command)("proxy:restart"),
|
|
257
|
-
__metadata("design:type", Function),
|
|
258
|
-
__metadata("design:paramtypes", []),
|
|
259
|
-
__metadata("design:returntype", Promise)
|
|
260
|
-
], ProxyController.prototype, "restart", null);
|
|
261
|
-
__decorate([
|
|
262
|
-
(0, core_1.Command)("domains"),
|
|
263
|
-
__param(0, (0, core_1.Option)("name", {
|
|
264
|
-
type: "string",
|
|
265
|
-
alias: "n",
|
|
266
|
-
description: "Project name"
|
|
267
|
-
})),
|
|
268
|
-
__metadata("design:type", Function),
|
|
269
|
-
__metadata("design:paramtypes", [String]),
|
|
270
|
-
__metadata("design:returntype", Promise)
|
|
271
|
-
], ProxyController.prototype, "domainList", null);
|
|
272
|
-
__decorate([
|
|
273
|
-
(0, core_1.Command)("domain:set [...domains]"),
|
|
274
|
-
__param(0, (0, core_1.Option)("name", {
|
|
275
|
-
type: "string",
|
|
276
|
-
alias: "n",
|
|
277
|
-
description: "Project name"
|
|
278
|
-
})),
|
|
279
|
-
__metadata("design:type", Function),
|
|
280
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
281
|
-
__metadata("design:returntype", Promise)
|
|
282
|
-
], ProxyController.prototype, "setDomains", null);
|
|
283
|
-
__decorate([
|
|
284
|
-
(0, core_1.Command)("domain:add [...domains]"),
|
|
285
|
-
__param(0, (0, core_1.Option)("name", {
|
|
286
|
-
type: "string",
|
|
287
|
-
alias: "n",
|
|
288
|
-
description: "Project name"
|
|
289
|
-
})),
|
|
290
|
-
__metadata("design:type", Function),
|
|
291
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
292
|
-
__metadata("design:returntype", Promise)
|
|
293
|
-
], ProxyController.prototype, "addDomain", null);
|
|
294
|
-
__decorate([
|
|
295
|
-
(0, core_1.Command)("domain:remove [...domains]"),
|
|
296
|
-
__param(0, (0, core_1.Option)("name", {
|
|
297
|
-
type: "string",
|
|
298
|
-
alias: "n",
|
|
299
|
-
description: "Project name"
|
|
300
|
-
})),
|
|
301
|
-
__metadata("design:type", Function),
|
|
302
|
-
__metadata("design:paramtypes", [String, Array]),
|
|
303
|
-
__metadata("design:returntype", Promise)
|
|
304
|
-
], ProxyController.prototype, "removeDomain", null);
|
|
305
|
-
__decorate([
|
|
306
|
-
(0, core_1.Command)("domain:clear"),
|
|
307
|
-
__param(0, (0, core_1.Option)("name", {
|
|
308
|
-
type: "string",
|
|
309
|
-
alias: "n",
|
|
310
|
-
description: "Project name"
|
|
311
|
-
})),
|
|
312
|
-
__metadata("design:type", Function),
|
|
313
|
-
__metadata("design:paramtypes", [String]),
|
|
314
|
-
__metadata("design:returntype", Promise)
|
|
315
|
-
], ProxyController.prototype, "clearDomains", null);
|
|
316
121
|
__decorate([
|
|
317
122
|
(0, core_1.Command)("proxy:logs"),
|
|
318
123
|
__metadata("design:type", Function),
|
|
@@ -324,5 +129,5 @@ exports.ProxyController = ProxyController = __decorate([
|
|
|
324
129
|
__metadata("design:paramtypes", [services_1.AppConfigService,
|
|
325
130
|
services_1.AppEventsService,
|
|
326
131
|
services_1.ProjectService,
|
|
327
|
-
services_1.
|
|
132
|
+
services_1.ProxyService])
|
|
328
133
|
], ProxyController);
|
package/lib/env.d.ts
CHANGED
package/lib/env.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.MAP_PATH = exports.DATA_DIR = exports.PLUGINS_DIR = exports.SERVICES_DIR = exports.PRESETS_DIR = exports.ROOT_DIR = exports.NODE_ENV = void 0;
|
|
26
|
+
exports.VIRTUAL_HOST_KEY = exports.MAP_PATH = exports.DATA_DIR = exports.PLUGINS_DIR = exports.SERVICES_DIR = exports.PRESETS_DIR = exports.ROOT_DIR = exports.NODE_ENV = void 0;
|
|
27
27
|
const OS = __importStar(require("os"));
|
|
28
28
|
const Path = __importStar(require("path"));
|
|
29
29
|
exports.NODE_ENV = process.env.NODE_ENV;
|
|
@@ -33,3 +33,4 @@ exports.SERVICES_DIR = Path.join(exports.ROOT_DIR, "services");
|
|
|
33
33
|
exports.PLUGINS_DIR = Path.join(exports.ROOT_DIR, "plugins");
|
|
34
34
|
exports.DATA_DIR = process.env.WS_DIR || Path.join(OS.homedir(), ".workspace");
|
|
35
35
|
exports.MAP_PATH = Path.join(exports.DATA_DIR, "data.json");
|
|
36
|
+
exports.VIRTUAL_HOST_KEY = "VIRTUAL_HOST";
|
|
@@ -13,7 +13,7 @@ export declare class DockerService {
|
|
|
13
13
|
imageRm(tag: string): Promise<void>;
|
|
14
14
|
imageLs(options?: Params.ImageList): Promise<Docker.ImageInfo[]>;
|
|
15
15
|
pullImage(tag: string): Promise<void>;
|
|
16
|
-
attach(
|
|
16
|
+
attach(containerOrName: string | Container): Promise<NodeJS.ReadWriteStream>;
|
|
17
17
|
logs(name: string): Promise<void>;
|
|
18
18
|
attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
|
|
19
19
|
exec(name: string, args?: string[], tty?: boolean): Promise<import("stream").Duplex>;
|
|
@@ -94,7 +94,7 @@ let DockerService = class DockerService {
|
|
|
94
94
|
];
|
|
95
95
|
}
|
|
96
96
|
return res;
|
|
97
|
-
}, {})
|
|
97
|
+
}, {})
|
|
98
98
|
},
|
|
99
99
|
NetworkingConfig: {
|
|
100
100
|
EndpointsConfig: networkMode === "host" ? {} : {
|
|
@@ -173,8 +173,9 @@ let DockerService = class DockerService {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
async imageRm(tag) {
|
|
176
|
-
const image =
|
|
177
|
-
|
|
176
|
+
const image = this.docker.getImage(tag);
|
|
177
|
+
const exists = await this.imageExists(tag);
|
|
178
|
+
if (!exists) {
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
181
|
await image.remove();
|
|
@@ -212,10 +213,16 @@ let DockerService = class DockerService {
|
|
|
212
213
|
const stream = await this.docker.pull(tag);
|
|
213
214
|
await (0, utils_2.followProgress)(stream);
|
|
214
215
|
}
|
|
215
|
-
async attach(
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
|
|
216
|
+
async attach(containerOrName) {
|
|
217
|
+
let container;
|
|
218
|
+
if (typeof containerOrName === "string") {
|
|
219
|
+
container = await this.getContainer(containerOrName);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
if (!containerOrName) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
container = containerOrName;
|
|
219
226
|
}
|
|
220
227
|
const stream = await container.attach({
|
|
221
228
|
logs: true,
|
|
@@ -236,23 +243,21 @@ let DockerService = class DockerService {
|
|
|
236
243
|
}
|
|
237
244
|
});
|
|
238
245
|
stream.on("data", (data) => {
|
|
239
|
-
process.stdout.write(
|
|
246
|
+
process.stdout.write(data);
|
|
240
247
|
});
|
|
241
248
|
stream.on("end", async () => {
|
|
242
249
|
process.exit();
|
|
243
250
|
});
|
|
244
|
-
|
|
251
|
+
const handleResize = () => {
|
|
245
252
|
const [width, height] = process.stdout.getWindowSize();
|
|
246
253
|
container.resize({
|
|
247
254
|
w: width,
|
|
248
255
|
h: height
|
|
249
256
|
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
h: height
|
|
255
|
-
});
|
|
257
|
+
};
|
|
258
|
+
process.stdout.on("resize", handleResize);
|
|
259
|
+
handleResize();
|
|
260
|
+
return stream;
|
|
256
261
|
}
|
|
257
262
|
async logs(name) {
|
|
258
263
|
const container = await this.getContainer(name);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Project,
|
|
1
|
+
import { Project, ProjectProperties } from "@wocker/core";
|
|
2
2
|
import { DockerService, AppConfigService, AppEventsService } from "../services";
|
|
3
3
|
type SearchParams = Partial<{
|
|
4
4
|
id: string;
|
|
@@ -10,13 +10,11 @@ declare class ProjectService {
|
|
|
10
10
|
protected readonly appEventsService: AppEventsService;
|
|
11
11
|
protected readonly dockerService: DockerService;
|
|
12
12
|
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, dockerService: DockerService);
|
|
13
|
-
fromObject(data: Partial<
|
|
13
|
+
fromObject(data: Partial<ProjectProperties>): Project;
|
|
14
14
|
getById(id: string): Promise<Project>;
|
|
15
15
|
cdProject(name: string): Promise<void>;
|
|
16
16
|
get(): Promise<Project>;
|
|
17
|
-
|
|
18
|
-
rebuild(project: Project): Promise<void>;
|
|
19
|
-
start(project: Project, restart?: boolean): Promise<void>;
|
|
17
|
+
start(project: Project, rebuild?: boolean, restart?: boolean): Promise<void>;
|
|
20
18
|
stop(project: Project): Promise<void>;
|
|
21
19
|
save(project: Project): Promise<void>;
|
|
22
20
|
search(params?: Partial<SearchParams>): Promise<Project[]>;
|
|
@@ -44,13 +44,13 @@ let ProjectService = class ProjectService {
|
|
|
44
44
|
this.dockerService = dockerService;
|
|
45
45
|
}
|
|
46
46
|
fromObject(data) {
|
|
47
|
-
const
|
|
47
|
+
const _this = this;
|
|
48
48
|
return new class extends core_1.Project {
|
|
49
49
|
constructor(data) {
|
|
50
50
|
super(data);
|
|
51
51
|
}
|
|
52
52
|
async save() {
|
|
53
|
-
await
|
|
53
|
+
await _this.save(this);
|
|
54
54
|
}
|
|
55
55
|
}(data);
|
|
56
56
|
}
|
|
@@ -76,46 +76,35 @@ let ProjectService = class ProjectService {
|
|
|
76
76
|
}
|
|
77
77
|
return project;
|
|
78
78
|
}
|
|
79
|
-
async
|
|
80
|
-
const project = await this.get();
|
|
81
|
-
return this.dockerService.getContainer(project.containerName);
|
|
82
|
-
}
|
|
83
|
-
async rebuild(project) {
|
|
84
|
-
await this.stop(project);
|
|
85
|
-
if (project.type === "dockerfile") {
|
|
86
|
-
project.imageName = `project-${project.name}:develop`;
|
|
87
|
-
const images = await this.dockerService.imageLs({
|
|
88
|
-
tag: project.imageName
|
|
89
|
-
});
|
|
90
|
-
if (images.length > 0) {
|
|
91
|
-
await this.dockerService.imageRm(project.imageName);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
await this.appEventsService.emit("project:rebuild", project);
|
|
95
|
-
}
|
|
96
|
-
async start(project, restart) {
|
|
97
|
-
if (project.type === "dockerfile") {
|
|
98
|
-
project.imageName = `project-${project.name}:develop`;
|
|
99
|
-
const images = await this.dockerService.imageLs({
|
|
100
|
-
tag: project.imageName
|
|
101
|
-
});
|
|
102
|
-
if (images.length === 0) {
|
|
103
|
-
await this.dockerService.buildImage({
|
|
104
|
-
tag: project.imageName,
|
|
105
|
-
buildArgs: project.buildArgs,
|
|
106
|
-
context: this.appConfigService.getPWD(),
|
|
107
|
-
src: project.dockerfile
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
await this.appEventsService.emit("project:beforeStart", project);
|
|
79
|
+
async start(project, rebuild, restart) {
|
|
112
80
|
let container = await this.dockerService.getContainer(project.containerName);
|
|
113
|
-
if (container && restart) {
|
|
81
|
+
if (container && (restart || rebuild)) {
|
|
114
82
|
container = null;
|
|
115
83
|
await this.appEventsService.emit("project:stop", project);
|
|
116
84
|
await this.dockerService.removeContainer(project.containerName);
|
|
117
85
|
}
|
|
118
86
|
if (!container) {
|
|
87
|
+
await this.appEventsService.emit("project:beforeStart", project);
|
|
88
|
+
if (project.type === "dockerfile") {
|
|
89
|
+
project.imageName = `project-${project.name}:develop`;
|
|
90
|
+
if (rebuild) {
|
|
91
|
+
await this.dockerService.imageRm(project.imageName);
|
|
92
|
+
}
|
|
93
|
+
const images = await this.dockerService.imageLs({
|
|
94
|
+
tag: project.imageName
|
|
95
|
+
});
|
|
96
|
+
if (images.length === 0) {
|
|
97
|
+
await this.dockerService.buildImage({
|
|
98
|
+
tag: project.imageName,
|
|
99
|
+
buildArgs: project.buildArgs,
|
|
100
|
+
context: this.appConfigService.getPWD(),
|
|
101
|
+
src: project.dockerfile
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (rebuild) {
|
|
106
|
+
await this.appEventsService.emit("project:rebuild", project);
|
|
107
|
+
}
|
|
119
108
|
const config = await this.appConfigService.getConfig();
|
|
120
109
|
container = await this.dockerService.createContainer({
|
|
121
110
|
name: project.containerName,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Project } from "@wocker/core";
|
|
2
|
+
import { AppConfigService } from "./AppConfigService";
|
|
3
|
+
import { DockerService } from "./DockerService";
|
|
4
|
+
export declare class ProxyService {
|
|
5
|
+
protected readonly appConfigService: AppConfigService;
|
|
6
|
+
protected readonly dockerService: DockerService;
|
|
7
|
+
protected containerName: string;
|
|
8
|
+
protected imageName: string;
|
|
9
|
+
constructor(appConfigService: AppConfigService, dockerService: DockerService);
|
|
10
|
+
init(project: Project): Promise<void>;
|
|
11
|
+
start(restart?: boolean): Promise<void>;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
logs(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProxyService = void 0;
|
|
13
|
+
const core_1 = require("@wocker/core");
|
|
14
|
+
const utils_1 = require("@wocker/utils");
|
|
15
|
+
const FS_1 = require("../makes/FS");
|
|
16
|
+
const AppConfigService_1 = require("./AppConfigService");
|
|
17
|
+
const DockerService_1 = require("./DockerService");
|
|
18
|
+
let ProxyService = class ProxyService {
|
|
19
|
+
constructor(appConfigService, dockerService) {
|
|
20
|
+
this.appConfigService = appConfigService;
|
|
21
|
+
this.dockerService = dockerService;
|
|
22
|
+
this.containerName = "proxy.workspace";
|
|
23
|
+
this.imageName = "nginxproxy/nginx-proxy";
|
|
24
|
+
}
|
|
25
|
+
async init(project) {
|
|
26
|
+
const enable = await (0, utils_1.promptConfirm)({
|
|
27
|
+
message: "Enable local proxy?",
|
|
28
|
+
default: project.getMeta("WITH_PROXY", "false") === "true"
|
|
29
|
+
});
|
|
30
|
+
if (enable) {
|
|
31
|
+
const appPort = await (0, utils_1.promptText)({
|
|
32
|
+
message: "App port:",
|
|
33
|
+
type: "number",
|
|
34
|
+
default: project.getEnv("VIRTUAL_PORT", "80")
|
|
35
|
+
});
|
|
36
|
+
project.setEnv("VIRTUAL_PORT", appPort);
|
|
37
|
+
project.setMeta("WITH_PROXY", "true");
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
project.setMeta("WITH_PROXY", "false");
|
|
41
|
+
}
|
|
42
|
+
await project.save();
|
|
43
|
+
}
|
|
44
|
+
async start(restart) {
|
|
45
|
+
console.info("Proxy starting...");
|
|
46
|
+
if (restart) {
|
|
47
|
+
await this.stop();
|
|
48
|
+
}
|
|
49
|
+
let container = await this.dockerService.getContainer(this.containerName);
|
|
50
|
+
if (!container) {
|
|
51
|
+
await this.dockerService.pullImage(this.imageName);
|
|
52
|
+
const certsDir = this.appConfigService.dataPath("certs");
|
|
53
|
+
if (!FS_1.FS.existsSync(certsDir)) {
|
|
54
|
+
FS_1.FS.mkdirSync(certsDir, {
|
|
55
|
+
recursive: true,
|
|
56
|
+
mode: 0o700
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const config = await this.appConfigService.getConfig();
|
|
60
|
+
const httpPort = config.getMeta("PROXY_HTTP_PORT", "80");
|
|
61
|
+
const httpsPort = config.getMeta("PROXY_HTTPS_PORT", "443");
|
|
62
|
+
container = await this.dockerService.createContainer({
|
|
63
|
+
name: this.containerName,
|
|
64
|
+
image: this.imageName,
|
|
65
|
+
restart: "always",
|
|
66
|
+
env: {
|
|
67
|
+
DEFAULT_HOST: "index.workspace"
|
|
68
|
+
},
|
|
69
|
+
ports: [
|
|
70
|
+
`${httpPort}:80`,
|
|
71
|
+
`${httpsPort}:443`
|
|
72
|
+
],
|
|
73
|
+
volumes: [
|
|
74
|
+
"/var/run/docker.sock:/tmp/docker.sock:ro",
|
|
75
|
+
`${certsDir}:/etc/nginx/certs`
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
const { State: { Status } } = await container.inspect();
|
|
79
|
+
if (["created", "exited"].includes(Status)) {
|
|
80
|
+
console.info("Starting...");
|
|
81
|
+
await container.start();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async stop() {
|
|
86
|
+
await this.dockerService.removeContainer(this.containerName);
|
|
87
|
+
}
|
|
88
|
+
async logs() {
|
|
89
|
+
await this.dockerService.logs(this.containerName);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.ProxyService = ProxyService;
|
|
93
|
+
exports.ProxyService = ProxyService = __decorate([
|
|
94
|
+
(0, core_1.Injectable)("PROXY_SERVICE"),
|
|
95
|
+
__metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
|
|
96
|
+
DockerService_1.DockerService])
|
|
97
|
+
], ProxyService);
|
package/lib/services/index.d.ts
CHANGED
package/lib/services/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Docker workspace for web projects",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@wocker/core": "^1.0.
|
|
28
|
+
"@wocker/core": "^1.0.12",
|
|
29
29
|
"@wocker/utils": "^1.0.5",
|
|
30
30
|
"async-mutex": "^0.4.0",
|
|
31
31
|
"axios": "^1.6.7",
|