Applications

This commit is contained in:
2025-12-30 14:31:26 +01:00
parent c1eacf996d
commit fb05b455d5
6 changed files with 129 additions and 80 deletions
+56
View File
@@ -0,0 +1,56 @@
"use server";
import { Application } from "@/lib/types";
import Docker from "dockerode";
const docker = new Docker();
export async function getApplications(): Promise<Application[]> {
const images = await docker.listImages();
const containers = await docker.listContainers({ all: true });
const apps: Application[] = [];
for (const image of images) {
const imageName = image.RepoTags?.[0];
if (!imageName) continue;
const relatedContainers = containers.filter((c) => c.Image === imageName);
let totalCpu = 0;
let totalMem = 0;
let running = 0;
const ports = new Set<string>();
for (const containerInfo of relatedContainers) {
const container = docker.getContainer(containerInfo.Id);
if (containerInfo.State === "running") running++;
containerInfo.Ports?.forEach((p) => {
if (p.PublicPort && p.PrivatePort) {
ports.add(`${p.PublicPort}:${p.PrivatePort}`);
}
});
if (containerInfo.State === "running") {
const stats = await container.stats({ stream: false });
}
}
apps.push({
id: image.Id.slice(7, 15),
name: imageName.split("/").pop()?.split(":")[0] ?? imageName,
image: imageName,
containers: relatedContainers.length,
replicas: `${running}/${relatedContainers.length}`,
cpu: Math.round(totalCpu),
memory: Math.round(totalMem),
network: "—",
status: running > 0 ? ("running" as const) : ("stopped" as const),
ports: [...ports],
});
}
return apps;
}