From 9718fb4c2b4fcebf9593dd5807540f69cc28b050 Mon Sep 17 00:00:00 2001 From: kopandante Date: Mon, 2 Mar 2026 23:53:33 +0900 Subject: [PATCH] fix: use buildServerId for preview deployment build and service creation Preview deployments ignored the buildServerId configuration, causing four issues when a separate build server was configured: 1. buildRegistry was unconditionally nulled, breaking registry auth for image push/pull between build and deploy servers 2. Build commands ran on serverId instead of buildServerId, so the build executed on the deploy server instead of the build server 3. docker.createService() did not pass authconfig as a separate argument (unlike service.update()), so Swarm could not pull images from authenticated registries 4. Log directory was created on the deploy server while the build ran on the build server, causing "file not found" errors These fixes align preview deployment behavior with the regular deployment flow (deployApplication/rebuildApplication) which already correctly uses buildServerId. --- packages/server/src/services/application.ts | 21 ++++++++++++++----- packages/server/src/services/deployment.ts | 16 ++++++++------ .../server/src/services/preview-deployment.ts | 1 + 3 files changed, 27 insertions(+), 11 deletions(-) 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, }, }, },