mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-09-12 19:51:00 +05:00
refactor: remove manual log deletion from clearOldDeployments
This commit is contained in:
parent
74843662e0
commit
18d2884469
@ -754,7 +754,7 @@ export const applicationRouter = createTRPCRouter({
|
||||
deployment: ["create"],
|
||||
});
|
||||
const application = await findApplicationById(input.applicationId);
|
||||
await clearOldDeployments(application.applicationId, "application", application.serverId);
|
||||
await clearOldDeployments(application.applicationId, "application");
|
||||
await audit(ctx, {
|
||||
action: "delete",
|
||||
resourceType: "application",
|
||||
|
||||
@ -298,7 +298,7 @@ export const composeRouter = createTRPCRouter({
|
||||
deployment: ["create"],
|
||||
});
|
||||
const compose = await findComposeById(input.composeId);
|
||||
await clearOldDeployments(compose.composeId, "compose", compose.serverId);
|
||||
await clearOldDeployments(compose.composeId, "compose");
|
||||
await audit(ctx, {
|
||||
action: "update",
|
||||
resourceType: "compose",
|
||||
|
||||
@ -1036,8 +1036,7 @@ export const findAllDeploymentsByServerId = async (serverId: string) => {
|
||||
|
||||
export const clearOldDeployments = async (
|
||||
id: string,
|
||||
type: "application" | "compose",
|
||||
serverId: string | null,
|
||||
type: "application" | "compose"
|
||||
) => {
|
||||
const deploymentsList = await db.query.deployments.findMany({
|
||||
where: eq(deployments[`${type}Id`], id),
|
||||
@ -1055,21 +1054,12 @@ export const clearOldDeployments = async (
|
||||
(d) => d.deploymentId !== currentDeployment.deploymentId,
|
||||
);
|
||||
|
||||
const remoteLogCommands: string[] = [];
|
||||
|
||||
for (const oldDeployment of deploymentsToDelete) {
|
||||
try {
|
||||
if (oldDeployment.rollbackId) {
|
||||
await removeRollbackById(oldDeployment.rollbackId);
|
||||
}
|
||||
|
||||
const logPath = path.join(oldDeployment.logPath);
|
||||
const hasLogPath = logPath && logPath !== ".";
|
||||
|
||||
if (serverId) {
|
||||
if (hasLogPath) remoteLogCommands.push(`rm -f "${logPath}"`);
|
||||
}
|
||||
|
||||
await removeDeployment(oldDeployment.deploymentId);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
@ -1078,8 +1068,4 @@ export const clearOldDeployments = async (
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (serverId && remoteLogCommands.length > 0) {
|
||||
await execAsyncRemote(serverId, remoteLogCommands.join(";"));
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user