This commit is contained in:
2026-01-01 06:37:21 +01:00
parent 1eadacae9e
commit a574aeb48f
5 changed files with 72 additions and 50 deletions
+18 -1
View File
@@ -3,7 +3,7 @@
import { verifySession } from "./auth/session";
import { getNodes } from "./node";
import axios from "axios";
import { ImageApp } from "@/lib/types";
import { Env, ImageApp } from "@/lib/types";
export async function deployNewApp(name: string, repo: string, nodeId: string) {
if (await verifySession()) {
@@ -41,3 +41,20 @@ export async function getApplications(): Promise<ImageApp[]> {
)
).flat();
}
export async function getEnv(): Promise<Record<string, Env[]>> {
const nodes = await getNodes();
const envRecords = await Promise.all(
nodes.map(async (n) => {
const response = await axios.get(`http://${n.ip}:3000/api/env`, {
headers: { Authorization: `ApiKey ${n.key}` },
});
return response.data as Record<string, Env[]>;
})
);
const merged: Record<string, Env[]> = Object.assign({}, ...envRecords);
return merged;
}
+19 -1
View File
@@ -6,7 +6,7 @@ import fs from "fs";
import path from "path";
import { exec } from "child_process";
import util from "util";
import { ImageApp } from "@/lib/types";
import { Env, ImageApp } from "@/lib/types";
import { CPUusage } from "@/lib/server/calc";
const docker = new Docker();
@@ -100,6 +100,8 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) {
JSON.stringify(appConfig, null, 2)
);
fs.writeFileSync(path.join(appDir, "env.json"), JSON.stringify([], null, 2));
// Clone repository
try {
await execAsync(`git clone ${repo} ${repoDir}`);
@@ -132,3 +134,19 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) {
image: imageTag,
};
}
export async function getEnv(): Promise<Record<string, Env[]>> {
const apps = fs.readdirSync(DATA_DIR);
return apps.reduce((acc, appId) => {
const appPath = path.join(DATA_DIR, appId, "app.json");
const name = JSON.parse(fs.readFileSync(appPath).toString()).name;
const envPath = path.join(DATA_DIR, appId, "env.json");
if (fs.existsSync(envPath)) {
const envData: Env[] = JSON.parse(fs.readFileSync(envPath, "utf-8"));
acc[name] = envData;
}
return acc;
}, {} as Record<string, Env[]>);
}