refactor(cloud): add is cloud flag to cluters

This commit is contained in:
Mauricio Siu 2024-10-04 14:40:31 -06:00
parent 3747db08d4
commit daa87c0dc7
2 changed files with 28 additions and 5 deletions

View File

@ -48,10 +48,7 @@ RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm
# Install Nixpacks and tsx # Install Nixpacks and tsx
# | VERBOSE=1 VERSION=1.21.0 bash # | VERBOSE=1 VERSION=1.21.0 bash
RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \ RUN pnpm install -g tsx
&& chmod +x install.sh \
&& ./install.sh \
&& pnpm install -g tsx
# Install buildpacks # Install buildpacks
COPY --from=buildpacksio/pack:0.35.0 /usr/local/bin/pack /usr/local/bin/pack COPY --from=buildpacksio/pack:0.35.0 /usr/local/bin/pack /usr/local/bin/pack

View File

@ -2,10 +2,18 @@ import { getPublicIpWithFallback } from "@/server/wss/terminal";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { z } from "zod"; import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "../trpc"; import { createTRPCRouter, protectedProcedure } from "../trpc";
import { execAsync, docker, type DockerNode } from "@dokploy/builders"; import {
execAsync,
docker,
type DockerNode,
IS_CLOUD,
} from "@dokploy/builders";
export const clusterRouter = createTRPCRouter({ export const clusterRouter = createTRPCRouter({
getNodes: protectedProcedure.query(async () => { getNodes: protectedProcedure.query(async () => {
if (IS_CLOUD) {
return [];
}
const workers: DockerNode[] = await docker.listNodes(); const workers: DockerNode[] = await docker.listNodes();
return workers; return workers;
@ -17,6 +25,12 @@ export const clusterRouter = createTRPCRouter({
}), }),
) )
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
if (IS_CLOUD) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Functionality not available in cloud version",
});
}
try { try {
await execAsync( await execAsync(
`docker node update --availability drain ${input.nodeId}`, `docker node update --availability drain ${input.nodeId}`,
@ -32,6 +46,12 @@ export const clusterRouter = createTRPCRouter({
} }
}), }),
addWorker: protectedProcedure.query(async ({ input }) => { addWorker: protectedProcedure.query(async ({ input }) => {
if (IS_CLOUD) {
return {
command: "",
version: "",
};
}
const result = await docker.swarmInspect(); const result = await docker.swarmInspect();
const docker_version = await docker.version(); const docker_version = await docker.version();
@ -43,6 +63,12 @@ export const clusterRouter = createTRPCRouter({
}; };
}), }),
addManager: protectedProcedure.query(async ({ input }) => { addManager: protectedProcedure.query(async ({ input }) => {
if (IS_CLOUD) {
return {
command: "",
version: "",
};
}
const result = await docker.swarmInspect(); const result = await docker.swarmInspect();
const docker_version = await docker.version(); const docker_version = await docker.version();
return { return {