@wocker/ws 1.0.14 → 1.0.16
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 +3 -3
- package/lib/controllers/DebugController.d.ts +3 -0
- package/lib/controllers/DebugController.js +43 -1
- package/lib/controllers/PresetController.d.ts +3 -1
- package/lib/controllers/PresetController.js +42 -7
- package/lib/controllers/ProjectController.d.ts +2 -1
- package/lib/controllers/ProjectController.js +17 -13
- package/lib/controllers/ProxyController.d.ts +1 -1
- package/lib/controllers/ProxyController.js +4 -4
- package/lib/env.d.ts +0 -1
- package/lib/env.js +1 -2
- package/lib/plugins/index.d.ts +0 -1
- package/lib/plugins/index.js +0 -1
- package/lib/services/AppConfigService.d.ts +6 -6
- package/lib/services/AppConfigService.js +42 -27
- package/lib/services/LogService.d.ts +3 -1
- package/lib/services/LogService.js +9 -1
- package/lib/services/PluginService.js +1 -1
- package/lib/services/PresetService.d.ts +12 -3
- package/lib/services/PresetService.js +256 -20
- package/lib/services/ProjectService.d.ts +2 -3
- package/lib/services/ProjectService.js +32 -26
- package/lib/services/ProxyService.js +10 -20
- package/package.json +5 -3
- package/presets/bun/config.json +1 -0
- package/presets/go/config.json +1 -0
- package/presets/php-fpm/config.json +1 -0
- package/presets/shopify/config.json +2 -0
- package/lib/plugins/PageKitePlugin.d.ts +0 -30
- package/lib/plugins/PageKitePlugin.js +0 -145
- package/plugins/pagekite/Dockerfile +0 -3
- package/presets/node/Dockerfile +0 -39
- package/presets/node/config.json +0 -39
- package/presets/php-apache/Dockerfile +0 -227
- package/presets/php-apache/bin/compare-version +0 -3
- package/presets/php-apache/config.json +0 -64
- package/presets/php-apache/etc/apache2/apache2.conf +0 -230
- package/presets/php-apache/etc/apache2/mods-available/mpm_prefork.conf +0 -16
- package/presets/php-apache/etc/apache2/sites-available/000-default.conf +0 -21
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
21
|
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
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
8
31
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
33
|
};
|
|
@@ -14,11 +37,82 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
exports.PresetService = void 0;
|
|
16
39
|
const core_1 = require("@wocker/core");
|
|
40
|
+
const utils_1 = require("@wocker/utils");
|
|
17
41
|
const md5_1 = __importDefault(require("md5"));
|
|
42
|
+
const axios_1 = __importDefault(require("axios"));
|
|
43
|
+
const unzipper_1 = require("unzipper");
|
|
44
|
+
const Path = __importStar(require("path"));
|
|
45
|
+
const AppConfigService_1 = require("./AppConfigService");
|
|
46
|
+
const LogService_1 = require("./LogService");
|
|
18
47
|
const env_1 = require("../env");
|
|
19
48
|
const makes_1 = require("../makes");
|
|
20
49
|
let PresetService = class PresetService {
|
|
21
|
-
constructor() {
|
|
50
|
+
constructor(appConfigService, logService) {
|
|
51
|
+
this.appConfigService = appConfigService;
|
|
52
|
+
this.logService = logService;
|
|
53
|
+
}
|
|
54
|
+
toObject(config) {
|
|
55
|
+
const _this = this;
|
|
56
|
+
return new class extends core_1.Preset {
|
|
57
|
+
constructor(data) {
|
|
58
|
+
super(data);
|
|
59
|
+
}
|
|
60
|
+
async save() {
|
|
61
|
+
const { source, path, ...rest } = this.toJSON();
|
|
62
|
+
const config = _this.appConfigService.getConfig();
|
|
63
|
+
let presetData = config.presets.find((presetData) => {
|
|
64
|
+
return presetData.name === this.name;
|
|
65
|
+
});
|
|
66
|
+
switch (this.source) {
|
|
67
|
+
case core_1.PRESET_SOURCE_EXTERNAL:
|
|
68
|
+
const fs = new core_1.FileSystem(this.path);
|
|
69
|
+
await fs.writeJSON("config.json", rest);
|
|
70
|
+
break;
|
|
71
|
+
case core_1.PRESET_SOURCE_GITHUB: {
|
|
72
|
+
const fs = new core_1.FileSystem(_this.appConfigService.dataPath("presets", this.name));
|
|
73
|
+
if (!fs.exists()) {
|
|
74
|
+
fs.mkdir("");
|
|
75
|
+
}
|
|
76
|
+
await fs.writeJSON("config.json", rest);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!presetData) {
|
|
81
|
+
config.registerPreset(this.name, source, path);
|
|
82
|
+
await config.save();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async delete() {
|
|
86
|
+
if (this.source === core_1.PRESET_SOURCE_GITHUB) {
|
|
87
|
+
const config = _this.appConfigService.getConfig();
|
|
88
|
+
await makes_1.FS.rm(_this.appConfigService.dataPath("presets", this.name), {
|
|
89
|
+
recursive: true
|
|
90
|
+
});
|
|
91
|
+
config.unregisterPreset(this.name);
|
|
92
|
+
await config.save();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}(config);
|
|
96
|
+
}
|
|
97
|
+
async getList() {
|
|
98
|
+
const dirs = await makes_1.FS.readdir(env_1.PRESETS_DIR);
|
|
99
|
+
const { presets } = this.appConfigService.getConfig();
|
|
100
|
+
return [
|
|
101
|
+
...dirs.map((name) => {
|
|
102
|
+
return {
|
|
103
|
+
name,
|
|
104
|
+
source: core_1.PRESET_SOURCE_INTERNAL,
|
|
105
|
+
path: Path.join(env_1.PRESETS_DIR, name)
|
|
106
|
+
};
|
|
107
|
+
}),
|
|
108
|
+
...presets.map((item) => {
|
|
109
|
+
if (item.source === core_1.PRESET_SOURCE_GITHUB) {
|
|
110
|
+
item.path = this.appConfigService.dataPath("presets", item.name);
|
|
111
|
+
}
|
|
112
|
+
return item;
|
|
113
|
+
})
|
|
114
|
+
];
|
|
115
|
+
}
|
|
22
116
|
getImageName(preset, buildArgs = {}) {
|
|
23
117
|
const rawValues = [];
|
|
24
118
|
const hashValues = [];
|
|
@@ -34,38 +128,179 @@ let PresetService = class PresetService {
|
|
|
34
128
|
});
|
|
35
129
|
const version = [
|
|
36
130
|
...rawValues,
|
|
37
|
-
(0, md5_1.default)(hashValues.join(",")).
|
|
131
|
+
(0, md5_1.default)(hashValues.join(",")).substring(0, 6)
|
|
38
132
|
].filter((value) => {
|
|
39
133
|
return !!value;
|
|
40
134
|
}).join("-");
|
|
41
135
|
return `ws-preset-${preset.name}:${version}`;
|
|
42
136
|
}
|
|
43
|
-
async
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
137
|
+
async init() {
|
|
138
|
+
let preset = await this.searchOne({
|
|
139
|
+
path: this.appConfigService.pwd()
|
|
140
|
+
});
|
|
141
|
+
if (preset) {
|
|
142
|
+
throw new Error("Preset is already registered");
|
|
143
|
+
}
|
|
144
|
+
const fs = new core_1.FileSystem(this.appConfigService.pwd());
|
|
145
|
+
if (!fs.exists("config.json")) {
|
|
146
|
+
preset = this.toObject({
|
|
147
|
+
name: fs.basename(),
|
|
148
|
+
version: "1.0.0",
|
|
149
|
+
source: "external",
|
|
150
|
+
path: this.appConfigService.pwd()
|
|
151
|
+
});
|
|
152
|
+
const list = await this.getList();
|
|
153
|
+
preset.name = await (0, utils_1.promptText)({
|
|
154
|
+
message: "Preset name:",
|
|
155
|
+
required: true,
|
|
156
|
+
validate: async (value) => {
|
|
157
|
+
if (!/^[a-z][a-z0-9-_]+$/.test(value || "")) {
|
|
158
|
+
return "Invalid name";
|
|
159
|
+
}
|
|
160
|
+
const presetData = list.find((presetData) => {
|
|
161
|
+
return presetData.name === value;
|
|
162
|
+
});
|
|
163
|
+
if (presetData) {
|
|
164
|
+
return "Preset name is already taken";
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
},
|
|
168
|
+
default: preset.name
|
|
169
|
+
});
|
|
170
|
+
preset.version = await (0, utils_1.promptText)({
|
|
171
|
+
message: "Preset version:",
|
|
172
|
+
validate: (version) => {
|
|
173
|
+
if (!/^[0-9]+\.[0.9]+\.[0-9]+$/.test(version)) {
|
|
174
|
+
return "Invalid version";
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
},
|
|
178
|
+
default: preset.version
|
|
179
|
+
});
|
|
180
|
+
preset.type = await (0, utils_1.promptSelect)({
|
|
181
|
+
message: "Preset type:",
|
|
182
|
+
options: ["dockerfile", "image"]
|
|
183
|
+
});
|
|
184
|
+
switch (preset.type) {
|
|
185
|
+
case "dockerfile":
|
|
186
|
+
const files = await fs.readdirFiles();
|
|
187
|
+
const dockerfiles = files.filter((fileName) => {
|
|
188
|
+
if (new RegExp("^(.*)\\.dockerfile$").test(fileName)) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return new RegExp("^Dockerfile(\\..*)?").test(fileName);
|
|
192
|
+
});
|
|
193
|
+
if (dockerfiles.length === 0) {
|
|
194
|
+
throw new Error("No dockerfiles found");
|
|
195
|
+
}
|
|
196
|
+
preset.dockerfile = await (0, utils_1.promptSelect)({
|
|
197
|
+
message: "Preset dockerfile:",
|
|
198
|
+
options: dockerfiles
|
|
199
|
+
});
|
|
200
|
+
break;
|
|
201
|
+
case "image":
|
|
202
|
+
preset.image = await (0, utils_1.promptText)({
|
|
203
|
+
message: "Preset image:",
|
|
204
|
+
required: true,
|
|
205
|
+
validate(value) {
|
|
206
|
+
if (!/^[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[a-z0-9]+(?:[._-][a-z0-9]+)*)?$/.test(value)) {
|
|
207
|
+
return "Invalid image name";
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
break;
|
|
51
213
|
}
|
|
52
|
-
|
|
214
|
+
console.info(JSON.stringify(preset.toJSON(), null, 4));
|
|
215
|
+
const confirm = await (0, utils_1.promptConfirm)({
|
|
216
|
+
message: "Correct?"
|
|
217
|
+
});
|
|
218
|
+
if (confirm) {
|
|
219
|
+
await preset.save();
|
|
53
220
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async get(name) {
|
|
224
|
+
const list = await this.getList();
|
|
225
|
+
const item = list.find((item) => {
|
|
226
|
+
return item.name === name;
|
|
227
|
+
});
|
|
228
|
+
if (!item) {
|
|
229
|
+
throw new Error(`Preset ${name} not found`);
|
|
230
|
+
}
|
|
231
|
+
const config = await makes_1.FS.readJSON(item.path, "config.json");
|
|
232
|
+
return this.toObject({
|
|
233
|
+
...item,
|
|
56
234
|
...config
|
|
57
235
|
});
|
|
58
236
|
}
|
|
237
|
+
async addPreset(name) {
|
|
238
|
+
let preset = await this.searchOne({
|
|
239
|
+
name
|
|
240
|
+
});
|
|
241
|
+
if (!preset) {
|
|
242
|
+
console.info("Loading...");
|
|
243
|
+
const res = await makes_1.Http.get("https://raw.githubusercontent.com")
|
|
244
|
+
.withHeader("User-Agent", "Wocker")
|
|
245
|
+
.send(`/kearisp/wocker-${name}-preset/master/config.json`);
|
|
246
|
+
preset = this.toObject(res.data);
|
|
247
|
+
preset.source = core_1.PRESET_SOURCE_GITHUB;
|
|
248
|
+
preset.path = this.appConfigService.dataPath("presets", preset.name);
|
|
249
|
+
const zipRes = await axios_1.default.create({
|
|
250
|
+
baseURL: "https://github.com",
|
|
251
|
+
headers: {
|
|
252
|
+
"User-Agent": "Wocker"
|
|
253
|
+
}
|
|
254
|
+
}).get(`/kearisp/wocker-${preset.name}-preset/archive/refs/heads/master.zip`, {
|
|
255
|
+
responseType: "stream"
|
|
256
|
+
});
|
|
257
|
+
makes_1.FS.mkdirSync(preset.path, {
|
|
258
|
+
recursive: true
|
|
259
|
+
});
|
|
260
|
+
zipRes.data.pipe((0, unzipper_1.Parse)()).on("entry", (entry) => {
|
|
261
|
+
const path = entry.path.replace(/^[^\/]+\//, "");
|
|
262
|
+
if (path === "config.json") {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const fullPath = this.appConfigService.dataPath("presets", preset.name, path);
|
|
266
|
+
if (entry.type === "File") {
|
|
267
|
+
entry.pipe(makes_1.FS.createWriteStream(fullPath));
|
|
268
|
+
}
|
|
269
|
+
else if (entry.type === "Directory") {
|
|
270
|
+
makes_1.FS.mkdirSync(fullPath, {
|
|
271
|
+
recursive: true
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
await preset.save();
|
|
276
|
+
}
|
|
277
|
+
console.log(preset.version);
|
|
278
|
+
}
|
|
59
279
|
async search(options = {}) {
|
|
60
|
-
const { name } = options;
|
|
280
|
+
const { name, source, path } = options;
|
|
61
281
|
const presets = [];
|
|
62
|
-
const
|
|
63
|
-
for (const
|
|
64
|
-
if (name && name !==
|
|
282
|
+
const presetConfigs = await this.getList();
|
|
283
|
+
for (const presetConfig of presetConfigs) {
|
|
284
|
+
if (name && name !== presetConfig.name) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (source && source !== presetConfig.source) {
|
|
65
288
|
continue;
|
|
66
289
|
}
|
|
67
|
-
|
|
68
|
-
|
|
290
|
+
if (path && path !== presetConfig.path) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const fullConfig = await makes_1.FS.readJSON(presetConfig.path, "config.json");
|
|
295
|
+
const preset = this.toObject({
|
|
296
|
+
...presetConfig,
|
|
297
|
+
...fullConfig
|
|
298
|
+
});
|
|
299
|
+
presets.push(preset);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
this.logService.error("PresetService.search(", options, ") ->", err.message);
|
|
303
|
+
}
|
|
69
304
|
}
|
|
70
305
|
return presets;
|
|
71
306
|
}
|
|
@@ -77,5 +312,6 @@ let PresetService = class PresetService {
|
|
|
77
312
|
exports.PresetService = PresetService;
|
|
78
313
|
exports.PresetService = PresetService = __decorate([
|
|
79
314
|
(0, core_1.Injectable)(),
|
|
80
|
-
__metadata("design:paramtypes", [
|
|
315
|
+
__metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
|
|
316
|
+
LogService_1.LogService])
|
|
81
317
|
], PresetService);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Project, ProjectProperties } from "@wocker/core";
|
|
2
2
|
import { DockerService, AppConfigService, AppEventsService } from "../services";
|
|
3
3
|
type SearchParams = Partial<{
|
|
4
|
-
id: string;
|
|
5
4
|
name: string;
|
|
6
5
|
path: string;
|
|
7
6
|
}>;
|
|
@@ -11,10 +10,10 @@ declare class ProjectService {
|
|
|
11
10
|
protected readonly dockerService: DockerService;
|
|
12
11
|
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, dockerService: DockerService);
|
|
13
12
|
fromObject(data: Partial<ProjectProperties>): Project;
|
|
13
|
+
get(): Promise<Project>;
|
|
14
14
|
getById(id: string): Promise<Project>;
|
|
15
15
|
cdProject(name: string): Promise<void>;
|
|
16
|
-
|
|
17
|
-
start(project: Project, rebuild?: boolean, restart?: boolean): Promise<void>;
|
|
16
|
+
start(project: Project, restart?: boolean, rebuild?: boolean): Promise<void>;
|
|
18
17
|
stop(project: Project): Promise<void>;
|
|
19
18
|
save(project: Project): Promise<void>;
|
|
20
19
|
search(params?: Partial<SearchParams>): Promise<Project[]>;
|
|
@@ -54,29 +54,34 @@ let ProjectService = class ProjectService {
|
|
|
54
54
|
}
|
|
55
55
|
}(data);
|
|
56
56
|
}
|
|
57
|
-
async
|
|
58
|
-
const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
|
|
59
|
-
return this.fromObject(data);
|
|
60
|
-
}
|
|
61
|
-
async cdProject(name) {
|
|
57
|
+
async get() {
|
|
62
58
|
const project = await this.searchOne({
|
|
63
|
-
|
|
59
|
+
path: this.appConfigService.pwd()
|
|
64
60
|
});
|
|
65
61
|
if (!project) {
|
|
66
62
|
throw new Error("Project not found");
|
|
67
63
|
}
|
|
68
|
-
|
|
64
|
+
return project;
|
|
69
65
|
}
|
|
70
|
-
async
|
|
66
|
+
async getById(id) {
|
|
67
|
+
const config = this.appConfigService.getConfig();
|
|
68
|
+
const projectData = config.getProject(id);
|
|
69
|
+
const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
|
|
70
|
+
return this.fromObject({
|
|
71
|
+
...data,
|
|
72
|
+
path: projectData.path || projectData.src
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async cdProject(name) {
|
|
71
76
|
const project = await this.searchOne({
|
|
72
|
-
|
|
77
|
+
name
|
|
73
78
|
});
|
|
74
79
|
if (!project) {
|
|
75
80
|
throw new Error("Project not found");
|
|
76
81
|
}
|
|
77
|
-
|
|
82
|
+
this.appConfigService.setPWD(project.path);
|
|
78
83
|
}
|
|
79
|
-
async start(project,
|
|
84
|
+
async start(project, restart, rebuild) {
|
|
80
85
|
let container = await this.dockerService.getContainer(project.containerName);
|
|
81
86
|
if (container && (restart || rebuild)) {
|
|
82
87
|
container = null;
|
|
@@ -84,8 +89,7 @@ let ProjectService = class ProjectService {
|
|
|
84
89
|
await this.dockerService.removeContainer(project.containerName);
|
|
85
90
|
}
|
|
86
91
|
if (!container) {
|
|
87
|
-
|
|
88
|
-
if (project.type === "dockerfile") {
|
|
92
|
+
if (project.type === core_1.PROJECT_TYPE_DOCKERFILE) {
|
|
89
93
|
project.imageName = `project-${project.name}:develop`;
|
|
90
94
|
if (rebuild) {
|
|
91
95
|
await this.dockerService.imageRm(project.imageName);
|
|
@@ -97,7 +101,7 @@ let ProjectService = class ProjectService {
|
|
|
97
101
|
await this.dockerService.buildImage({
|
|
98
102
|
tag: project.imageName,
|
|
99
103
|
buildArgs: project.buildArgs,
|
|
100
|
-
context: this.appConfigService.
|
|
104
|
+
context: this.appConfigService.pwd(),
|
|
101
105
|
src: project.dockerfile
|
|
102
106
|
});
|
|
103
107
|
}
|
|
@@ -105,6 +109,7 @@ let ProjectService = class ProjectService {
|
|
|
105
109
|
if (rebuild) {
|
|
106
110
|
await this.appEventsService.emit("project:rebuild", project);
|
|
107
111
|
}
|
|
112
|
+
await this.appEventsService.emit("project:beforeStart", project);
|
|
108
113
|
const config = await this.appConfigService.getConfig();
|
|
109
114
|
container = await this.dockerService.createContainer({
|
|
110
115
|
name: project.containerName,
|
|
@@ -116,7 +121,10 @@ let ProjectService = class ProjectService {
|
|
|
116
121
|
volumes: (project.volumes || []).map((volume) => {
|
|
117
122
|
const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
|
|
118
123
|
const [, source, destination, options] = regVolume.exec(volume);
|
|
119
|
-
|
|
124
|
+
if (source.startsWith("/")) {
|
|
125
|
+
return volume;
|
|
126
|
+
}
|
|
127
|
+
return `${Path.join(this.appConfigService.pwd(), source)}:${destination}` + (options ? `:${options}` : "");
|
|
120
128
|
}),
|
|
121
129
|
ports: project.ports || []
|
|
122
130
|
});
|
|
@@ -145,27 +153,25 @@ let ProjectService = class ProjectService {
|
|
|
145
153
|
if (!project.id) {
|
|
146
154
|
project.id = project.name;
|
|
147
155
|
}
|
|
148
|
-
const projectDirPath = this.appConfigService.dataPath("projects", project.id);
|
|
149
156
|
const config = await this.appConfigService.getConfig();
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
152
|
-
|
|
153
|
-
recursive: true
|
|
154
|
-
});
|
|
157
|
+
const fs = new core_1.FileSystem(this.appConfigService.dataPath("projects", project.id));
|
|
158
|
+
if (!fs.exists()) {
|
|
159
|
+
fs.mkdir("", { recursive: true });
|
|
155
160
|
}
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
const { path, ...rest } = project.toJSON();
|
|
162
|
+
config.addProject(project.id, project.name, path);
|
|
163
|
+
await fs.writeJSON("config.json", rest);
|
|
158
164
|
await config.save();
|
|
159
165
|
}
|
|
160
166
|
async search(params = {}) {
|
|
161
|
-
const {
|
|
167
|
+
const { name, path } = params;
|
|
162
168
|
const config = await this.appConfigService.getConfig();
|
|
163
169
|
const projects = [];
|
|
164
170
|
for (const projectConfig of config.projects) {
|
|
165
|
-
if (
|
|
171
|
+
if (name && projectConfig.name !== name) {
|
|
166
172
|
continue;
|
|
167
173
|
}
|
|
168
|
-
if (path && projectConfig.src !== path) {
|
|
174
|
+
if (path && (projectConfig.path || projectConfig.src) !== path) {
|
|
169
175
|
continue;
|
|
170
176
|
}
|
|
171
177
|
const project = await this.getById(projectConfig.id);
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ProxyService = void 0;
|
|
13
13
|
const core_1 = require("@wocker/core");
|
|
14
14
|
const utils_1 = require("@wocker/utils");
|
|
15
|
-
const
|
|
15
|
+
const makes_1 = require("../makes");
|
|
16
16
|
const AppConfigService_1 = require("./AppConfigService");
|
|
17
17
|
const DockerService_1 = require("./DockerService");
|
|
18
18
|
let ProxyService = class ProxyService {
|
|
@@ -23,35 +23,25 @@ let ProxyService = class ProxyService {
|
|
|
23
23
|
this.imageName = "nginxproxy/nginx-proxy";
|
|
24
24
|
}
|
|
25
25
|
async init(project) {
|
|
26
|
-
const
|
|
27
|
-
message: "
|
|
28
|
-
|
|
26
|
+
const appPort = await (0, utils_1.promptText)({
|
|
27
|
+
message: "App port:",
|
|
28
|
+
type: "number",
|
|
29
|
+
default: project.getEnv("VIRTUAL_PORT", "80")
|
|
29
30
|
});
|
|
30
|
-
|
|
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
|
-
}
|
|
31
|
+
project.setEnv("VIRTUAL_PORT", appPort);
|
|
42
32
|
await project.save();
|
|
43
33
|
}
|
|
44
34
|
async start(restart) {
|
|
45
|
-
console.info("Proxy starting...");
|
|
46
35
|
if (restart) {
|
|
47
36
|
await this.stop();
|
|
48
37
|
}
|
|
49
38
|
let container = await this.dockerService.getContainer(this.containerName);
|
|
50
39
|
if (!container) {
|
|
40
|
+
console.info("Proxy starting...");
|
|
51
41
|
await this.dockerService.pullImage(this.imageName);
|
|
52
42
|
const certsDir = this.appConfigService.dataPath("certs");
|
|
53
|
-
if (!
|
|
54
|
-
|
|
43
|
+
if (!makes_1.FS.existsSync(certsDir)) {
|
|
44
|
+
makes_1.FS.mkdirSync(certsDir, {
|
|
55
45
|
recursive: true,
|
|
56
46
|
mode: 0o700
|
|
57
47
|
});
|
|
@@ -77,8 +67,8 @@ let ProxyService = class ProxyService {
|
|
|
77
67
|
});
|
|
78
68
|
const { State: { Status } } = await container.inspect();
|
|
79
69
|
if (["created", "exited"].includes(Status)) {
|
|
80
|
-
console.info("Starting...");
|
|
81
70
|
await container.start();
|
|
71
|
+
console.info("Started");
|
|
82
72
|
}
|
|
83
73
|
}
|
|
84
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/ws",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
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": "
|
|
28
|
+
"@wocker/core": "1.0.16",
|
|
29
29
|
"@wocker/utils": "^1.0.5",
|
|
30
30
|
"async-mutex": "^0.4.0",
|
|
31
31
|
"axios": "^1.6.7",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"md5": "^2.3.0",
|
|
39
39
|
"os": "^0.1.2",
|
|
40
40
|
"path": "^0.12.7",
|
|
41
|
-
"readable-stream": "^4.1.0"
|
|
41
|
+
"readable-stream": "^4.1.0",
|
|
42
|
+
"unzipper": "^0.12.3"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/dockerode": "3.3.23",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"@types/mute-stream": "^0.0.1",
|
|
49
50
|
"@types/node": "^20.11.16",
|
|
50
51
|
"@types/readable-stream": "^2.3.15",
|
|
52
|
+
"@types/unzipper": "^0.10.10",
|
|
51
53
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
52
54
|
"@typescript-eslint/parser": "^6.5.0",
|
|
53
55
|
"eslint": "^8.48.0",
|
package/presets/bun/config.json
CHANGED
package/presets/go/config.json
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Project } from "@wocker/core";
|
|
2
|
-
import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
|
|
3
|
-
type InitOptions = {};
|
|
4
|
-
type StartOptions = {
|
|
5
|
-
name?: string;
|
|
6
|
-
detach?: boolean;
|
|
7
|
-
restart?: boolean;
|
|
8
|
-
rebuild?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type StopOptions = {
|
|
11
|
-
name?: string;
|
|
12
|
-
};
|
|
13
|
-
type BuildOptions = {
|
|
14
|
-
rebuild?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export declare class PageKitePlugin {
|
|
17
|
-
protected readonly appConfigService: AppConfigService;
|
|
18
|
-
protected readonly appEventsService: AppEventsService;
|
|
19
|
-
protected readonly projectService: ProjectService;
|
|
20
|
-
protected readonly dockerService: DockerService;
|
|
21
|
-
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
|
|
22
|
-
pluginPath(...parts: string[]): string;
|
|
23
|
-
onProjectStart(project: Project): Promise<void>;
|
|
24
|
-
onProjectStop(project: Project): Promise<void>;
|
|
25
|
-
init(options: InitOptions): Promise<void>;
|
|
26
|
-
start(options: StartOptions): Promise<void>;
|
|
27
|
-
stop(options: StopOptions): Promise<void>;
|
|
28
|
-
build(options?: BuildOptions): Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
export {};
|