@wocker/ws 1.0.22 → 1.0.24
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.d.ts → RootModule.d.ts} +1 -1
- package/lib/RootModule.js +93 -0
- package/lib/controllers/DebugController.d.ts +1 -1
- package/lib/controllers/DebugController.js +7 -9
- package/lib/controllers/ExperimentalController.d.ts +8 -0
- package/lib/controllers/ExperimentalController.js +76 -0
- package/lib/controllers/PluginController.d.ts +2 -1
- package/lib/controllers/PluginController.js +3 -3
- package/lib/controllers/ProjectController.d.ts +8 -7
- package/lib/controllers/ProjectController.js +123 -240
- package/lib/controllers/index.d.ts +1 -4
- package/lib/controllers/index.js +1 -4
- package/lib/env.d.ts +2 -3
- package/lib/env.js +3 -4
- package/lib/main.js +8 -8
- package/lib/makes/Plugin.d.ts +0 -1
- package/lib/makes/Plugin.js +0 -1
- package/lib/makes/index.d.ts +0 -2
- package/lib/makes/index.js +0 -2
- package/lib/modules/app/index.d.ts +2 -0
- package/lib/modules/app/index.js +32 -0
- package/lib/modules/docker/index.d.ts +8 -0
- package/lib/modules/docker/index.js +41 -0
- package/lib/modules/docker/services/ContainerService.d.ts +14 -0
- package/lib/modules/docker/services/ContainerService.js +115 -0
- package/lib/{services → modules/docker/services}/DockerService.d.ts +12 -5
- package/lib/{services → modules/docker/services}/DockerService.js +27 -114
- package/lib/modules/docker/services/ImageService.d.ts +18 -0
- package/lib/modules/docker/services/ImageService.js +68 -0
- package/lib/modules/docker/services/ModemService.d.ts +15 -0
- package/lib/modules/docker/services/ModemService.js +138 -0
- package/lib/modules/docker/services/ProtoService.d.ts +6 -0
- package/lib/modules/docker/services/ProtoService.js +20 -0
- package/lib/modules/index.d.ts +6 -0
- package/lib/{keystore → modules}/index.js +6 -1
- package/lib/{controllers → modules/keystore/controllers}/KeystoreController.d.ts +2 -2
- package/lib/{controllers → modules/keystore/controllers}/KeystoreController.js +4 -5
- package/lib/modules/keystore/index.d.ts +4 -0
- package/lib/modules/keystore/index.js +29 -0
- package/lib/{keystore → modules/keystore}/providers/FileKeystoreProvider.d.ts +3 -4
- package/lib/{keystore → modules/keystore}/providers/FileKeystoreProvider.js +4 -5
- package/lib/{keystore → modules/keystore}/providers/KeytarKeystoreProvider.js +1 -1
- package/lib/{keystore → modules/keystore/services}/KeystoreService.d.ts +4 -3
- package/lib/{keystore → modules/keystore/services}/KeystoreService.js +9 -6
- package/lib/modules/preset/controllers/PresetController.d.ts +18 -0
- package/lib/modules/preset/controllers/PresetController.js +157 -0
- package/lib/modules/preset/controllers/PresetListener.d.ts +14 -0
- package/lib/modules/preset/controllers/PresetListener.js +140 -0
- package/lib/modules/preset/index.d.ts +5 -0
- package/lib/modules/preset/index.js +39 -0
- package/lib/modules/preset/repositories/PresetRepository.d.ts +16 -0
- package/lib/{repositories → modules/preset/repositories}/PresetRepository.js +9 -11
- package/lib/{services → modules/preset/services}/PresetService.d.ts +4 -12
- package/lib/{services → modules/preset/services}/PresetService.js +22 -27
- package/lib/modules/project/controllers/ProjectController.d.ts +13 -0
- package/lib/modules/project/controllers/ProjectController.js +127 -0
- package/lib/modules/project/index.d.ts +5 -0
- package/lib/modules/project/index.js +39 -0
- package/lib/modules/project/repositories/ProjectRepository.d.ts +13 -0
- package/lib/modules/project/repositories/ProjectRepository.js +90 -0
- package/lib/modules/project/services/ProjectService.d.ts +21 -0
- package/lib/modules/project/services/ProjectService.js +211 -0
- package/lib/{controllers → modules/proxy/controllers}/CertController.d.ts +2 -1
- package/lib/{controllers → modules/proxy/controllers}/CertController.js +4 -3
- package/lib/{controllers → modules/proxy/controllers}/ProxyController.d.ts +5 -4
- package/lib/{controllers → modules/proxy/controllers}/ProxyController.js +12 -11
- package/lib/modules/proxy/index.d.ts +5 -0
- package/lib/modules/proxy/index.js +41 -0
- package/lib/{services → modules/proxy/services}/CertService.d.ts +5 -6
- package/lib/{services → modules/proxy/services}/CertService.js +13 -14
- package/lib/{services → modules/proxy/services}/ProxyService.d.ts +4 -4
- package/lib/{services → modules/proxy/services}/ProxyService.js +27 -20
- package/lib/services/PluginService.d.ts +1 -3
- package/lib/services/PluginService.js +12 -18
- package/lib/utils/followProgress2.d.ts +1 -0
- package/lib/utils/followProgress2.js +63 -0
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +1 -2
- package/package.json +7 -8
- package/proto/buildkit.proto +55 -0
- package/proto/solver/pb/ops.proto +443 -0
- package/lib/AppModule.js +0 -84
- package/lib/controllers/PresetController.d.ts +0 -23
- package/lib/controllers/PresetController.js +0 -361
- package/lib/keystore/index.d.ts +0 -1
- package/lib/keystore/types/Encryption.d.ts +0 -9
- package/lib/keystore/types/Encryption.js +0 -81
- package/lib/keystore/types/Encryptor.d.ts +0 -10
- package/lib/keystore/types/Encryptor.js +0 -59
- package/lib/makes/FS.d.ts +0 -27
- package/lib/makes/FS.js +0 -284
- package/lib/makes/LineConvertStream.d.ts +0 -11
- package/lib/makes/LineConvertStream.js +0 -42
- package/lib/makes/Logger.d.ts +0 -9
- package/lib/makes/Logger.js +0 -34
- package/lib/plugins/MongodbPlugin.d.ts +0 -20
- package/lib/plugins/MongodbPlugin.js +0 -288
- package/lib/plugins/index.d.ts +0 -1
- package/lib/plugins/index.js +0 -17
- package/lib/repositories/PresetRepository.d.ts +0 -23
- package/lib/repositories/index.d.ts +0 -1
- package/lib/repositories/index.js +0 -17
- package/lib/services/AppConfigService.d.ts +0 -35
- package/lib/services/AppConfigService.js +0 -163
- package/lib/services/AppEventsService.d.ts +0 -9
- package/lib/services/AppEventsService.js +0 -43
- package/lib/services/LogService.d.ts +0 -15
- package/lib/services/LogService.js +0 -67
- package/lib/services/ProjectService.d.ts +0 -27
- package/lib/services/ProjectService.js +0 -207
- package/lib/services/index.d.ts +0 -10
- package/lib/services/index.js +0 -26
- package/lib/utils/followProgress.d.ts +0 -1
- package/lib/utils/followProgress.js +0 -73
- package/presets/go/Dockerfile +0 -19
- package/presets/go/config.json +0 -14
- package/presets/php-fpm/Dockerfile +0 -173
- package/presets/php-fpm/bin/compare-version +0 -3
- package/presets/php-fpm/config.json +0 -55
- package/presets/php-fpm/etc/nginx/sites-available/default.conf +0 -36
- /package/lib/{utils/format-size-units.d.ts → modules/docker/utils/formatSizeUnits.d.ts} +0 -0
- /package/lib/{utils/format-size-units.js → modules/docker/utils/formatSizeUnits.js} +0 -0
- /package/lib/{keystore → modules/keystore}/providers/KeytarKeystoreProvider.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/types/FileKeystore.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/types/FileKeystore.js +0 -0
- /package/lib/{keystore → modules/keystore}/types/Keytar.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/types/Keytar.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/createEncryptionKey.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/createEncryptionKey.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/createPasswordHash.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/createPasswordHash.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/decrypt.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/decrypt.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/encrypt.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/encrypt.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/index.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/index.js +0 -0
- /package/lib/{keystore → modules/keystore}/utils/verifyPasswordHash.d.ts +0 -0
- /package/lib/{keystore → modules/keystore}/utils/verifyPasswordHash.js +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
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.ProjectRepository = void 0;
|
|
13
|
+
const core_1 = require("@wocker/core");
|
|
14
|
+
const keystore_1 = require("../../keystore");
|
|
15
|
+
let ProjectRepository = class ProjectRepository {
|
|
16
|
+
constructor(appConfigService, fs, keystoreService) {
|
|
17
|
+
this.appConfigService = appConfigService;
|
|
18
|
+
this.fs = fs;
|
|
19
|
+
this.keystoreService = keystoreService;
|
|
20
|
+
}
|
|
21
|
+
getByName(name) {
|
|
22
|
+
const ref = this.appConfigService.config.getProject(name), config = this.fs.readJSON(`projects/${name}/config.json`);
|
|
23
|
+
return this.fromObject({
|
|
24
|
+
...config,
|
|
25
|
+
path: ref.path
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
fromObject(data) {
|
|
29
|
+
const _this = this;
|
|
30
|
+
return new class extends core_1.Project {
|
|
31
|
+
constructor(data) {
|
|
32
|
+
super(data);
|
|
33
|
+
}
|
|
34
|
+
async getSecret(key, defaultValue) {
|
|
35
|
+
return _this.keystoreService.get(`p:${this.name}:${key}`, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
async setSecret(key, value) {
|
|
38
|
+
return _this.keystoreService.set(`p:${this.name}:${key}`, value);
|
|
39
|
+
}
|
|
40
|
+
save() {
|
|
41
|
+
_this.save(this);
|
|
42
|
+
}
|
|
43
|
+
}(data);
|
|
44
|
+
}
|
|
45
|
+
save(project) {
|
|
46
|
+
if (!project.name) {
|
|
47
|
+
throw new Error("Project should has a name");
|
|
48
|
+
}
|
|
49
|
+
if (!project.path) {
|
|
50
|
+
throw new Error("Project should has a path");
|
|
51
|
+
}
|
|
52
|
+
if (!project.id) {
|
|
53
|
+
project.id = project.name;
|
|
54
|
+
}
|
|
55
|
+
if (!this.fs.exists(`projects/${project.id}`)) {
|
|
56
|
+
this.fs.mkdir(`projects/${project.id}`, {
|
|
57
|
+
recursive: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const { path, ...rest } = project.toObject();
|
|
61
|
+
this.appConfigService.addProject(project.id, project.name, path);
|
|
62
|
+
this.fs.writeJSON(`projects/${project.id}/config.json`, rest);
|
|
63
|
+
this.appConfigService.save();
|
|
64
|
+
}
|
|
65
|
+
search(params = {}) {
|
|
66
|
+
const { name, path } = params, projects = [];
|
|
67
|
+
for (const ref of this.appConfigService.projects) {
|
|
68
|
+
if (name && ref.name !== name) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (path && ref.path !== path) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const project = this.getByName(ref.name);
|
|
75
|
+
projects.push(project);
|
|
76
|
+
}
|
|
77
|
+
return projects;
|
|
78
|
+
}
|
|
79
|
+
searchOne(params = {}) {
|
|
80
|
+
const [project] = this.search(params);
|
|
81
|
+
return project || null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.ProjectRepository = ProjectRepository;
|
|
85
|
+
exports.ProjectRepository = ProjectRepository = __decorate([
|
|
86
|
+
(0, core_1.Injectable)(),
|
|
87
|
+
__metadata("design:paramtypes", [core_1.AppConfigService,
|
|
88
|
+
core_1.AppFileSystemService,
|
|
89
|
+
keystore_1.KeystoreService])
|
|
90
|
+
], ProjectRepository);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Project, AppConfigService, EventService, ProjectService as CoreProjectService, ProjectServiceSearchParams as SearchParams } from "@wocker/core";
|
|
2
|
+
import { ProjectRepository } from "../repositories/ProjectRepository";
|
|
3
|
+
import { DockerService } from "../../docker";
|
|
4
|
+
import { PresetService, PresetRepository } from "../../preset";
|
|
5
|
+
export declare class ProjectService extends CoreProjectService {
|
|
6
|
+
protected readonly appConfigService: AppConfigService;
|
|
7
|
+
protected readonly eventService: EventService;
|
|
8
|
+
protected readonly dockerService: DockerService;
|
|
9
|
+
protected readonly projectRepository: ProjectRepository;
|
|
10
|
+
protected readonly presetService: PresetService;
|
|
11
|
+
protected readonly presetRepository: PresetRepository;
|
|
12
|
+
constructor(appConfigService: AppConfigService, eventService: EventService, dockerService: DockerService, projectRepository: ProjectRepository, presetService: PresetService, presetRepository: PresetRepository);
|
|
13
|
+
get(name?: string): Project;
|
|
14
|
+
search(params?: SearchParams): Project[];
|
|
15
|
+
searchOne(params?: SearchParams): Project | null;
|
|
16
|
+
save(project: Project): void;
|
|
17
|
+
start(project: Project, restart?: boolean, rebuild?: boolean, attach?: boolean): Promise<void>;
|
|
18
|
+
stop(project: Project): Promise<void>;
|
|
19
|
+
build(project: Project, rebuild?: boolean): Promise<void>;
|
|
20
|
+
logs(project: Project, detach?: boolean): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
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.ProjectService = void 0;
|
|
13
|
+
const core_1 = require("@wocker/core");
|
|
14
|
+
const ProjectRepository_1 = require("../repositories/ProjectRepository");
|
|
15
|
+
const docker_1 = require("../../docker");
|
|
16
|
+
const preset_1 = require("../../preset");
|
|
17
|
+
let ProjectService = class ProjectService extends core_1.ProjectService {
|
|
18
|
+
constructor(appConfigService, eventService, dockerService, projectRepository, presetService, presetRepository) {
|
|
19
|
+
super();
|
|
20
|
+
this.appConfigService = appConfigService;
|
|
21
|
+
this.eventService = eventService;
|
|
22
|
+
this.dockerService = dockerService;
|
|
23
|
+
this.projectRepository = projectRepository;
|
|
24
|
+
this.presetService = presetService;
|
|
25
|
+
this.presetRepository = presetRepository;
|
|
26
|
+
}
|
|
27
|
+
get(name) {
|
|
28
|
+
const project = name
|
|
29
|
+
? this.projectRepository.searchOne({ name })
|
|
30
|
+
: this.projectRepository.searchOne({
|
|
31
|
+
path: this.appConfigService.pwd()
|
|
32
|
+
});
|
|
33
|
+
if (!project) {
|
|
34
|
+
throw new Error("Project not found");
|
|
35
|
+
}
|
|
36
|
+
if (name) {
|
|
37
|
+
this.appConfigService.setPWD(project.path);
|
|
38
|
+
}
|
|
39
|
+
return project;
|
|
40
|
+
}
|
|
41
|
+
search(params = {}) {
|
|
42
|
+
return this.projectRepository.search(params);
|
|
43
|
+
}
|
|
44
|
+
searchOne(params = {}) {
|
|
45
|
+
return this.projectRepository.searchOne(params);
|
|
46
|
+
}
|
|
47
|
+
save(project) {
|
|
48
|
+
this.projectRepository.save(project);
|
|
49
|
+
}
|
|
50
|
+
async start(project, restart, rebuild, attach) {
|
|
51
|
+
if (restart || rebuild) {
|
|
52
|
+
await this.stop(project);
|
|
53
|
+
}
|
|
54
|
+
await this.build(project, rebuild);
|
|
55
|
+
await this.eventService.emit("project:beforeStart", project);
|
|
56
|
+
switch (project.type) {
|
|
57
|
+
case core_1.PROJECT_TYPE_IMAGE:
|
|
58
|
+
case core_1.PROJECT_TYPE_DOCKERFILE:
|
|
59
|
+
case core_1.PROJECT_TYPE_PRESET: {
|
|
60
|
+
let container = await this.dockerService.getContainer(project.containerName);
|
|
61
|
+
const fs = new core_1.FileSystem(project.path);
|
|
62
|
+
if (!container) {
|
|
63
|
+
container = await this.dockerService.createContainer({
|
|
64
|
+
name: project.containerName,
|
|
65
|
+
image: project.imageName,
|
|
66
|
+
env: {
|
|
67
|
+
...this.appConfigService.config.env || {},
|
|
68
|
+
...project.env || {}
|
|
69
|
+
},
|
|
70
|
+
ports: project.ports || [],
|
|
71
|
+
volumes: (project.volumes || []).map((volume) => {
|
|
72
|
+
const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
|
|
73
|
+
const [, source, destination, options] = regVolume.exec(volume);
|
|
74
|
+
if (source.startsWith("/")) {
|
|
75
|
+
return volume;
|
|
76
|
+
}
|
|
77
|
+
return `${fs.path(source)}:${destination}` + (options ? `:${options}` : "");
|
|
78
|
+
}),
|
|
79
|
+
extraHosts: Object.keys(project.extraHosts || {}).map((host) => {
|
|
80
|
+
return `${project.extraHosts[host]}:${host}`;
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const { State: { Status } } = await container.inspect();
|
|
85
|
+
if (Status === "created" || Status === "exited") {
|
|
86
|
+
await container.start();
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case core_1.PROJECT_TYPE_COMPOSE: {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await this.eventService.emit("project:start", project);
|
|
95
|
+
await this.eventService.emit("project:afterStart", project);
|
|
96
|
+
if (attach) {
|
|
97
|
+
switch (project.type) {
|
|
98
|
+
case core_1.PROJECT_TYPE_IMAGE:
|
|
99
|
+
case core_1.PROJECT_TYPE_DOCKERFILE:
|
|
100
|
+
case core_1.PROJECT_TYPE_PRESET:
|
|
101
|
+
await this.dockerService.attach(project.containerName);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async stop(project) {
|
|
107
|
+
await this.eventService.emit("project:beforeStop", project);
|
|
108
|
+
switch (project.type) {
|
|
109
|
+
case core_1.PROJECT_TYPE_IMAGE:
|
|
110
|
+
case core_1.PROJECT_TYPE_DOCKERFILE:
|
|
111
|
+
case core_1.PROJECT_TYPE_PRESET:
|
|
112
|
+
await this.dockerService.removeContainer(project.containerName);
|
|
113
|
+
break;
|
|
114
|
+
case core_1.PROJECT_TYPE_COMPOSE:
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
await this.eventService.emit("project:stop", project);
|
|
118
|
+
}
|
|
119
|
+
async build(project, rebuild) {
|
|
120
|
+
switch (project.type) {
|
|
121
|
+
case core_1.PROJECT_TYPE_IMAGE:
|
|
122
|
+
await this.dockerService.pullImage(project.imageName);
|
|
123
|
+
break;
|
|
124
|
+
case core_1.PROJECT_TYPE_DOCKERFILE: {
|
|
125
|
+
project.imageName = `project-${project.name}:develop`;
|
|
126
|
+
project.save();
|
|
127
|
+
if (rebuild) {
|
|
128
|
+
await this.dockerService.imageRm(project.imageName);
|
|
129
|
+
}
|
|
130
|
+
if (!await this.dockerService.imageExists(project.imageName)) {
|
|
131
|
+
await this.dockerService.buildImage({
|
|
132
|
+
tag: project.imageName,
|
|
133
|
+
buildArgs: project.buildArgs,
|
|
134
|
+
context: project.path,
|
|
135
|
+
src: project.dockerfile
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case core_1.PROJECT_TYPE_PRESET: {
|
|
141
|
+
const preset = this.presetRepository.searchOne({
|
|
142
|
+
name: project.preset
|
|
143
|
+
});
|
|
144
|
+
if (preset.image) {
|
|
145
|
+
await this.dockerService.pullImage(preset.image);
|
|
146
|
+
project.imageName = preset.image;
|
|
147
|
+
project.save();
|
|
148
|
+
}
|
|
149
|
+
if (preset.dockerfile) {
|
|
150
|
+
project.imageName = this.presetService.getImageNameForProject(project, preset);
|
|
151
|
+
project.save();
|
|
152
|
+
if (rebuild) {
|
|
153
|
+
await this.dockerService.imageRm(project.imageName);
|
|
154
|
+
}
|
|
155
|
+
if (!await this.dockerService.imageExists(project.imageName)) {
|
|
156
|
+
await this.dockerService.buildImage({
|
|
157
|
+
tag: project.imageName,
|
|
158
|
+
labels: {
|
|
159
|
+
"org.wocker.preset": preset.name
|
|
160
|
+
},
|
|
161
|
+
buildArgs: project.buildArgs,
|
|
162
|
+
context: preset.path,
|
|
163
|
+
src: preset.dockerfile
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case core_1.PROJECT_TYPE_COMPOSE: {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
await this.eventService.emit("project:build", project, rebuild);
|
|
174
|
+
}
|
|
175
|
+
async logs(project, detach) {
|
|
176
|
+
switch (project.type) {
|
|
177
|
+
case core_1.PROJECT_TYPE_IMAGE:
|
|
178
|
+
case core_1.PROJECT_TYPE_DOCKERFILE:
|
|
179
|
+
case core_1.PROJECT_TYPE_PRESET: {
|
|
180
|
+
const container = await this.dockerService.getContainer(project.containerName);
|
|
181
|
+
if (!container) {
|
|
182
|
+
throw new Error("Project not started");
|
|
183
|
+
}
|
|
184
|
+
if (!detach) {
|
|
185
|
+
await this.dockerService.logs(container);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const data = await container.logs({
|
|
189
|
+
stdout: true,
|
|
190
|
+
stderr: true,
|
|
191
|
+
follow: false
|
|
192
|
+
});
|
|
193
|
+
process.stdout.write(data);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case core_1.PROJECT_TYPE_COMPOSE:
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
exports.ProjectService = ProjectService;
|
|
203
|
+
exports.ProjectService = ProjectService = __decorate([
|
|
204
|
+
(0, core_1.Injectable)("PROJECT_SERVICE"),
|
|
205
|
+
__metadata("design:paramtypes", [core_1.AppConfigService,
|
|
206
|
+
core_1.EventService,
|
|
207
|
+
docker_1.DockerService,
|
|
208
|
+
ProjectRepository_1.ProjectRepository,
|
|
209
|
+
preset_1.PresetService,
|
|
210
|
+
preset_1.PresetRepository])
|
|
211
|
+
], ProjectService);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CertService } from "../services/CertService";
|
|
2
|
+
import { ProjectService } from "../../project";
|
|
2
3
|
export declare class CertController {
|
|
3
4
|
protected readonly projectService: ProjectService;
|
|
4
5
|
protected readonly certService: CertService;
|
|
@@ -14,7 +14,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CertController = void 0;
|
|
16
16
|
const core_1 = require("@wocker/core");
|
|
17
|
-
const
|
|
17
|
+
const CertService_1 = require("../services/CertService");
|
|
18
|
+
const project_1 = require("../../project");
|
|
18
19
|
let CertController = class CertController {
|
|
19
20
|
constructor(projectService, certService) {
|
|
20
21
|
this.projectService = projectService;
|
|
@@ -108,6 +109,6 @@ __decorate([
|
|
|
108
109
|
], CertController.prototype, "existsOtherNames", null);
|
|
109
110
|
exports.CertController = CertController = __decorate([
|
|
110
111
|
(0, core_1.Controller)(),
|
|
111
|
-
__metadata("design:paramtypes", [
|
|
112
|
-
|
|
112
|
+
__metadata("design:paramtypes", [project_1.ProjectService,
|
|
113
|
+
CertService_1.CertService])
|
|
113
114
|
], CertController);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Project } from "@wocker/core";
|
|
2
|
-
import {
|
|
1
|
+
import { Project, AppConfigService, EventService } from "@wocker/core";
|
|
2
|
+
import { ProjectService } from "../../project";
|
|
3
|
+
import { ProxyService } from "../services/ProxyService";
|
|
3
4
|
export declare class ProxyController {
|
|
4
5
|
protected readonly appConfigService: AppConfigService;
|
|
5
|
-
protected readonly
|
|
6
|
+
protected readonly eventService: EventService;
|
|
6
7
|
protected readonly projectService: ProjectService;
|
|
7
8
|
protected readonly proxyService: ProxyService;
|
|
8
9
|
protected containerName: string;
|
|
9
|
-
constructor(appConfigService: AppConfigService,
|
|
10
|
+
constructor(appConfigService: AppConfigService, eventService: EventService, projectService: ProjectService, proxyService: ProxyService);
|
|
10
11
|
onProjectStart(project: Project): Promise<void>;
|
|
11
12
|
onProjectStop(project: Project): Promise<void>;
|
|
12
13
|
getProjectNames(): string[];
|
|
@@ -19,17 +19,18 @@ exports.ProxyController = void 0;
|
|
|
19
19
|
const core_1 = require("@wocker/core");
|
|
20
20
|
const utils_1 = require("@wocker/utils");
|
|
21
21
|
const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
|
|
22
|
-
const
|
|
22
|
+
const project_1 = require("../../project");
|
|
23
|
+
const ProxyService_1 = require("../services/ProxyService");
|
|
23
24
|
let ProxyController = class ProxyController {
|
|
24
|
-
constructor(appConfigService,
|
|
25
|
+
constructor(appConfigService, eventService, projectService, proxyService) {
|
|
25
26
|
this.appConfigService = appConfigService;
|
|
26
|
-
this.
|
|
27
|
+
this.eventService = eventService;
|
|
27
28
|
this.projectService = projectService;
|
|
28
29
|
this.proxyService = proxyService;
|
|
29
30
|
this.containerName = "proxy.workspace";
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
31
|
+
this.eventService.on("project:init", (project) => this.proxyService.init(project));
|
|
32
|
+
this.eventService.on("project:start", (project) => this.onProjectStart(project));
|
|
33
|
+
this.eventService.on("project:stop", (project) => this.onProjectStop(project));
|
|
33
34
|
}
|
|
34
35
|
async onProjectStart(project) {
|
|
35
36
|
if (project.domains.length === 0) {
|
|
@@ -96,7 +97,7 @@ let ProxyController = class ProxyController {
|
|
|
96
97
|
config.unsetMeta("PROXY_SSH_PASSWORD");
|
|
97
98
|
config.unsetMeta("PROXY_SSH_PORT");
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
this.appConfigService.save();
|
|
100
101
|
}
|
|
101
102
|
async start(restart, rebuild) {
|
|
102
103
|
await this.proxyService.start(restart, rebuild);
|
|
@@ -173,8 +174,8 @@ __decorate([
|
|
|
173
174
|
exports.ProxyController = ProxyController = __decorate([
|
|
174
175
|
(0, core_1.Controller)(),
|
|
175
176
|
(0, core_1.Description)("Proxy commands"),
|
|
176
|
-
__metadata("design:paramtypes", [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
__metadata("design:paramtypes", [core_1.AppConfigService,
|
|
178
|
+
core_1.EventService,
|
|
179
|
+
project_1.ProjectService,
|
|
180
|
+
ProxyService_1.ProxyService])
|
|
180
181
|
], ProxyController);
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CertService = exports.ProxyService = exports.ProxyModule = void 0;
|
|
10
|
+
const core_1 = require("@wocker/core");
|
|
11
|
+
const docker_1 = require("../docker");
|
|
12
|
+
const project_1 = require("../project");
|
|
13
|
+
const CertController_1 = require("./controllers/CertController");
|
|
14
|
+
const ProxyController_1 = require("./controllers/ProxyController");
|
|
15
|
+
const CertService_1 = require("./services/CertService");
|
|
16
|
+
Object.defineProperty(exports, "CertService", { enumerable: true, get: function () { return CertService_1.CertService; } });
|
|
17
|
+
const ProxyService_1 = require("./services/ProxyService");
|
|
18
|
+
Object.defineProperty(exports, "ProxyService", { enumerable: true, get: function () { return ProxyService_1.ProxyService; } });
|
|
19
|
+
let ProxyModule = class ProxyModule {
|
|
20
|
+
};
|
|
21
|
+
exports.ProxyModule = ProxyModule;
|
|
22
|
+
exports.ProxyModule = ProxyModule = __decorate([
|
|
23
|
+
(0, core_1.Module)({
|
|
24
|
+
imports: [
|
|
25
|
+
docker_1.DockerModule,
|
|
26
|
+
project_1.ProjectModule
|
|
27
|
+
],
|
|
28
|
+
controllers: [
|
|
29
|
+
CertController_1.CertController,
|
|
30
|
+
ProxyController_1.ProxyController
|
|
31
|
+
],
|
|
32
|
+
providers: [
|
|
33
|
+
ProxyService_1.ProxyService,
|
|
34
|
+
CertService_1.CertService
|
|
35
|
+
],
|
|
36
|
+
exports: [
|
|
37
|
+
ProxyService_1.ProxyService,
|
|
38
|
+
CertService_1.CertService
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
], ProxyModule);
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { Project } from "@wocker/core";
|
|
2
|
-
import {
|
|
3
|
-
import { DockerService } from "./DockerService";
|
|
1
|
+
import { Project, AppFileSystemService } from "@wocker/core";
|
|
2
|
+
import { DockerService } from "../../docker";
|
|
4
3
|
import { ProxyService } from "./ProxyService";
|
|
5
4
|
type CertMap = {
|
|
6
5
|
[name: string]: string[];
|
|
7
6
|
};
|
|
8
7
|
export declare class CertService {
|
|
9
|
-
protected readonly
|
|
8
|
+
protected readonly fs: AppFileSystemService;
|
|
10
9
|
protected readonly proxyService: ProxyService;
|
|
11
10
|
protected readonly dockerService: DockerService;
|
|
12
|
-
constructor(
|
|
11
|
+
constructor(fs: AppFileSystemService, proxyService: ProxyService, dockerService: DockerService);
|
|
13
12
|
list(): Promise<string>;
|
|
14
13
|
generate(certName: string, dns: string[]): Promise<void>;
|
|
15
|
-
getCertsMap():
|
|
14
|
+
getCertsMap(): CertMap;
|
|
16
15
|
use(project: Project, name: string): Promise<void>;
|
|
17
16
|
remove(project: Project): Promise<void>;
|
|
18
17
|
delete(name: string): Promise<void>;
|
|
@@ -49,12 +49,11 @@ exports.CertService = void 0;
|
|
|
49
49
|
const core_1 = require("@wocker/core");
|
|
50
50
|
const Path = __importStar(require("path"));
|
|
51
51
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
52
|
-
const
|
|
53
|
-
const DockerService_1 = require("./DockerService");
|
|
52
|
+
const docker_1 = require("../../docker");
|
|
54
53
|
const ProxyService_1 = require("./ProxyService");
|
|
55
54
|
let CertService = class CertService {
|
|
56
|
-
constructor(
|
|
57
|
-
this.
|
|
55
|
+
constructor(fs, proxyService, dockerService) {
|
|
56
|
+
this.fs = fs;
|
|
58
57
|
this.proxyService = proxyService;
|
|
59
58
|
this.dockerService = dockerService;
|
|
60
59
|
}
|
|
@@ -62,7 +61,7 @@ let CertService = class CertService {
|
|
|
62
61
|
const table = new cli_table3_1.default({
|
|
63
62
|
head: ["Name"]
|
|
64
63
|
});
|
|
65
|
-
const certMap =
|
|
64
|
+
const certMap = this.getCertsMap();
|
|
66
65
|
for (const name in certMap) {
|
|
67
66
|
table.push([name]);
|
|
68
67
|
}
|
|
@@ -93,8 +92,8 @@ let CertService = class CertService {
|
|
|
93
92
|
cmd: ["wocker-create-cert", certName]
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
const files = this.
|
|
95
|
+
getCertsMap() {
|
|
96
|
+
const files = this.fs.readdir("certs/projects");
|
|
98
97
|
return files.reduce((res, file) => {
|
|
99
98
|
const ext = Path.extname(file);
|
|
100
99
|
const name = Path.basename(file, ext);
|
|
@@ -106,7 +105,7 @@ let CertService = class CertService {
|
|
|
106
105
|
}, {});
|
|
107
106
|
}
|
|
108
107
|
async use(project, name) {
|
|
109
|
-
const certs =
|
|
108
|
+
const certs = this.getCertsMap();
|
|
110
109
|
if (!name) {
|
|
111
110
|
name = project.domains.find((domain) => domain in certs);
|
|
112
111
|
}
|
|
@@ -121,23 +120,23 @@ let CertService = class CertService {
|
|
|
121
120
|
throw new Error(`${name}.key file missing`);
|
|
122
121
|
}
|
|
123
122
|
project.setEnv("CERT_NAME", name);
|
|
124
|
-
|
|
123
|
+
project.save();
|
|
125
124
|
}
|
|
126
125
|
async remove(project) {
|
|
127
126
|
if (!project.hasEnv("CERT_NAME")) {
|
|
128
127
|
return;
|
|
129
128
|
}
|
|
130
129
|
project.unsetEnv("CERT_NAME");
|
|
131
|
-
|
|
130
|
+
project.save();
|
|
132
131
|
}
|
|
133
132
|
async delete(name) {
|
|
134
|
-
const certs =
|
|
133
|
+
const certs = this.getCertsMap();
|
|
135
134
|
if (!(name in certs)) {
|
|
136
135
|
console.warn(`Cert ${name} not found`);
|
|
137
136
|
return;
|
|
138
137
|
}
|
|
139
138
|
for (const ext of certs[name]) {
|
|
140
|
-
this.
|
|
139
|
+
this.fs.rm(`certs/projects/${name}${ext}`);
|
|
141
140
|
}
|
|
142
141
|
console.info(`Cert ${name} deleted`);
|
|
143
142
|
}
|
|
@@ -145,7 +144,7 @@ let CertService = class CertService {
|
|
|
145
144
|
exports.CertService = CertService;
|
|
146
145
|
exports.CertService = CertService = __decorate([
|
|
147
146
|
(0, core_1.Injectable)(),
|
|
148
|
-
__metadata("design:paramtypes", [
|
|
147
|
+
__metadata("design:paramtypes", [core_1.AppFileSystemService,
|
|
149
148
|
ProxyService_1.ProxyService,
|
|
150
|
-
|
|
149
|
+
docker_1.DockerService])
|
|
151
150
|
], CertService);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Project, ProxyService as CoreProxyService } from "@wocker/core";
|
|
2
|
-
import {
|
|
3
|
-
import { DockerService } from "./DockerService";
|
|
1
|
+
import { Project, AppConfigService, AppFileSystemService, ProxyService as CoreProxyService } from "@wocker/core";
|
|
2
|
+
import { DockerService } from "../../docker";
|
|
4
3
|
export declare class ProxyService extends CoreProxyService {
|
|
5
4
|
protected readonly appConfigService: AppConfigService;
|
|
5
|
+
protected readonly fs: AppFileSystemService;
|
|
6
6
|
protected readonly dockerService: DockerService;
|
|
7
7
|
protected containerName: string;
|
|
8
8
|
protected imageName: string;
|
|
9
9
|
protected oldImages: string[];
|
|
10
|
-
constructor(appConfigService: AppConfigService, dockerService: DockerService);
|
|
10
|
+
constructor(appConfigService: AppConfigService, fs: AppFileSystemService, dockerService: DockerService);
|
|
11
11
|
init(project: Project): Promise<void>;
|
|
12
12
|
start(restart?: boolean, rebuild?: boolean): Promise<void>;
|
|
13
13
|
stop(): Promise<void>;
|