fix: clean cache at the start of deployments

This commit is contained in:
Mauricio Siu 2025-01-19 13:22:23 -06:00
parent 9298d6c693
commit 49edcdb99e
2 changed files with 58 additions and 57 deletions

View File

@ -176,6 +176,7 @@ export const deployApplication = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`;
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
@ -184,6 +185,12 @@ export const deployApplication = async ({
}); });
try { try {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
if (application.sourceType === "github") { if (application.sourceType === "github") {
await cloneGithubRepository({ await cloneGithubRepository({
...application, ...application,
@ -230,12 +237,6 @@ export const deployApplication = async ({
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;
@ -251,6 +252,7 @@ export const rebuildApplication = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
title: titleLog, title: titleLog,
@ -258,6 +260,11 @@ export const rebuildApplication = async ({
}); });
try { try {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
if (application.sourceType === "github") { if (application.sourceType === "github") {
await buildApplication(application, deployment.logPath); await buildApplication(application, deployment.logPath);
} else if (application.sourceType === "gitlab") { } else if (application.sourceType === "gitlab") {
@ -277,12 +284,6 @@ export const rebuildApplication = async ({
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
await updateApplicationStatus(applicationId, "error"); await updateApplicationStatus(applicationId, "error");
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;
@ -298,6 +299,7 @@ export const deployRemoteApplication = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`; const buildLink = `${await getDokployUrl()}/dashboard/project/${application.projectId}/services/application/${application.applicationId}?tab=deployments`;
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
@ -307,6 +309,11 @@ export const deployRemoteApplication = async ({
try { try {
if (application.serverId) { if (application.serverId) {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
let command = "set -e;"; let command = "set -e;";
if (application.sourceType === "github") { if (application.sourceType === "github") {
command += await getGithubCloneCommand({ command += await getGithubCloneCommand({
@ -373,12 +380,6 @@ export const deployRemoteApplication = async ({
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;
@ -396,6 +397,7 @@ export const deployPreviewApplication = async ({
previewDeploymentId: string; previewDeploymentId: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const deployment = await createDeploymentPreview({ const deployment = await createDeploymentPreview({
title: titleLog, title: titleLog,
description: descriptionLog, description: descriptionLog,
@ -452,6 +454,12 @@ export const deployPreviewApplication = async ({
application.env = application.previewEnv; application.env = application.previewEnv;
application.buildArgs = application.previewBuildArgs; application.buildArgs = application.previewBuildArgs;
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheOnPreviews) {
await cleanupFullDocker(application?.serverId);
}
if (application.sourceType === "github") { if (application.sourceType === "github") {
await cloneGithubRepository({ await cloneGithubRepository({
...application, ...application,
@ -461,7 +469,6 @@ export const deployPreviewApplication = async ({
}); });
await buildApplication(application, deployment.logPath); await buildApplication(application, deployment.logPath);
} }
// 4eef09efc46009187d668cf1c25f768d0bde4f91
const successComment = getIssueComment( const successComment = getIssueComment(
application.name, application.name,
"success", "success",
@ -486,12 +493,6 @@ export const deployPreviewApplication = async ({
previewStatus: "error", previewStatus: "error",
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheOnPreviews) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;
@ -509,6 +510,7 @@ export const deployRemotePreviewApplication = async ({
previewDeploymentId: string; previewDeploymentId: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const deployment = await createDeploymentPreview({ const deployment = await createDeploymentPreview({
title: titleLog, title: titleLog,
description: descriptionLog, description: descriptionLog,
@ -566,6 +568,11 @@ export const deployRemotePreviewApplication = async ({
application.buildArgs = application.previewBuildArgs; application.buildArgs = application.previewBuildArgs;
if (application.serverId) { if (application.serverId) {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheOnPreviews) {
await cleanupFullDocker(application?.serverId);
}
let command = "set -e;"; let command = "set -e;";
if (application.sourceType === "github") { if (application.sourceType === "github") {
command += await getGithubCloneCommand({ command += await getGithubCloneCommand({
@ -604,12 +611,6 @@ export const deployRemotePreviewApplication = async ({
previewStatus: "error", previewStatus: "error",
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheOnPreviews) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;
@ -625,6 +626,7 @@ export const rebuildRemoteApplication = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const application = await findApplicationById(applicationId); const application = await findApplicationById(applicationId);
const deployment = await createDeployment({ const deployment = await createDeployment({
applicationId: applicationId, applicationId: applicationId,
title: titleLog, title: titleLog,
@ -633,6 +635,11 @@ export const rebuildRemoteApplication = async ({
try { try {
if (application.serverId) { if (application.serverId) {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
if (application.sourceType !== "docker") { if (application.sourceType !== "docker") {
let command = "set -e;"; let command = "set -e;";
command += getBuildCommand(application, deployment.logPath); command += getBuildCommand(application, deployment.logPath);
@ -657,12 +664,6 @@ export const rebuildRemoteApplication = async ({
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
await updateApplicationStatus(applicationId, "error"); await updateApplicationStatus(applicationId, "error");
throw error; throw error;
} finally {
const admin = await findAdminById(application.project.adminId);
if (admin.cleanupCacheApplications) {
await cleanupFullDocker(application?.serverId);
}
} }
return true; return true;

View File

@ -206,6 +206,7 @@ export const deployCompose = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${ const buildLink = `${await getDokployUrl()}/dashboard/project/${
compose.projectId compose.projectId
}/services/compose/${compose.composeId}?tab=deployments`; }/services/compose/${compose.composeId}?tab=deployments`;
@ -216,6 +217,10 @@ export const deployCompose = async ({
}); });
try { try {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
if (compose.sourceType === "github") { if (compose.sourceType === "github") {
await cloneGithubRepository({ await cloneGithubRepository({
...compose, ...compose,
@ -260,11 +265,6 @@ export const deployCompose = async ({
adminId: compose.project.adminId, adminId: compose.project.adminId,
}); });
throw error; 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; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const deployment = await createDeploymentCompose({ const deployment = await createDeploymentCompose({
composeId: composeId, composeId: composeId,
title: titleLog, title: titleLog,
@ -285,6 +286,10 @@ export const rebuildCompose = async ({
}); });
try { try {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
if (compose.serverId) { if (compose.serverId) {
await getBuildComposeCommand(compose, deployment.logPath); await getBuildComposeCommand(compose, deployment.logPath);
} else { } else {
@ -301,11 +306,6 @@ export const rebuildCompose = async ({
composeStatus: "error", composeStatus: "error",
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
} }
return true; return true;
@ -321,6 +321,7 @@ export const deployRemoteCompose = async ({
descriptionLog: string; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const buildLink = `${await getDokployUrl()}/dashboard/project/${ const buildLink = `${await getDokployUrl()}/dashboard/project/${
compose.projectId compose.projectId
}/services/compose/${compose.composeId}?tab=deployments`; }/services/compose/${compose.composeId}?tab=deployments`;
@ -331,6 +332,10 @@ export const deployRemoteCompose = async ({
}); });
try { try {
if (compose.serverId) { if (compose.serverId) {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
let command = "set -e;"; let command = "set -e;";
if (compose.sourceType === "github") { if (compose.sourceType === "github") {
@ -404,11 +409,6 @@ export const deployRemoteCompose = async ({
adminId: compose.project.adminId, adminId: compose.project.adminId,
}); });
throw error; 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; descriptionLog: string;
}) => { }) => {
const compose = await findComposeById(composeId); const compose = await findComposeById(composeId);
const deployment = await createDeploymentCompose({ const deployment = await createDeploymentCompose({
composeId: composeId, composeId: composeId,
title: titleLog, title: titleLog,
@ -429,6 +430,10 @@ export const rebuildRemoteCompose = async ({
}); });
try { try {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
if (compose.serverId) { if (compose.serverId) {
await getBuildComposeCommand(compose, deployment.logPath); await getBuildComposeCommand(compose, deployment.logPath);
} }
@ -453,11 +458,6 @@ export const rebuildRemoteCompose = async ({
composeStatus: "error", composeStatus: "error",
}); });
throw error; throw error;
} finally {
const admin = await findAdminById(compose.project.adminId);
if (admin.cleanupCacheOnCompose) {
await cleanupFullDocker(compose?.serverId);
}
} }
return true; return true;