mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-25 21:28:47 +00:00
refactor(deployments): streamline deployment clearing process and remove cloud check
- Removed the cloud check from the ClearDeployments component, simplifying the logic. - Updated the clearOldDeployments function to accept appName and serverId, enhancing its flexibility. - Adjusted the return values in the application and compose routers to return a boolean instead of a detailed message, improving consistency.
This commit is contained in:
@@ -25,11 +25,6 @@ export const ClearDeployments = ({ id, type }: Props) => {
|
|||||||
type === "application"
|
type === "application"
|
||||||
? api.application.clearDeployments.useMutation()
|
? api.application.clearDeployments.useMutation()
|
||||||
: api.compose.clearDeployments.useMutation();
|
: api.compose.clearDeployments.useMutation();
|
||||||
const { data: isCloud } = api.settings.isCloud.useQuery();
|
|
||||||
|
|
||||||
if (isCloud) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AlertDialog>
|
<AlertDialog>
|
||||||
@@ -57,14 +52,11 @@ export const ClearDeployments = ({ id, type }: Props) => {
|
|||||||
applicationId: id || "",
|
applicationId: id || "",
|
||||||
composeId: id || "",
|
composeId: id || "",
|
||||||
})
|
})
|
||||||
.then(async (result) => {
|
.then(async () => {
|
||||||
toast.success(
|
toast.success("Old deployments cleared successfully");
|
||||||
`${result.deletedCount} old deployments cleared successfully`,
|
|
||||||
);
|
|
||||||
// Invalidate deployment queries to refresh the list
|
|
||||||
await utils.deployment.allByType.invalidate({
|
await utils.deployment.allByType.invalidate({
|
||||||
id,
|
id,
|
||||||
type,
|
type: type as "application" | "compose",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
@@ -761,12 +761,8 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
"You are not authorized to clear deployments for this application",
|
"You are not authorized to clear deployments for this application",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const result = await clearOldDeployments(input.applicationId);
|
await clearOldDeployments(application.appName, application.serverId);
|
||||||
return {
|
return true;
|
||||||
success: true,
|
|
||||||
message: `${result.deletedCount} old deployments cleared successfully`,
|
|
||||||
deletedCount: result.deletedCount,
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
killBuild: protectedProcedure
|
killBuild: protectedProcedure
|
||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
|
|||||||
@@ -278,12 +278,8 @@ export const composeRouter = createTRPCRouter({
|
|||||||
"You are not authorized to clear deployments for this compose",
|
"You are not authorized to clear deployments for this compose",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const result = await clearOldDeployments(input.composeId, "compose");
|
await clearOldDeployments(compose.appName, compose.serverId);
|
||||||
return {
|
return true;
|
||||||
success: true,
|
|
||||||
message: `${result.deletedCount} old deployments cleared successfully`,
|
|
||||||
deletedCount: result.deletedCount,
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
killBuild: protectedProcedure
|
killBuild: protectedProcedure
|
||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
} from "@dokploy/server/utils/process/execAsync";
|
} from "@dokploy/server/utils/process/execAsync";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { and, desc, eq, or } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
import {
|
import {
|
||||||
type Application,
|
type Application,
|
||||||
findApplicationById,
|
findApplicationById,
|
||||||
@@ -853,23 +853,17 @@ export const findAllDeploymentsByServerId = async (serverId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const clearOldDeployments = async (
|
export const clearOldDeployments = async (
|
||||||
id: string,
|
appName: string,
|
||||||
type: "application" | "compose" = "application",
|
serverId: string | null,
|
||||||
) => {
|
) => {
|
||||||
// Get all deployments ordered by creation date (newest first)
|
const { LOGS_PATH } = paths(!!serverId);
|
||||||
const deploymentsList = await db.query.deployments.findMany({
|
const folder = path.join(LOGS_PATH, appName);
|
||||||
where: and(
|
const command = `
|
||||||
eq(deployments[`${type}Id`], id),
|
rm -rf ${folder};
|
||||||
or(eq(deployments.status, "done"), eq(deployments.status, "error")),
|
`;
|
||||||
),
|
if (serverId) {
|
||||||
orderBy: desc(deployments.createdAt),
|
await execAsyncRemote(serverId, command);
|
||||||
});
|
} else {
|
||||||
|
await execAsync(command);
|
||||||
for (const deployment of deploymentsList) {
|
|
||||||
await removeDeployment(deployment.deploymentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
deletedCount: deploymentsList.length,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user