Patched a few things with deployment

This commit is contained in:
2026-01-03 00:12:30 +01:00
parent 8265f12375
commit e95dc66913
6 changed files with 109 additions and 39 deletions
+28
View File
@@ -32,6 +32,7 @@
"lucide-react": "^0.562.0", "lucide-react": "^0.562.0",
"next": "16.1.1", "next": "16.1.1",
"os-name": "^6.1.0", "os-name": "^6.1.0",
"p-limit": "^7.2.0",
"react": "19.2.3", "react": "19.2.3",
"react-dom": "19.2.3", "react-dom": "19.2.3",
"recharts": "^2.15.4", "recharts": "^2.15.4",
@@ -4517,6 +4518,21 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/p-limit": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-7.2.0.tgz",
"integrity": "sha512-ATHLtwoTNDloHRFFxFJdHnG6n2WUeFjaR8XQMFdKIv0xkXjrER8/iG9iu265jOM95zXHAfv9oTkqhrfbIzosrQ==",
"license": "MIT",
"dependencies": {
"yocto-queue": "^1.2.1"
},
"engines": {
"node": ">=20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/path-key": { "node_modules/path-key": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
@@ -5348,6 +5364,18 @@
"engines": { "engines": {
"node": ">=12" "node": ">=12"
} }
},
"node_modules/yocto-queue": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz",
"integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==",
"license": "MIT",
"engines": {
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
} }
} }
} }
+1
View File
@@ -32,6 +32,7 @@
"lucide-react": "^0.562.0", "lucide-react": "^0.562.0",
"next": "16.1.1", "next": "16.1.1",
"os-name": "^6.1.0", "os-name": "^6.1.0",
"p-limit": "^7.2.0",
"react": "19.2.3", "react": "19.2.3",
"react-dom": "19.2.3", "react-dom": "19.2.3",
"recharts": "^2.15.4", "recharts": "^2.15.4",
+3
View File
@@ -17,6 +17,7 @@ import { useEffect, useState } from "react";
import { getApplications, removeApp } from "@/lib/dockship/application"; import { getApplications, removeApp } from "@/lib/dockship/application";
import RemoveDialog from "@/components/dialogs/Remove"; import RemoveDialog from "@/components/dialogs/Remove";
import { Application } from "@/lib/types"; import { Application } from "@/lib/types";
import DeployAppDialog from "@/components/dialogs/DeployApp";
export default function ApplicationsPage() { export default function ApplicationsPage() {
const [applications, setApplications] = useState<Application[]>([]); const [applications, setApplications] = useState<Application[]>([]);
@@ -75,9 +76,11 @@ export default function ApplicationsPage() {
</CardContent> </CardContent>
<CardFooter className="justify-end"> <CardFooter className="justify-end">
<DeployAppDialog defaultApp={app.id}>
<Button variant="ghost" size="icon-sm" aria-label="Deploy"> <Button variant="ghost" size="icon-sm" aria-label="Deploy">
<Rocket className="w-3 h-3" /> <Rocket className="w-3 h-3" />
</Button> </Button>
</DeployAppDialog>
<RemoveDialog remove={() => remove(app.id)} /> <RemoveDialog remove={() => remove(app.id)} />
+3 -2
View File
@@ -82,7 +82,8 @@ export default function DeploymentsPage() {
{/* Desktop */} {/* Desktop */}
<div className="hidden md:block space-y-3"> <div className="hidden md:block space-y-3">
{deployments.map((dep) => { {deployments.map((dep) => {
const appName = appNameByContainer.get(dep.container) ?? "Unknown app"; const appName =
appNameByContainer.get(dep.container) ?? "Unknown app";
return ( return (
<div <div
@@ -128,7 +129,7 @@ export default function DeploymentsPage() {
appNameByContainer.get(dep.container) ?? "Unknown app"; appNameByContainer.get(dep.container) ?? "Unknown app";
return ( return (
<div key={`${dep.image}-mobile`} className="p-4 space-y-3"> <div key={`${dep.container}-mobile`} className="p-4 space-y-3">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Rocket className="w-4 h-4 text-muted-foreground" /> <Rocket className="w-4 h-4 text-muted-foreground" />
+8 -2
View File
@@ -19,12 +19,18 @@ import { Application, Node, NodeLiveData } from "@/lib/types";
import { getApplications } from "@/core/application"; import { getApplications } from "@/core/application";
import { deployApp } from "@/lib/dockship/deploy"; import { deployApp } from "@/lib/dockship/deploy";
export default function DeployAppDialog({ children }: { children: ReactNode }) { export default function DeployAppDialog({
defaultApp,
children,
}: {
defaultApp?: string;
children: ReactNode;
}) {
const [nodeList, setNodeList] = useState<(NodeLiveData & Node)[]>([]); const [nodeList, setNodeList] = useState<(NodeLiveData & Node)[]>([]);
const [apps, setApps] = useState<Application[]>([]); const [apps, setApps] = useState<Application[]>([]);
const [name, setName] = useState(""); const [name, setName] = useState("");
const [app, setApp] = useState(""); const [app, setApp] = useState(defaultApp || "");
const [node, setNode] = useState(""); const [node, setNode] = useState("");
useEffect(() => { useEffect(() => {
+50 -19
View File
@@ -5,6 +5,7 @@ import { Application, Deployment } from "@/lib/types";
import { CPUusage } from "@/lib/server/calc"; import { CPUusage } from "@/lib/server/calc";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import pLimit from "p-limit";
const docker = new Docker(); const docker = new Docker();
@@ -18,33 +19,50 @@ function sanitizeString(str: string): string {
export async function getDeployments( export async function getDeployments(
apps: Application[] apps: Application[]
): Promise<(null | Deployment)[]> { ): Promise<Deployment[]> {
return await Promise.all( // Limit concurrent Docker calls (adjust if needed)
apps const limit = pLimit(5);
.map((app) => app.deployments)
.flat() const deploymentIds = apps.flatMap((app) => app.deployments);
.map(async (deployId) => {
const results = await Promise.all(
deploymentIds.map((deployId) =>
limit(async (): Promise<Deployment | null> => {
try {
const container = docker.getContainer(deployId); const container = docker.getContainer(deployId);
const containerInfo = await container.inspect(); const containerInfo = await container.inspect();
let cpu = 0; let cpu = 0;
let memory = 0; let memory = 0;
let ports: Set<[number, number]> = new Set();
if (containerInfo.State.Running) { // Use Map to deduplicate ports reliably
const ports = new Map<number, number>();
if (containerInfo.State?.Running) {
const stats = await container.stats({ stream: false }); const stats = await container.stats({ stream: false });
memory += (stats.memory_stats.usage / stats.memory_stats.limit) * 100;
cpu += CPUusage(stats); const usage = stats.memory_stats?.usage ?? 0;
const limitMem = stats.memory_stats?.limit ?? 0;
if (limitMem > 0) {
memory = (usage / limitMem) * 100;
} }
for (const [key, mappings] of Object.entries( cpu = CPUusage(stats);
containerInfo.NetworkSettings.Ports }
)) {
const privatePort = parseInt(key.split("/")[0], 10); const portMappings = containerInfo.NetworkSettings?.Ports ?? {};
if (mappings) {
for (const [key, mappings] of Object.entries(portMappings)) {
if (!mappings) continue;
const privatePort = Number.parseInt(key.split("/")[0], 10);
for (const mapping of mappings) { for (const mapping of mappings) {
const publicPort = parseInt(mapping.HostPort, 10); const publicPort = Number.parseInt(mapping.HostPort, 10);
ports.add([publicPort, privatePort]);
if (!Number.isNaN(publicPort) && !Number.isNaN(privatePort)) {
ports.set(publicPort, privatePort);
} }
} }
} }
@@ -54,10 +72,23 @@ export async function getDeployments(
container: containerInfo.Id, container: containerInfo.Id,
cpu, cpu,
memory, memory,
status: containerInfo.State.Running ? "running" : "stopped", status: containerInfo.State?.Running ? "running" : "stopped",
ports: [...ports], ports: [...ports.entries()].map(
([publicPort, privatePort]) =>
[publicPort, privatePort] as [number, number]
),
}; };
} catch {
// Container may have stopped / been removed
return null;
}
}) })
)
);
// Remove failed containers
return results.filter(
(deployment: any): deployment is Deployment => deployment !== null
); );
} }