From 49edcdb99eaae838f3fa9eea61024adc3466434e Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 19 Jan 2025 13:22:23 -0600 Subject: [PATCH 1/2] fix: clean cache at the start of deployments --- packages/server/src/services/application.ts | 75 +++++++++++---------- packages/server/src/services/compose.ts | 40 +++++------ 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index ccadebf7..e297124d 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -176,6 +176,7 @@ export const deployApplication = async ({ descriptionLog: string; }) => { const application = await findApplicationById(applicationId); + const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const deployment = await createDeployment({ applicationId: applicationId, @@ -184,6 +185,12 @@ export const deployApplication = async ({ }); try { + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheApplications) { + await cleanupFullDocker(application?.serverId); + } + if (application.sourceType === "github") { await cloneGithubRepository({ ...application, @@ -230,12 +237,6 @@ export const deployApplication = async ({ }); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheApplications) { - await cleanupFullDocker(application?.serverId); - } } return true; @@ -251,6 +252,7 @@ export const rebuildApplication = async ({ descriptionLog: string; }) => { const application = await findApplicationById(applicationId); + const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -258,6 +260,11 @@ export const rebuildApplication = async ({ }); try { + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheApplications) { + await cleanupFullDocker(application?.serverId); + } if (application.sourceType === "github") { await buildApplication(application, deployment.logPath); } else if (application.sourceType === "gitlab") { @@ -277,12 +284,6 @@ export const rebuildApplication = async ({ await updateDeploymentStatus(deployment.deploymentId, "error"); await updateApplicationStatus(applicationId, "error"); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheApplications) { - await cleanupFullDocker(application?.serverId); - } } return true; @@ -298,6 +299,7 @@ export const deployRemoteApplication = async ({ descriptionLog: string; }) => { const application = await findApplicationById(applicationId); + const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const deployment = await createDeployment({ applicationId: applicationId, @@ -307,6 +309,11 @@ export const deployRemoteApplication = async ({ try { if (application.serverId) { + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheApplications) { + await cleanupFullDocker(application?.serverId); + } let command = "set -e;"; if (application.sourceType === "github") { command += await getGithubCloneCommand({ @@ -373,12 +380,6 @@ export const deployRemoteApplication = async ({ }); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheApplications) { - await cleanupFullDocker(application?.serverId); - } } return true; @@ -396,6 +397,7 @@ export const deployPreviewApplication = async ({ previewDeploymentId: string; }) => { const application = await findApplicationById(applicationId); + const deployment = await createDeploymentPreview({ title: titleLog, description: descriptionLog, @@ -452,6 +454,12 @@ export const deployPreviewApplication = async ({ application.env = application.previewEnv; application.buildArgs = application.previewBuildArgs; + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheOnPreviews) { + await cleanupFullDocker(application?.serverId); + } + if (application.sourceType === "github") { await cloneGithubRepository({ ...application, @@ -461,7 +469,6 @@ export const deployPreviewApplication = async ({ }); await buildApplication(application, deployment.logPath); } - // 4eef09efc46009187d668cf1c25f768d0bde4f91 const successComment = getIssueComment( application.name, "success", @@ -486,12 +493,6 @@ export const deployPreviewApplication = async ({ previewStatus: "error", }); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheOnPreviews) { - await cleanupFullDocker(application?.serverId); - } } return true; @@ -509,6 +510,7 @@ export const deployRemotePreviewApplication = async ({ previewDeploymentId: string; }) => { const application = await findApplicationById(applicationId); + const deployment = await createDeploymentPreview({ title: titleLog, description: descriptionLog, @@ -566,6 +568,11 @@ export const deployRemotePreviewApplication = async ({ application.buildArgs = application.previewBuildArgs; if (application.serverId) { + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheOnPreviews) { + await cleanupFullDocker(application?.serverId); + } let command = "set -e;"; if (application.sourceType === "github") { command += await getGithubCloneCommand({ @@ -604,12 +611,6 @@ export const deployRemotePreviewApplication = async ({ previewStatus: "error", }); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheOnPreviews) { - await cleanupFullDocker(application?.serverId); - } } return true; @@ -625,6 +626,7 @@ export const rebuildRemoteApplication = async ({ descriptionLog: string; }) => { const application = await findApplicationById(applicationId); + const deployment = await createDeployment({ applicationId: applicationId, title: titleLog, @@ -633,6 +635,11 @@ export const rebuildRemoteApplication = async ({ try { if (application.serverId) { + const admin = await findAdminById(application.project.adminId); + + if (admin.cleanupCacheApplications) { + await cleanupFullDocker(application?.serverId); + } if (application.sourceType !== "docker") { let command = "set -e;"; command += getBuildCommand(application, deployment.logPath); @@ -657,12 +664,6 @@ export const rebuildRemoteApplication = async ({ await updateDeploymentStatus(deployment.deploymentId, "error"); await updateApplicationStatus(applicationId, "error"); throw error; - } finally { - const admin = await findAdminById(application.project.adminId); - - if (admin.cleanupCacheApplications) { - await cleanupFullDocker(application?.serverId); - } } return true; diff --git a/packages/server/src/services/compose.ts b/packages/server/src/services/compose.ts index 7f6a5954..a0492314 100644 --- a/packages/server/src/services/compose.ts +++ b/packages/server/src/services/compose.ts @@ -206,6 +206,7 @@ export const deployCompose = async ({ descriptionLog: string; }) => { const compose = await findComposeById(composeId); + const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; @@ -216,6 +217,10 @@ export const deployCompose = async ({ }); try { + const admin = await findAdminById(compose.project.adminId); + if (admin.cleanupCacheOnCompose) { + await cleanupFullDocker(compose?.serverId); + } if (compose.sourceType === "github") { await cloneGithubRepository({ ...compose, @@ -260,11 +265,6 @@ export const deployCompose = async ({ adminId: compose.project.adminId, }); throw error; - } finally { - const admin = await findAdminById(compose.project.adminId); - if (admin.cleanupCacheOnCompose) { - await cleanupFullDocker(compose?.serverId); - } } }; @@ -278,6 +278,7 @@ export const rebuildCompose = async ({ descriptionLog: string; }) => { const compose = await findComposeById(composeId); + const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -285,6 +286,10 @@ export const rebuildCompose = async ({ }); try { + const admin = await findAdminById(compose.project.adminId); + if (admin.cleanupCacheOnCompose) { + await cleanupFullDocker(compose?.serverId); + } if (compose.serverId) { await getBuildComposeCommand(compose, deployment.logPath); } else { @@ -301,11 +306,6 @@ export const rebuildCompose = async ({ composeStatus: "error", }); throw error; - } finally { - const admin = await findAdminById(compose.project.adminId); - if (admin.cleanupCacheOnCompose) { - await cleanupFullDocker(compose?.serverId); - } } return true; @@ -321,6 +321,7 @@ export const deployRemoteCompose = async ({ descriptionLog: string; }) => { const compose = await findComposeById(composeId); + const buildLink = `${await getDokployUrl()}/dashboard/project/${ compose.projectId }/services/compose/${compose.composeId}?tab=deployments`; @@ -331,6 +332,10 @@ export const deployRemoteCompose = async ({ }); try { if (compose.serverId) { + const admin = await findAdminById(compose.project.adminId); + if (admin.cleanupCacheOnCompose) { + await cleanupFullDocker(compose?.serverId); + } let command = "set -e;"; if (compose.sourceType === "github") { @@ -404,11 +409,6 @@ export const deployRemoteCompose = async ({ adminId: compose.project.adminId, }); throw error; - } finally { - const admin = await findAdminById(compose.project.adminId); - if (admin.cleanupCacheOnCompose) { - await cleanupFullDocker(compose?.serverId); - } } }; @@ -422,6 +422,7 @@ export const rebuildRemoteCompose = async ({ descriptionLog: string; }) => { const compose = await findComposeById(composeId); + const deployment = await createDeploymentCompose({ composeId: composeId, title: titleLog, @@ -429,6 +430,10 @@ export const rebuildRemoteCompose = async ({ }); try { + const admin = await findAdminById(compose.project.adminId); + if (admin.cleanupCacheOnCompose) { + await cleanupFullDocker(compose?.serverId); + } if (compose.serverId) { await getBuildComposeCommand(compose, deployment.logPath); } @@ -453,11 +458,6 @@ export const rebuildRemoteCompose = async ({ composeStatus: "error", }); throw error; - } finally { - const admin = await findAdminById(compose.project.adminId); - if (admin.cleanupCacheOnCompose) { - await cleanupFullDocker(compose?.serverId); - } } return true; From 42c9cd5901bf9f2d0d7db24798c93f2fb83bfb19 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 19 Jan 2025 13:24:22 -0600 Subject: [PATCH 2/2] chore: bump package --- apps/dokploy/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dokploy/package.json b/apps/dokploy/package.json index 292c9de6..a7238748 100644 --- a/apps/dokploy/package.json +++ b/apps/dokploy/package.json @@ -1,6 +1,6 @@ { "name": "dokploy", - "version": "v0.17.3", + "version": "v0.17.4", "private": true, "license": "Apache-2.0", "type": "module",