Skip to content

Commit 95a944c

Browse files
committed
feat(deployments): enhance deployment deletion logic and improve error handling
- Updated the deployment deletion process to include error handling for non-existent deployments. - Refactored the command execution to handle both remote and local execution based on server availability. - Simplified the logic for determining deletable deployments in the ShowDeployments component.
1 parent 6d6cf18 commit 95a944c

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,9 @@ export const ShowDeployments = ({
259259
const isExpanded = expandedDescriptions.has(
260260
deployment.deploymentId,
261261
);
262-
const lastSuccessfulDeployment = deployments?.find(
263-
(d) => d.status === "done",
264-
);
265-
const isLastSuccessfulDeployment =
266-
lastSuccessfulDeployment?.deploymentId ===
267-
deployment.deploymentId;
268262
const canDelete =
269-
deployments &&
270-
deployments.length > 1 &&
271-
!isLastSuccessfulDeployment;
263+
deployment.status === "done" || deployment.status === "error";
264+
272265
return (
273266
<div
274267
key={deployment.deploymentId}

packages/server/src/services/deployment.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
deployments,
1414
} from "@dokploy/server/db/schema";
1515
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
16-
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
16+
import {
17+
execAsync,
18+
execAsyncRemote,
19+
} from "@dokploy/server/utils/process/execAsync";
1720
import { TRPCError } from "@trpc/server";
1821
import { format } from "date-fns";
1922
import { desc, eq } from "drizzle-orm";
@@ -554,8 +557,25 @@ export const removeDeployment = async (deploymentId: string) => {
554557
const deployment = await db
555558
.delete(deployments)
556559
.where(eq(deployments.deploymentId, deploymentId))
557-
.returning();
558-
return deployment[0];
560+
.returning()
561+
.then((result) => result[0]);
562+
563+
if (!deployment) {
564+
throw new TRPCError({
565+
code: "BAD_REQUEST",
566+
message: "Deployment not found",
567+
});
568+
}
569+
const command = `
570+
rm -f ${deployment.logPath};
571+
`;
572+
if (deployment.serverId) {
573+
await execAsyncRemote(deployment.serverId, command);
574+
} else {
575+
await execAsync(command);
576+
}
577+
578+
return deployment;
559579
} catch (error) {
560580
const message =
561581
error instanceof Error ? error.message : "Error creating the deployment";
@@ -848,7 +868,7 @@ export const clearOldDeploymentsByApplicationId = async (
848868

849869
// If there's an active deployment, keep it and remove all others
850870
// If there's no active deployment, keep the most recent one and remove the rest
851-
let deploymentsToKeep: string[] = [];
871+
const deploymentsToKeep: string[] = [];
852872

853873
if (activeDeployment) {
854874
deploymentsToKeep.push(activeDeployment.deploymentId);
@@ -901,7 +921,7 @@ export const clearOldDeploymentsByComposeId = async (composeId: string) => {
901921

902922
// If there's an active deployment, keep it and remove all others
903923
// If there's no active deployment, keep the most recent one and remove the rest
904-
let deploymentsToKeep: string[] = [];
924+
const deploymentsToKeep: string[] = [];
905925

906926
if (activeDeployment) {
907927
deploymentsToKeep.push(activeDeployment.deploymentId);

0 commit comments

Comments
 (0)