Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: simplify node service log & add badge color on list service/container #1000

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions apps/dokploy/components/dashboard/application/logs/show.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Badge } from "@/components/ui/badge";
import {
Card,
CardContent,
Expand Down Expand Up @@ -30,6 +31,21 @@ export const DockerLogs = dynamic(
},
);

export const badgeStateColor = (state: string) => {
switch (state) {
case "running":
return "green";
case "exited":
case "shutdown":
return "red";
case "accepted":
case "created":
return "blue";
default:
return "default";
}
};

interface Props {
appName: string;
serverId?: string;
Expand Down Expand Up @@ -80,7 +96,7 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
return (
<Card className="bg-background">
<CardHeader>
<CardTitle className="text-xl">Logssss</CardTitle>
<CardTitle className="text-xl">Logs</CardTitle>
<CardDescription>
Watch the logs of the application in real time
</CardDescription>
Expand Down Expand Up @@ -123,7 +139,9 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
value={container.containerId}
>
{container.name} ({container.containerId}){" "}
{container.state}
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem>
))}
</div>
Expand All @@ -135,7 +153,10 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
value={container.containerId}
>
{container.name} ({container.containerId}@{container.node}
) {container.state}
)
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem>
))}
</>
Expand Down
13 changes: 11 additions & 2 deletions apps/dokploy/components/dashboard/compose/logs/show-stack.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { badgeStateColor } from "@/components/dashboard/application/logs/show";
import { Badge } from "@/components/ui/badge";
import {
Card,
CardContent,
Expand Down Expand Up @@ -35,6 +37,8 @@ interface Props {
serverId?: string;
}

badgeStateColor;

export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
const [option, setOption] = useState<"swarm" | "native">("native");
const [containerId, setContainerId] = useState<string | undefined>();
Expand Down Expand Up @@ -123,7 +127,9 @@ export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
value={container.containerId}
>
{container.name} ({container.containerId}){" "}
{container.state}
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem>
))}
</div>
Expand All @@ -135,7 +141,10 @@ export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
value={container.containerId}
>
{container.name} ({container.containerId}@{container.node}
) {container.state}
)
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem>
))}
</>
Expand Down
7 changes: 6 additions & 1 deletion apps/dokploy/components/dashboard/compose/logs/show.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { badgeStateColor } from "@/components/dashboard/application/logs/show";
import { Badge } from "@/components/ui/badge";
import {
Card,
CardContent,
Expand Down Expand Up @@ -87,7 +89,10 @@ export const ShowDockerLogsCompose = ({
key={container.containerId}
value={container.containerId}
>
{container.name} ({container.containerId}) {container.state}
{container.name} ({container.containerId}){" "}
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem>
))}
<SelectLabel>Containers ({data?.length})</SelectLabel>
Expand Down
8 changes: 6 additions & 2 deletions apps/dokploy/server/wss/docker-container-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const setupDockerContainerLogsWebSocketServer = (
const client = new Client();
client
.once("ready", () => {
const baseCommand = `docker ${runType === "swarm" ? "service" : "container"} logs --timestamps --tail ${tail} ${
const baseCommand = `docker ${runType === "swarm" ? "service" : "container"} logs --timestamps ${
runType === "swarm" ? "--raw" : ""
} --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const escapedSearch = search ? search.replace(/'/g, "'\\''") : "";
Expand Down Expand Up @@ -98,7 +100,9 @@ export const setupDockerContainerLogsWebSocketServer = (
});
} else {
const shell = getShell();
const baseCommand = `docker ${runType === "swarm" ? "service" : "container"} logs --timestamps --tail ${tail} ${
const baseCommand = `docker ${runType === "swarm" ? "service" : "container"} logs --timestamps ${
runType === "swarm" ? "--raw" : ""
} --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const command = search
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/services/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const getStackContainersByAppName = async (
: "No container name";

const state = parts[2]
? parts[2].replace("State: ", "").trim()
? parts[2].replace("State: ", "").trim().toLowerCase()
: "No state";
const node = parts[3]
? parts[3].replace("Node: ", "").trim()
Expand Down Expand Up @@ -255,7 +255,7 @@ export const getServiceContainersByAppName = async (
: "No container name";

const state = parts[2]
? parts[2].replace("State: ", "").trim()
? parts[2].replace("State: ", "").trim().toLowerCase()
: "No state";

const node = parts[3]
Expand Down Expand Up @@ -426,7 +426,7 @@ export const getNodeApplications = async (serverId?: string) => {
.trim()
.split("\n")
.map((line) => JSON.parse(line))
.filter((service) => !service.Name.startsWith('dokploy-'));
.filter((service) => !service.Name.startsWith("dokploy-"));

return appArray;
} catch (error) {}
Expand Down
Loading