diff --git a/src/app/applications/page.tsx b/src/app/applications/page.tsx index ca959e5..b363fba 100644 --- a/src/app/applications/page.tsx +++ b/src/app/applications/page.tsx @@ -8,11 +8,11 @@ import { Play, Square, RotateCcw, MoreVertical, Plus } from "lucide-react"; import { Progress } from "@/components/ui/progress"; import DeployApplication from "@/components/dialogs/DeployApplication"; import { useEffect, useState } from "react"; -import { Application } from "@/lib/types"; +import { ImageApp } from "@/lib/types"; import { getApplications } from "@/core/application"; export default function ApplicationsPage() { - const [applications, setApplications] = useState([]); + const [applications, setApplications] = useState([]); useEffect(() => { const fetch = async () => { @@ -22,6 +22,8 @@ export default function ApplicationsPage() { fetch(); }, []); + console.log(applications); + return (
- {app.name} + {app.app?.name || app.name}
{app.image} @@ -62,10 +64,10 @@ export default function ApplicationsPage() {
- {/* Replicas */} + {/* Containers */}
- Replicas + Containers
{app.replicas}
diff --git a/src/core/application.ts b/src/core/application.ts index 664ebf8..3f6d4c8 100644 --- a/src/core/application.ts +++ b/src/core/application.ts @@ -3,7 +3,7 @@ import { verifySession } from "./auth/session"; import { getNodes } from "./node"; import axios from "axios"; -import { Application } from "@/lib/types"; +import { ImageApp } from "@/lib/types"; export async function deployNewApp(name: string, repo: string, nodeId: string) { if (await verifySession()) { @@ -25,7 +25,7 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) { ).data.applications; } -export async function getApplications(): Promise { +export async function getApplications(): Promise { const nodes = await getNodes(); return ( diff --git a/src/core/server/application.ts b/src/core/server/application.ts index f2db803..ca27bd5 100644 --- a/src/core/server/application.ts +++ b/src/core/server/application.ts @@ -2,22 +2,21 @@ import Docker from "dockerode"; import { randomUUID } from "crypto"; -import fs from "fs/promises"; +import fs from "fs"; import path from "path"; import { exec } from "child_process"; import util from "util"; -import axios from "axios"; -import { Application } from "@/lib/types"; +import { ImageApp } from "@/lib/types"; const docker = new Docker(); const execAsync = util.promisify(exec); const DATA_DIR = path.join(process.cwd(), "data", "apps"); -export async function getApplications(): Promise { +export async function getApplications(): Promise { const images = await docker.listImages(); const containers = await docker.listContainers({ all: true }); - const apps: Application[] = []; + const apps: ImageApp[] = []; for (const image of images) { const imageName = image.RepoTags?.[0]; @@ -46,9 +45,20 @@ export async function getApplications(): Promise { } } + const name = imageName.split("/").pop()?.split(":")[0] ?? imageName; + + var app; + + try { + app = JSON.parse( + fs.readFileSync(path.join(DATA_DIR, name, "app.json")).toString() + ); + } catch {} + apps.push({ + app, + name, id: image.Id.slice(7, 15), - name: imageName.split("/").pop()?.split(":")[0] ?? imageName, image: imageName, containers: relatedContainers.length, replicas: `${running}/${relatedContainers.length}`, @@ -70,7 +80,7 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) { const repoDir = path.join(appDir, "repo"); // Create directories - await fs.mkdir(repoDir, { recursive: true }); + fs.mkdirSync(repoDir, { recursive: true }); // Write app.json const appConfig = { @@ -81,7 +91,7 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) { createdAt: new Date().toISOString(), }; - await fs.writeFile( + fs.writeFileSync( path.join(appDir, "app.json"), JSON.stringify(appConfig, null, 2) ); @@ -97,7 +107,7 @@ export async function deployNewApp(name: string, repo: string, nodeId: string) { const dockerfilePath = path.join(repoDir, "Dockerfile"); try { - await fs.access(dockerfilePath); + fs.accessSync(dockerfilePath); } catch { throw new Error("Dockerfile not found in repository root"); } diff --git a/src/lib/types.ts b/src/lib/types.ts index 8ce361f..163958e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -49,6 +49,15 @@ export interface Docker { } export interface Application { + id: string; + name: string; + repo: string; + nodeId: string; + createdAt: string; +} + +export interface ImageApp { + app?: Application; id: string; name: string; image: string;