diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index 0f2e5a4fc..72239038c 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -429,10 +429,16 @@ export const deployPreviewApplication = async ({ application.buildArgs = `${application.previewBuildArgs}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`; application.buildSecrets = `${application.previewBuildSecrets}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`; application.rollbackActive = false; - application.buildRegistry = null; + if ( + !application.buildServerId || + application.buildServerId === application.serverId + ) { + application.buildRegistry = null; + } application.rollbackRegistry = null; application.registry = null; + const buildServerId = application.buildServerId || application.serverId; let command = "set -e;"; if (application.sourceType === "github") { command += await cloneGithubRepository({ @@ -443,8 +449,8 @@ export const deployPreviewApplication = async ({ command += await getBuildCommand(application); const commandWithLog = `(${command}) >> ${deployment.logPath} 2>&1`; - if (application.serverId) { - await execAsyncRemote(application.serverId, commandWithLog); + if (buildServerId) { + await execAsyncRemote(buildServerId, commandWithLog); } else { await execAsync(commandWithLog); } @@ -548,11 +554,16 @@ export const rebuildPreviewApplication = async ({ application.buildArgs = `${application.previewBuildArgs}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`; application.buildSecrets = `${application.previewBuildSecrets}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`; application.rollbackActive = false; - application.buildRegistry = null; + if ( + !application.buildServerId || + application.buildServerId === application.serverId + ) { + application.buildRegistry = null; + } application.rollbackRegistry = null; application.registry = null; - const serverId = application.serverId; + const serverId = application.buildServerId || application.serverId; let command = "set -e;"; // Only rebuild, don't clone repository command += await getBuildCommand(application); diff --git a/packages/server/src/services/deployment.ts b/packages/server/src/services/deployment.ts index fd61fc106..732b84cf6 100644 --- a/packages/server/src/services/deployment.ts +++ b/packages/server/src/services/deployment.ts @@ -210,22 +210,23 @@ export const createDeploymentPreview = async ( const previewDeployment = await findPreviewDeploymentById( deployment.previewDeploymentId, ); + const buildServerId = + previewDeployment?.application?.buildServerId || + previewDeployment?.application?.serverId; await removeLastTenDeployments( deployment.previewDeploymentId, "previewDeployment", - previewDeployment?.application?.serverId, + buildServerId, ); try { const appName = `${previewDeployment.appName}`; - const { LOGS_PATH } = paths(!!previewDeployment?.application?.serverId); + const { LOGS_PATH } = paths(!!buildServerId); const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss"); const fileName = `${appName}-${formattedDateTime}.log`; const logFilePath = path.join(LOGS_PATH, appName, fileName); - if (previewDeployment?.application?.serverId) { - const server = await findServerById( - previewDeployment?.application?.serverId, - ); + if (buildServerId) { + const server = await findServerById(buildServerId); const command = ` mkdir -p ${LOGS_PATH}/${appName}; @@ -249,6 +250,9 @@ export const createDeploymentPreview = async ( description: deployment.description || "", previewDeploymentId: deployment.previewDeploymentId, startedAt: new Date().toISOString(), + ...(previewDeployment?.application?.buildServerId && { + buildServerId: previewDeployment.application.buildServerId, + }), }) .returning(); if (deploymentCreate.length === 0 || !deploymentCreate[0]) { diff --git a/packages/server/src/services/preview-deployment.ts b/packages/server/src/services/preview-deployment.ts index cc3d3dc02..9bbc46232 100644 --- a/packages/server/src/services/preview-deployment.ts +++ b/packages/server/src/services/preview-deployment.ts @@ -33,6 +33,7 @@ export const findPreviewDeploymentById = async ( columns: { applicationId: true, serverId: true, + buildServerId: true, }, }, },