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.
This commit is contained in:
kopandante 2026-03-02 23:53:33 +09:00
parent c225188ed4
commit 9718fb4c2b
3 changed files with 27 additions and 11 deletions

View File

@ -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);

View File

@ -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]) {

View File

@ -33,6 +33,7 @@ export const findPreviewDeploymentById = async (
columns: {
applicationId: true,
serverId: true,
buildServerId: true,
},
},
},