mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
- Added an AlertBlock in AddNode to inform users about architecture compatibility when adding nodes. - Updated ShowNodes to correctly handle node deletion actions based on ManagerStatus. - Refactored cluster API to remove cloud-specific checks and improve command execution for remote servers.
101 lines
2.5 KiB
TypeScript
101 lines
2.5 KiB
TypeScript
import { getPublicIpWithFallback } from "@/server/wss/terminal";
|
|
import {
|
|
type DockerNode,
|
|
execAsync,
|
|
execAsyncRemote,
|
|
findServerById,
|
|
getRemoteDocker,
|
|
} from "@dokploy/server";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { z } from "zod";
|
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
|
export const clusterRouter = createTRPCRouter({
|
|
getNodes: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
serverId: z.string().optional(),
|
|
}),
|
|
)
|
|
.query(async ({ input }) => {
|
|
const docker = await getRemoteDocker(input.serverId);
|
|
const workers: DockerNode[] = await docker.listNodes();
|
|
|
|
return workers;
|
|
}),
|
|
removeWorker: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
nodeId: z.string(),
|
|
serverId: z.string().optional(),
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
try {
|
|
const drainCommand = `docker node update --availability drain ${input.nodeId}`;
|
|
const removeCommand = `docker node rm ${input.nodeId} --force`;
|
|
|
|
if (input.serverId) {
|
|
await execAsyncRemote(input.serverId, drainCommand);
|
|
await execAsyncRemote(input.serverId, removeCommand);
|
|
} else {
|
|
await execAsync(drainCommand);
|
|
await execAsync(removeCommand);
|
|
}
|
|
return true;
|
|
} catch (error) {
|
|
throw new TRPCError({
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
message: "Error removing the node",
|
|
cause: error,
|
|
});
|
|
}
|
|
}),
|
|
addWorker: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
serverId: z.string().optional(),
|
|
}),
|
|
)
|
|
.query(async ({ input }) => {
|
|
const docker = await getRemoteDocker(input.serverId);
|
|
const result = await docker.swarmInspect();
|
|
const docker_version = await docker.version();
|
|
|
|
let ip = await getPublicIpWithFallback();
|
|
if (input.serverId) {
|
|
const server = await findServerById(input.serverId);
|
|
ip = server?.ipAddress;
|
|
}
|
|
|
|
return {
|
|
command: `docker swarm join --token ${
|
|
result.JoinTokens.Worker
|
|
} ${ip}:2377`,
|
|
version: docker_version.Version,
|
|
};
|
|
}),
|
|
addManager: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
serverId: z.string().optional(),
|
|
}),
|
|
)
|
|
.query(async ({ input }) => {
|
|
const docker = await getRemoteDocker(input.serverId);
|
|
const result = await docker.swarmInspect();
|
|
const docker_version = await docker.version();
|
|
|
|
let ip = await getPublicIpWithFallback();
|
|
if (input.serverId) {
|
|
const server = await findServerById(input.serverId);
|
|
ip = server?.ipAddress;
|
|
}
|
|
return {
|
|
command: `docker swarm join --token ${
|
|
result.JoinTokens.Manager
|
|
} ${ip}:2377`,
|
|
version: docker_version.Version,
|
|
};
|
|
}),
|
|
});
|