Skip to content

Commit 76038f6

Browse files
committed
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.
1 parent a511f4d commit 76038f6

4 files changed

Lines changed: 19 additions & 41 deletions

File tree

apps/dokploy/components/dashboard/application/deployments/clear-deployments.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ export const ClearDeployments = ({ id, type }: Props) => {
2525
type === "application"
2626
? api.application.clearDeployments.useMutation()
2727
: api.compose.clearDeployments.useMutation();
28-
const { data: isCloud } = api.settings.isCloud.useQuery();
29-
30-
if (isCloud) {
31-
return null;
32-
}
3328

3429
return (
3530
<AlertDialog>
@@ -57,14 +52,11 @@ export const ClearDeployments = ({ id, type }: Props) => {
5752
applicationId: id || "",
5853
composeId: id || "",
5954
})
60-
.then(async (result) => {
61-
toast.success(
62-
`${result.deletedCount} old deployments cleared successfully`,
63-
);
64-
// Invalidate deployment queries to refresh the list
55+
.then(async () => {
56+
toast.success("Old deployments cleared successfully");
6557
await utils.deployment.allByType.invalidate({
6658
id,
67-
type,
59+
type: type as "application" | "compose",
6860
});
6961
})
7062
.catch((err) => {

apps/dokploy/server/api/routers/application.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,8 @@ export const applicationRouter = createTRPCRouter({
761761
"You are not authorized to clear deployments for this application",
762762
});
763763
}
764-
const result = await clearOldDeployments(input.applicationId);
765-
return {
766-
success: true,
767-
message: `${result.deletedCount} old deployments cleared successfully`,
768-
deletedCount: result.deletedCount,
769-
};
764+
await clearOldDeployments(application.appName, application.serverId);
765+
return true;
770766
}),
771767
killBuild: protectedProcedure
772768
.input(apiFindOneApplication)

apps/dokploy/server/api/routers/compose.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,8 @@ export const composeRouter = createTRPCRouter({
278278
"You are not authorized to clear deployments for this compose",
279279
});
280280
}
281-
const result = await clearOldDeployments(input.composeId, "compose");
282-
return {
283-
success: true,
284-
message: `${result.deletedCount} old deployments cleared successfully`,
285-
deletedCount: result.deletedCount,
286-
};
281+
await clearOldDeployments(compose.appName, compose.serverId);
282+
return true;
287283
}),
288284
killBuild: protectedProcedure
289285
.input(apiFindCompose)

packages/server/src/services/deployment.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from "@dokploy/server/utils/process/execAsync";
2020
import { TRPCError } from "@trpc/server";
2121
import { format } from "date-fns";
22-
import { and, desc, eq, or } from "drizzle-orm";
22+
import { desc, eq } from "drizzle-orm";
2323
import {
2424
type Application,
2525
findApplicationById,
@@ -853,23 +853,17 @@ export const findAllDeploymentsByServerId = async (serverId: string) => {
853853
};
854854

855855
export const clearOldDeployments = async (
856-
id: string,
857-
type: "application" | "compose" = "application",
856+
appName: string,
857+
serverId: string | null,
858858
) => {
859-
// Get all deployments ordered by creation date (newest first)
860-
const deploymentsList = await db.query.deployments.findMany({
861-
where: and(
862-
eq(deployments[`${type}Id`], id),
863-
or(eq(deployments.status, "done"), eq(deployments.status, "error")),
864-
),
865-
orderBy: desc(deployments.createdAt),
866-
});
867-
868-
for (const deployment of deploymentsList) {
869-
await removeDeployment(deployment.deploymentId);
859+
const { LOGS_PATH } = paths(!!serverId);
860+
const folder = path.join(LOGS_PATH, appName);
861+
const command = `
862+
rm -rf ${folder};
863+
`;
864+
if (serverId) {
865+
await execAsyncRemote(serverId, command);
866+
} else {
867+
await execAsync(command);
870868
}
871-
872-
return {
873-
deletedCount: deploymentsList.length,
874-
};
875869
};

0 commit comments

Comments
 (0)