Patched a few things with deployment
This commit is contained in:
Generated
+28
@@ -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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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">
|
||||||
<Button variant="ghost" size="icon-sm" aria-label="Deploy">
|
<DeployAppDialog defaultApp={app.id}>
|
||||||
<Rocket className="w-3 h-3" />
|
<Button variant="ghost" size="icon-sm" aria-label="Deploy">
|
||||||
</Button>
|
<Rocket className="w-3 h-3" />
|
||||||
|
</Button>
|
||||||
|
</DeployAppDialog>
|
||||||
|
|
||||||
<RemoveDialog remove={() => remove(app.id)} />
|
<RemoveDialog remove={() => remove(app.id)} />
|
||||||
|
|
||||||
|
|||||||
@@ -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" />
|
||||||
|
|||||||
@@ -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(() => {
|
||||||
|
|||||||
+63
-32
@@ -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,46 +19,76 @@ 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()
|
|
||||||
.map(async (deployId) => {
|
|
||||||
const container = docker.getContainer(deployId);
|
|
||||||
const containerInfo = await container.inspect();
|
|
||||||
|
|
||||||
let cpu = 0;
|
const deploymentIds = apps.flatMap((app) => app.deployments);
|
||||||
let memory = 0;
|
|
||||||
let ports: Set<[number, number]> = new Set();
|
|
||||||
|
|
||||||
if (containerInfo.State.Running) {
|
const results = await Promise.all(
|
||||||
const stats = await container.stats({ stream: false });
|
deploymentIds.map((deployId) =>
|
||||||
memory += (stats.memory_stats.usage / stats.memory_stats.limit) * 100;
|
limit(async (): Promise<Deployment | null> => {
|
||||||
cpu += CPUusage(stats);
|
try {
|
||||||
}
|
const container = docker.getContainer(deployId);
|
||||||
|
const containerInfo = await container.inspect();
|
||||||
|
|
||||||
|
let cpu = 0;
|
||||||
|
let memory = 0;
|
||||||
|
|
||||||
|
// Use Map to deduplicate ports reliably
|
||||||
|
const ports = new Map<number, number>();
|
||||||
|
|
||||||
|
if (containerInfo.State?.Running) {
|
||||||
|
const stats = await container.stats({ stream: false });
|
||||||
|
|
||||||
|
const usage = stats.memory_stats?.usage ?? 0;
|
||||||
|
const limitMem = stats.memory_stats?.limit ?? 0;
|
||||||
|
|
||||||
|
if (limitMem > 0) {
|
||||||
|
memory = (usage / limitMem) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu = CPUusage(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
const portMappings = containerInfo.NetworkSettings?.Ports ?? {};
|
||||||
|
|
||||||
|
for (const [key, mappings] of Object.entries(portMappings)) {
|
||||||
|
if (!mappings) continue;
|
||||||
|
|
||||||
|
const privatePort = Number.parseInt(key.split("/")[0], 10);
|
||||||
|
|
||||||
for (const [key, mappings] of Object.entries(
|
|
||||||
containerInfo.NetworkSettings.Ports
|
|
||||||
)) {
|
|
||||||
const privatePort = parseInt(key.split("/")[0], 10);
|
|
||||||
if (mappings) {
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
image: containerInfo.Image,
|
image: containerInfo.Image,
|
||||||
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user