mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-18 18:05:18 +00:00
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.
This commit is contained in:
@@ -259,16 +259,9 @@ export const ShowDeployments = ({
|
|||||||
const isExpanded = expandedDescriptions.has(
|
const isExpanded = expandedDescriptions.has(
|
||||||
deployment.deploymentId,
|
deployment.deploymentId,
|
||||||
);
|
);
|
||||||
const lastSuccessfulDeployment = deployments?.find(
|
|
||||||
(d) => d.status === "done",
|
|
||||||
);
|
|
||||||
const isLastSuccessfulDeployment =
|
|
||||||
lastSuccessfulDeployment?.deploymentId ===
|
|
||||||
deployment.deploymentId;
|
|
||||||
const canDelete =
|
const canDelete =
|
||||||
deployments &&
|
deployment.status === "done" || deployment.status === "error";
|
||||||
deployments.length > 1 &&
|
|
||||||
!isLastSuccessfulDeployment;
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={deployment.deploymentId}
|
key={deployment.deploymentId}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import {
|
|||||||
deployments,
|
deployments,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
|
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
|
||||||
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
import {
|
||||||
|
execAsync,
|
||||||
|
execAsyncRemote,
|
||||||
|
} 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 { desc, eq } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
@@ -554,8 +557,25 @@ export const removeDeployment = async (deploymentId: string) => {
|
|||||||
const deployment = await db
|
const deployment = await db
|
||||||
.delete(deployments)
|
.delete(deployments)
|
||||||
.where(eq(deployments.deploymentId, deploymentId))
|
.where(eq(deployments.deploymentId, deploymentId))
|
||||||
.returning();
|
.returning()
|
||||||
return deployment[0];
|
.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) {
|
} catch (error) {
|
||||||
const message =
|
const message =
|
||||||
error instanceof Error ? error.message : "Error creating the deployment";
|
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 an active deployment, keep it and remove all others
|
||||||
// If there's no active deployment, keep the most recent one and remove the rest
|
// If there's no active deployment, keep the most recent one and remove the rest
|
||||||
let deploymentsToKeep: string[] = [];
|
const deploymentsToKeep: string[] = [];
|
||||||
|
|
||||||
if (activeDeployment) {
|
if (activeDeployment) {
|
||||||
deploymentsToKeep.push(activeDeployment.deploymentId);
|
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 an active deployment, keep it and remove all others
|
||||||
// If there's no active deployment, keep the most recent one and remove the rest
|
// If there's no active deployment, keep the most recent one and remove the rest
|
||||||
let deploymentsToKeep: string[] = [];
|
const deploymentsToKeep: string[] = [];
|
||||||
|
|
||||||
if (activeDeployment) {
|
if (activeDeployment) {
|
||||||
deploymentsToKeep.push(activeDeployment.deploymentId);
|
deploymentsToKeep.push(activeDeployment.deploymentId);
|
||||||
|
|||||||
Reference in New Issue
Block a user