From 95a944c4e5cd63671c5f3034e943270d26e6f534 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Mon, 16 Feb 2026 22:12:56 -0600 Subject: [PATCH] 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. --- .../deployments/show-deployments.tsx | 11 ++----- packages/server/src/services/deployment.ts | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx b/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx index 294772228..3f674aa3c 100644 --- a/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx +++ b/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx @@ -259,16 +259,9 @@ export const ShowDeployments = ({ const isExpanded = expandedDescriptions.has( deployment.deploymentId, ); - const lastSuccessfulDeployment = deployments?.find( - (d) => d.status === "done", - ); - const isLastSuccessfulDeployment = - lastSuccessfulDeployment?.deploymentId === - deployment.deploymentId; const canDelete = - deployments && - deployments.length > 1 && - !isLastSuccessfulDeployment; + deployment.status === "done" || deployment.status === "error"; + return (
{ const deployment = await db .delete(deployments) .where(eq(deployments.deploymentId, deploymentId)) - .returning(); - return deployment[0]; + .returning() + .then((result) => result[0]); + + if (!deployment) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Deployment not found", + }); + } + const command = ` + rm -f ${deployment.logPath}; + `; + if (deployment.serverId) { + await execAsyncRemote(deployment.serverId, command); + } else { + await execAsync(command); + } + + return deployment; } catch (error) { const message = error instanceof Error ? error.message : "Error creating the deployment"; @@ -848,7 +868,7 @@ export const clearOldDeploymentsByApplicationId = async ( // If there's an active deployment, keep it and remove all others // If there's no active deployment, keep the most recent one and remove the rest - let deploymentsToKeep: string[] = []; + const deploymentsToKeep: string[] = []; if (activeDeployment) { deploymentsToKeep.push(activeDeployment.deploymentId); @@ -901,7 +921,7 @@ export const clearOldDeploymentsByComposeId = async (composeId: string) => { // If there's an active deployment, keep it and remove all others // If there's no active deployment, keep the most recent one and remove the rest - let deploymentsToKeep: string[] = []; + const deploymentsToKeep: string[] = []; if (activeDeployment) { deploymentsToKeep.push(activeDeployment.deploymentId);