testeranto 0.205.0 → 0.206.0
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/Dockerfile.mothership +14 -4
- package/Dockerfile.node +5 -3
- package/bundle.js +5 -4
- package/dist/common/src/app/backend/PM_0.js +3 -0
- package/dist/common/src/app/backend/PM_1_WithProcesses.js +2 -0
- package/dist/common/src/app/backend/PM_2_WithTCP.js +2 -0
- package/dist/common/src/app/backend/PM_WithHelpo.js +1 -0
- package/dist/common/src/app/backend/main.js +27 -26
- package/dist/common/src/app/frontend/useFs.js +2 -1
- package/dist/common/src/mothership/mothership.js +197 -0
- package/dist/common/src/testeranto.js +31 -42
- package/dist/common/tsconfig.common.tsbuildinfo +1 -1
- package/dist/module/src/app/backend/PM_0.js +3 -0
- package/dist/module/src/app/backend/PM_1_WithProcesses.js +2 -0
- package/dist/module/src/app/backend/PM_2_WithTCP.js +2 -0
- package/dist/module/src/app/backend/PM_WithHelpo.js +1 -0
- package/dist/module/src/app/backend/main.js +27 -26
- package/dist/module/src/app/frontend/useFs.js +2 -1
- package/dist/module/src/mothership/mothership.js +196 -0
- package/dist/module/src/testeranto.js +31 -42
- package/dist/module/tsconfig.module.tsbuildinfo +1 -1
- package/dist/prebuild/App.css +68 -12
- package/dist/prebuild/App.js +8 -91
- package/dist/prebuild/mothership.mjs +4 -0
- package/dist/types/src/app/backend/PM_1_WithProcesses.d.ts +0 -1
- package/dist/types/src/app/backend/PM_WithBuild.d.ts +0 -1
- package/dist/types/src/app/backend/main.d.ts +1 -0
- package/dist/types/src/app/frontend/useFs.d.ts +1 -1
- package/dist/types/src/mothership/mothership.d.ts +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docker-compose.yml +54 -54
- package/package.json +8 -3
- package/src/app/backend/PM_0.ts +3 -0
- package/src/app/backend/PM_1_WithProcesses.ts +4 -2
- package/src/app/backend/PM_2_WithTCP.ts +3 -0
- package/src/app/backend/PM_WithBuild.ts +0 -2
- package/src/app/backend/PM_WithHelpo.ts +1 -1
- package/src/app/backend/main.ts +26 -8
- package/src/app/frontend/useFs.ts +2 -1
- package/src/mothership/mothership.ts +218 -0
- package/src/testeranto.ts +47 -45
- package/dist/common/src/mothership/index.js +0 -183
- package/dist/module/src/mothership/index.js +0 -178
- package/dist/prebuild/esbuildConfigs/eslint-formatter-testeranto.mjs +0 -22
- package/dist/prebuild/init-docs.mjs +0 -43
- package/dist/prebuild/testeranto.mjs +0 -5352
- package/dist/types/src/mothership/index.d.ts +0 -2
- package/src/mothership/index.ts +0 -216
package/docker-compose.yml
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
version:
|
|
1
|
+
version: "3.8"
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
|
-
mothership:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
# mothership:
|
|
5
|
+
# build:
|
|
6
|
+
# context: .
|
|
7
|
+
# dockerfile: Dockerfile.mothership
|
|
8
|
+
# ports:
|
|
9
|
+
# - "8080:8080"
|
|
10
|
+
# environment:
|
|
11
|
+
# - NODE_ENV=development
|
|
12
|
+
# volumes:
|
|
13
|
+
# - .:/workspace
|
|
14
|
+
# - /var/run/docker.sock:/var/run/docker.sock
|
|
15
|
+
# working_dir: /workspace
|
|
16
|
+
# # command: npm run mothership
|
|
17
17
|
|
|
18
18
|
node-build:
|
|
19
19
|
build:
|
|
@@ -23,51 +23,51 @@ services:
|
|
|
23
23
|
- .:/workspace
|
|
24
24
|
- node_modules:/workspace/node_modules
|
|
25
25
|
working_dir: /workspace
|
|
26
|
-
command: tail -f /dev/null
|
|
26
|
+
# command: tail -f /dev/null
|
|
27
27
|
environment:
|
|
28
28
|
- NODE_ENV=development
|
|
29
|
-
depends_on:
|
|
30
|
-
|
|
29
|
+
# depends_on:
|
|
30
|
+
# - mothership
|
|
31
31
|
|
|
32
|
-
web-build:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
# web-build:
|
|
33
|
+
# build:
|
|
34
|
+
# context: .
|
|
35
|
+
# dockerfile: Dockerfile.web
|
|
36
|
+
# volumes:
|
|
37
|
+
# - .:/workspace
|
|
38
|
+
# - web_build_node_modules:/workspace/node_modules
|
|
39
|
+
# working_dir: /workspace
|
|
40
|
+
# command: tail -f /dev/null
|
|
41
|
+
# environment:
|
|
42
|
+
# - NODE_ENV=development
|
|
43
|
+
# depends_on:
|
|
44
|
+
# - mothership
|
|
45
45
|
|
|
46
|
-
golang-build:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
# golang-build:
|
|
47
|
+
# build:
|
|
48
|
+
# context: .
|
|
49
|
+
# dockerfile: Dockerfile.golang
|
|
50
|
+
# volumes:
|
|
51
|
+
# - .:/workspace
|
|
52
|
+
# working_dir: /workspace
|
|
53
|
+
# command: tail -f /dev/null
|
|
54
|
+
# environment:
|
|
55
|
+
# - GOPATH=/workspace
|
|
56
|
+
# depends_on:
|
|
57
|
+
# - mothership
|
|
58
58
|
|
|
59
|
-
python-build:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
# python-build:
|
|
60
|
+
# build:
|
|
61
|
+
# context: .
|
|
62
|
+
# dockerfile: Dockerfile.python
|
|
63
|
+
# volumes:
|
|
64
|
+
# - .:/workspace
|
|
65
|
+
# working_dir: /workspace
|
|
66
|
+
# command: tail -f /dev/null
|
|
67
|
+
# environment:
|
|
68
|
+
# - PYTHONPATH=/workspace
|
|
69
|
+
# depends_on:
|
|
70
|
+
# - mothership
|
|
71
71
|
|
|
72
72
|
volumes:
|
|
73
73
|
node_modules:
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testeranto",
|
|
3
3
|
"description": "the AI powered BDD test framework for typescript projects",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.206.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "18.18.0"
|
|
7
7
|
},
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "adam wong <adamwong246@gmail.com>",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"mothership": "
|
|
16
|
+
"mothership": "node dist/prebuild/mothership/index.mjs",
|
|
17
17
|
"build-hard": "rm -rf testeranto/** && yarn build && yarn type-check; yarn t-init; cp dist/prebuild/App.* testeranto; yarn t-build core once; yarn t-run core once",
|
|
18
18
|
"build": "sh prebuild.sh; cp ./src/cjs-shim.js ./dist/cjs-shim.js; tsc -p tsconfig.module.json; tsc -p tsconfig.common.json; tsc -p tsconfig.types.json; sh postBuild.sh; yarn bundle",
|
|
19
19
|
"build3": "yarn bundle",
|
|
@@ -84,6 +84,10 @@
|
|
|
84
84
|
"import": "./src/WebSidecar.ts",
|
|
85
85
|
"require": "./src/WebSidecar.ts"
|
|
86
86
|
},
|
|
87
|
+
"./src/CoreTypes": {
|
|
88
|
+
"import": "./src/CoreTypes.ts",
|
|
89
|
+
"require": "./src/CoreTypes.ts"
|
|
90
|
+
},
|
|
87
91
|
"./src/Types": {
|
|
88
92
|
"import": "./src/Types.ts",
|
|
89
93
|
"require": "./src/Types.ts"
|
|
@@ -189,6 +193,7 @@
|
|
|
189
193
|
"@jest/globals": "^30.0.4",
|
|
190
194
|
"@monaco-editor/react": "^4.7.0",
|
|
191
195
|
"@types/chokidar": "^2.1.7",
|
|
196
|
+
"@types/dockerode": "3.3.40",
|
|
192
197
|
"@types/eslint": "^9.6.1",
|
|
193
198
|
"@types/fabric": "^5.3.10",
|
|
194
199
|
"@types/file-saver": "^2.0.7",
|
|
@@ -207,7 +212,7 @@
|
|
|
207
212
|
"chai": "^5.2.0",
|
|
208
213
|
"chokidar": "^4.0.3",
|
|
209
214
|
"chromium": "^3.0.3",
|
|
210
|
-
"
|
|
215
|
+
"dockerode": "^4.0.9",
|
|
211
216
|
"dynamic-base": "^1.1.2",
|
|
212
217
|
"esbuild": "^0.20.1",
|
|
213
218
|
"esbuild-plugin-external-package": "^1.0.0",
|
package/src/app/backend/PM_0.ts
CHANGED
|
@@ -31,7 +31,10 @@ export abstract class PM_0 {
|
|
|
31
31
|
projectName: string;
|
|
32
32
|
|
|
33
33
|
constructor(configs: IBuiltConfig, projectName: string, mode: IMode) {
|
|
34
|
+
console.log("mark6", configs);
|
|
35
|
+
console.log("mark7", this.configs);
|
|
34
36
|
this.configs = configs;
|
|
37
|
+
console.log("mark8", this.configs);
|
|
35
38
|
this.mode = mode;
|
|
36
39
|
this.projectName = projectName;
|
|
37
40
|
}
|
|
@@ -39,8 +39,6 @@ export abstract class PM_1_WithProcesses extends PM_0 {
|
|
|
39
39
|
logStreams: Record<string, ReturnType<typeof createLogStreams>> = {};
|
|
40
40
|
launchers: Record<string, () => void>;
|
|
41
41
|
|
|
42
|
-
configs: any;
|
|
43
|
-
|
|
44
42
|
abstract launchNode(src: string, dest: string);
|
|
45
43
|
abstract launchWeb(src: string, dest: string);
|
|
46
44
|
abstract launchPure(src: string, dest: string);
|
|
@@ -98,6 +96,10 @@ export abstract class PM_1_WithProcesses extends PM_0 {
|
|
|
98
96
|
constructor(configs: IBuiltConfig, name, mode) {
|
|
99
97
|
super(configs, name, mode);
|
|
100
98
|
|
|
99
|
+
console.log("mark5", configs);
|
|
100
|
+
|
|
101
|
+
console.log("mark1", this.configs);
|
|
102
|
+
|
|
101
103
|
this.configs.tests.forEach(([t, rt, tr, sidecars]) => {
|
|
102
104
|
this.ensureSummaryEntry(t);
|
|
103
105
|
sidecars.forEach(([sidecarName]) => {
|
|
@@ -18,6 +18,9 @@ export abstract class PM_2_WithTCP extends PM_1_WithProcesses {
|
|
|
18
18
|
constructor(configs: any, name: string, mode: string) {
|
|
19
19
|
super(configs, name, mode);
|
|
20
20
|
|
|
21
|
+
console.log("mark2", this.configs);
|
|
22
|
+
console.log("mark3", configs);
|
|
23
|
+
|
|
21
24
|
this.httpServer = http.createServer(this.handleHttpRequest.bind(this));
|
|
22
25
|
this.wss = new WebSocketServer({ server: this.httpServer });
|
|
23
26
|
|
|
@@ -6,8 +6,6 @@ import { IBuiltConfig } from "../../Types.js";
|
|
|
6
6
|
import { PM_2_WithTCP } from "./PM_2_WithTCP.js";
|
|
7
7
|
|
|
8
8
|
export abstract class PM_WithBuild extends PM_2_WithTCP {
|
|
9
|
-
configs: IBuiltConfig;
|
|
10
|
-
|
|
11
9
|
currentBuildResolve: (() => void) | null = null;
|
|
12
10
|
currentBuildReject: ((error: any) => void) | null = null;
|
|
13
11
|
|
|
@@ -27,7 +27,7 @@ import { spawnSync, ChildProcess } from "node:child_process";
|
|
|
27
27
|
// @ts-ignore: node-pty is a CommonJS module
|
|
28
28
|
import fs from "fs";
|
|
29
29
|
import path from "path";
|
|
30
|
-
import { PM_1 } from "./PM_1_WithProcesses.js";
|
|
30
|
+
// import { PM_1 } from "./PM_1_WithProcesses.js";
|
|
31
31
|
import { PM_WithGit } from "./PM_WithGit.js";
|
|
32
32
|
|
|
33
33
|
interface ChatMessage {
|
package/src/app/backend/main.ts
CHANGED
|
@@ -31,6 +31,10 @@ const files: Record<string, Set<string>> = {};
|
|
|
31
31
|
const screenshots: Record<string, Promise<Uint8Array>[]> = {};
|
|
32
32
|
|
|
33
33
|
export class PM_Main extends PM_WithHelpo {
|
|
34
|
+
constructor(configs: any, name: string, mode: string) {
|
|
35
|
+
super(configs, name, mode);
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
async startBuildProcesses(): Promise<void> {
|
|
35
39
|
const { nodeEntryPoints, webEntryPoints, pureEntryPoints } = getRunnables(
|
|
36
40
|
this.configs.tests,
|
|
@@ -513,11 +517,18 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
513
517
|
|
|
514
518
|
const logs = createLogStreams(reportDest, "web");
|
|
515
519
|
|
|
520
|
+
logs.info?.write("testing123");
|
|
521
|
+
logs.info?.write("wtf");
|
|
522
|
+
|
|
516
523
|
return new Promise<void>((resolve, reject) => {
|
|
517
524
|
this.browser
|
|
518
525
|
.newPage()
|
|
526
|
+
|
|
519
527
|
.then((page) => {
|
|
528
|
+
// page.on("")
|
|
520
529
|
page.on("console", (log: ConsoleMessage) => {
|
|
530
|
+
console.log("mark9", log);
|
|
531
|
+
|
|
521
532
|
const msg = `${log.text()}\n`;
|
|
522
533
|
|
|
523
534
|
switch (log.type()) {
|
|
@@ -539,6 +550,7 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
539
550
|
});
|
|
540
551
|
|
|
541
552
|
page.on("close", () => {
|
|
553
|
+
logs.info?.write("close 1");
|
|
542
554
|
logs.writeExitCode(0);
|
|
543
555
|
logs.closeAll();
|
|
544
556
|
});
|
|
@@ -561,6 +573,8 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
561
573
|
})
|
|
562
574
|
.then(async (page) => {
|
|
563
575
|
const close = () => {
|
|
576
|
+
logs.info?.write("close2");
|
|
577
|
+
|
|
564
578
|
if (!files[src]) {
|
|
565
579
|
files[src] = new Set();
|
|
566
580
|
}
|
|
@@ -574,14 +588,15 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
574
588
|
};
|
|
575
589
|
|
|
576
590
|
page.on("pageerror", (err: Error) => {
|
|
577
|
-
logs.
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
)
|
|
583
|
-
|
|
584
|
-
|
|
591
|
+
logs.info?.write("pageerror");
|
|
592
|
+
// logs.writeExitCode(-1, err);
|
|
593
|
+
// console.log(
|
|
594
|
+
// ansiColors.red(
|
|
595
|
+
// `web ! ${src} failed to execute No "tests.json" file was generated. Check ${reportDest}/error.log for more info`
|
|
596
|
+
// )
|
|
597
|
+
// );
|
|
598
|
+
// this.bddTestIsNowDone(src, -1);
|
|
599
|
+
// close();
|
|
585
600
|
reject(err);
|
|
586
601
|
});
|
|
587
602
|
|
|
@@ -590,11 +605,13 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
590
605
|
await page
|
|
591
606
|
.evaluate(webEvaluator(d, webArgz))
|
|
592
607
|
.then(async ({ fails, failed, features }: IFinalResults) => {
|
|
608
|
+
logs.info?.write("\n idk1");
|
|
593
609
|
statusMessagePretty(fails, src, "web");
|
|
594
610
|
this.bddTestIsNowDone(src, fails);
|
|
595
611
|
resolve();
|
|
596
612
|
})
|
|
597
613
|
.catch((e) => {
|
|
614
|
+
logs.info?.write("\n idk2");
|
|
598
615
|
console.log(ansiC.red(ansiC.inverse(e.stack)));
|
|
599
616
|
console.log(
|
|
600
617
|
ansiC.red(
|
|
@@ -626,6 +643,7 @@ export class PM_Main extends PM_WithHelpo {
|
|
|
626
643
|
reject(e);
|
|
627
644
|
})
|
|
628
645
|
.finally(async () => {
|
|
646
|
+
logs.info?.write("\n idk3");
|
|
629
647
|
// Generate prompt files for Web tests
|
|
630
648
|
await this.generatePromptFiles(reportDest, src);
|
|
631
649
|
close();
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import express from "express";
|
|
3
|
+
// import Docker from "dockerode";
|
|
4
|
+
|
|
5
|
+
console.log("hello mothership");
|
|
6
|
+
|
|
7
|
+
// const app = express();
|
|
8
|
+
// app.use(express.json());
|
|
9
|
+
|
|
10
|
+
// // const docker = new Docker();
|
|
11
|
+
|
|
12
|
+
// // Track running services
|
|
13
|
+
// const runningServices = new Map();
|
|
14
|
+
|
|
15
|
+
// // Service to build file mapping
|
|
16
|
+
// const serviceBuildFiles = {
|
|
17
|
+
// "node-build": "src/builders/node.ts",
|
|
18
|
+
// "web-build": "src/builders/web.ts",
|
|
19
|
+
// "golang-build": "src/builders/golang.ts",
|
|
20
|
+
// "python-build": "src/builders/python.ts",
|
|
21
|
+
// };
|
|
22
|
+
|
|
23
|
+
// // Automatically start build services on mothership startup
|
|
24
|
+
// async function initializeServices() {
|
|
25
|
+
// console.log("Initializing build services...");
|
|
26
|
+
|
|
27
|
+
// for (const serviceName of Object.keys(serviceBuildFiles)) {
|
|
28
|
+
// try {
|
|
29
|
+
// // Get all containers
|
|
30
|
+
// // const containers = await docker.listContainers({ all: true });
|
|
31
|
+
// // Find the container for the requested service
|
|
32
|
+
// // const containerInfo = containers.find((container) =>
|
|
33
|
+
// // container.Names.some((name) => name.includes(serviceName))
|
|
34
|
+
// // );
|
|
35
|
+
// // if (containerInfo) {
|
|
36
|
+
// // // const container = docker.getContainer(containerInfo.Id);
|
|
37
|
+
// // // Start the container if it's not running
|
|
38
|
+
// // if (containerInfo.State !== "running") {
|
|
39
|
+
// // console.log(`Starting ${serviceName}...`);
|
|
40
|
+
// // await container.start();
|
|
41
|
+
// // } else {
|
|
42
|
+
// // console.log(`${serviceName} is already running`);
|
|
43
|
+
// // }
|
|
44
|
+
// // runningServices.set(serviceName, containerInfo.Id);
|
|
45
|
+
// // } else {
|
|
46
|
+
// // console.warn(`Container for ${serviceName} not found`);
|
|
47
|
+
// // }
|
|
48
|
+
// } catch (error) {
|
|
49
|
+
// console.error(`Error initializing ${serviceName}:`, error);
|
|
50
|
+
// }
|
|
51
|
+
// }
|
|
52
|
+
// console.log("Build services initialization complete");
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// // Initialize services when mothership starts
|
|
56
|
+
// initializeServices();
|
|
57
|
+
|
|
58
|
+
// app.get("/", (req, res) => {
|
|
59
|
+
// res.send("Mothership is running");
|
|
60
|
+
// });
|
|
61
|
+
|
|
62
|
+
// // Start a specific service
|
|
63
|
+
// app.post("/services/:serviceName/start", async (req, res) => {
|
|
64
|
+
// const { serviceName } = req.params;
|
|
65
|
+
|
|
66
|
+
// try {
|
|
67
|
+
// // // Get all containers
|
|
68
|
+
// // const containers = await docker.listContainers({ all: true });
|
|
69
|
+
// // // Find the container for the requested service
|
|
70
|
+
// // const containerInfo = containers.find((container) =>
|
|
71
|
+
// // container.Names.some((name) => name.includes(serviceName))
|
|
72
|
+
// // );
|
|
73
|
+
// // if (!containerInfo) {
|
|
74
|
+
// // return res
|
|
75
|
+
// // .status(404)
|
|
76
|
+
// // .json({ error: `Service ${serviceName} not found` });
|
|
77
|
+
// // }
|
|
78
|
+
// // const container = docker.getContainer(containerInfo.Id);
|
|
79
|
+
// // // Start the container if it's not running
|
|
80
|
+
// // if (containerInfo.State !== "running") {
|
|
81
|
+
// // await container.start();
|
|
82
|
+
// // }
|
|
83
|
+
// // runningServices.set(serviceName, containerInfo.Id);
|
|
84
|
+
// // res.status(200).json({
|
|
85
|
+
// // status: "started",
|
|
86
|
+
// // service: serviceName,
|
|
87
|
+
// // containerId: containerInfo.Id,
|
|
88
|
+
// // });
|
|
89
|
+
// } catch (error) {
|
|
90
|
+
// console.error(`Error starting service ${serviceName}:`, error);
|
|
91
|
+
// res
|
|
92
|
+
// .status(500)
|
|
93
|
+
// .json({ error: `Failed to start service: ${error.message}` });
|
|
94
|
+
// }
|
|
95
|
+
// });
|
|
96
|
+
|
|
97
|
+
// // Stop a specific service
|
|
98
|
+
// app.post("/services/:serviceName/stop", async (req, res) => {
|
|
99
|
+
// const { serviceName } = req.params;
|
|
100
|
+
|
|
101
|
+
// try {
|
|
102
|
+
// // const containerId = runningServices.get(serviceName);
|
|
103
|
+
// // if (!containerId) {
|
|
104
|
+
// // return res
|
|
105
|
+
// // .status(404)
|
|
106
|
+
// // .json({ error: `Service ${serviceName} is not running` });
|
|
107
|
+
// // }
|
|
108
|
+
|
|
109
|
+
// // const container = docker.getContainer(containerId);
|
|
110
|
+
// // await container.stop();
|
|
111
|
+
// // runningServices.delete(serviceName);
|
|
112
|
+
|
|
113
|
+
// res.status(200).json({
|
|
114
|
+
// status: "stopped",
|
|
115
|
+
// service: serviceName,
|
|
116
|
+
// });
|
|
117
|
+
// } catch (error) {
|
|
118
|
+
// console.error(`Error stopping service ${serviceName}:`, error);
|
|
119
|
+
// res.status(500).json({ error: `Failed to stop service: ${error.message}` });
|
|
120
|
+
// }
|
|
121
|
+
// });
|
|
122
|
+
|
|
123
|
+
// // Get status of all services
|
|
124
|
+
// app.get("/services", async (req, res) => {
|
|
125
|
+
// try {
|
|
126
|
+
// // const containers = await docker.listContainers({ all: true });
|
|
127
|
+
// // const services = containers
|
|
128
|
+
// // .filter((container) =>
|
|
129
|
+
// // container.Names.some((name) =>
|
|
130
|
+
// // name.match(
|
|
131
|
+
// // /_(node-build|web-build|golang-build|python-build|mothership)_/
|
|
132
|
+
// // )
|
|
133
|
+
// // )
|
|
134
|
+
// // )
|
|
135
|
+
// // .map((container) => ({
|
|
136
|
+
// // name: container.Names[0].replace("/", ""),
|
|
137
|
+
// // id: container.Id,
|
|
138
|
+
// // status: container.State,
|
|
139
|
+
// // image: container.Image,
|
|
140
|
+
// // }));
|
|
141
|
+
// // res.status(200).json({ services });
|
|
142
|
+
// } catch (error) {
|
|
143
|
+
// console.error("Error listing services:", error);
|
|
144
|
+
// res
|
|
145
|
+
// .status(500)
|
|
146
|
+
// .json({ error: `Failed to list services: ${error.message}` });
|
|
147
|
+
// }
|
|
148
|
+
// });
|
|
149
|
+
|
|
150
|
+
// // Trigger a build in a specific service
|
|
151
|
+
// app.post("/build/:serviceName", async (req, res) => {
|
|
152
|
+
// // const { serviceName } = req.params;
|
|
153
|
+
// // try {
|
|
154
|
+
// // const containerId = runningServices.get(serviceName);
|
|
155
|
+
// // if (!containerId) {
|
|
156
|
+
// // return res
|
|
157
|
+
// // .status(404)
|
|
158
|
+
// // .json({ error: `Service ${serviceName} is not running` });
|
|
159
|
+
// // }
|
|
160
|
+
// // // const container = docker.getContainer(containerId);
|
|
161
|
+
// // // Execute the build command in the container
|
|
162
|
+
// // const buildFile = serviceBuildFiles[serviceName];
|
|
163
|
+
// // if (!buildFile) {
|
|
164
|
+
// // return res
|
|
165
|
+
// // .status(400)
|
|
166
|
+
// // .json({ error: `No build file configured for ${serviceName}` });
|
|
167
|
+
// // }
|
|
168
|
+
// // // Run the TypeScript build file using ts-node
|
|
169
|
+
// // const exec = await container.exec({
|
|
170
|
+
// // Cmd: ["npx", "ts-node", "--transpile-only", buildFile],
|
|
171
|
+
// // AttachStdout: true,
|
|
172
|
+
// // AttachStderr: true,
|
|
173
|
+
// // });
|
|
174
|
+
// // // Start the exec instance
|
|
175
|
+
// // const stream = await exec.start({ hijack: true, stdin: false });
|
|
176
|
+
// // // Collect output
|
|
177
|
+
// // let output = "";
|
|
178
|
+
// // stream.on("data", (chunk: Buffer) => {
|
|
179
|
+
// // output += chunk.toString();
|
|
180
|
+
// // });
|
|
181
|
+
// // stream.on("end", () => {
|
|
182
|
+
// // res.status(200).json({
|
|
183
|
+
// // status: "build completed",
|
|
184
|
+
// // service: serviceName,
|
|
185
|
+
// // output: output,
|
|
186
|
+
// // });
|
|
187
|
+
// // });
|
|
188
|
+
// // stream.on("error", (error) => {
|
|
189
|
+
// // console.error(`Stream error for ${serviceName}:`, error);
|
|
190
|
+
// // res.status(500).json({ error: `Build stream error: ${error.message}` });
|
|
191
|
+
// // });
|
|
192
|
+
// // } catch (error) {
|
|
193
|
+
// // console.error(`Error triggering build for ${serviceName}:`, error);
|
|
194
|
+
// // res
|
|
195
|
+
// // .status(500)
|
|
196
|
+
// // .json({ error: `Failed to trigger build: ${error.message}` });
|
|
197
|
+
// // }
|
|
198
|
+
// });
|
|
199
|
+
|
|
200
|
+
// // Get build file for each service
|
|
201
|
+
// app.get("/build-files", (req, res) => {
|
|
202
|
+
// res.status(200).json(serviceBuildFiles);
|
|
203
|
+
// });
|
|
204
|
+
|
|
205
|
+
// // Claim resource endpoint
|
|
206
|
+
// app.get("/claim", (req, res) => {
|
|
207
|
+
// const { resource } = req.query;
|
|
208
|
+
// console.log(`Resource claimed: ${resource}`);
|
|
209
|
+
// res.status(200).json({ status: "claimed", resource });
|
|
210
|
+
// });
|
|
211
|
+
|
|
212
|
+
// export default (port: number) => {
|
|
213
|
+
// app.listen(port, () => {
|
|
214
|
+
// console.log(`Mothership listening on port ${port}`);
|
|
215
|
+
// });
|
|
216
|
+
|
|
217
|
+
// return app;
|
|
218
|
+
// };
|