Skip to content

Comments

fix: use buildServerId for preview deployments#3781

Closed
kopandante wants to merge 1 commit intoDokploy:canaryfrom
kopandante:fix/preview-build-server
Closed

fix: use buildServerId for preview deployments#3781
kopandante wants to merge 1 commit intoDokploy:canaryfrom
kopandante:fix/preview-build-server

Conversation

@kopandante
Copy link

@kopandante kopandante commented Feb 23, 2026

Problem

Preview deployments always build on the application server (serverId), ignoring the configured build server (buildServerId). This is inconsistent with production deployments, which correctly use buildServerId || serverId.

This means users who set up a separate build server to offload resource-intensive builds still have preview builds running on their production server, potentially causing memory pressure and OOM issues.

Related issues: #3450

Root Cause

In packages/server/src/services/application.ts:

  • deployPreviewApplication() uses application.serverId directly
  • rebuildPreviewApplication() uses application.serverId in the try block (interestingly, the catch block already uses the correct application.buildServerId || application.serverId pattern)

In packages/server/src/services/deployment.ts:

  • createDeploymentPreview() uses previewDeployment.application.serverId for log path resolution and remote execution, and does not store buildServerId in the deployment record

Meanwhile, their production counterparts (deployApplication() and createDeployment()) correctly use the buildServerId || serverId fallback pattern.

Changes

packages/server/src/services/application.ts:

  • deployPreviewApplication(): resolve buildServerId || serverId before executing the build command remotely
  • rebuildPreviewApplication(): change const serverId = application.serverId to const serverId = application.buildServerId || application.serverId (aligns try block with existing catch block)

packages/server/src/services/deployment.ts:

  • createDeploymentPreview(): resolve buildServerId from the application, use it for paths(), findServerById(), and execAsyncRemote(). Store buildServerId in the deployment record (matching createDeployment() behavior)

Behavior

  • If buildServerId is configured: preview builds run on the build server
  • If buildServerId is not configured: no change, builds run on the application server (same as before)
  • Production deployments: unaffected

Testing

Tested on a Dokploy v0.27.0 instance with a separate build server configured. Preview deployments now correctly execute on the build server and logs are written to the correct remote path.

Greptile Summary

This PR correctly fixes preview deployments to respect the buildServerId configuration, aligning them with production deployment behavior. The changes ensure that when a separate build server is configured, preview builds execute on that server instead of incorrectly running on the application server.

Key changes:

  • deployPreviewApplication(): now resolves buildServerId || serverId before remote execution
  • rebuildPreviewApplication(): changed to use buildServerId || serverId consistently in both try and catch blocks
  • createDeploymentPreview(): resolves buildServerId for log paths, remote execution, and stores it in deployment records

Minor issue found:

  • Line 171 in deployment.ts still passes serverId to removeLastTenDeployments() instead of buildServerId, which could cause old logs to be cleaned up from the wrong server

Confidence Score: 4/5

  • This PR is safe to merge with one minor fix needed
  • The changes correctly implement buildServerId support for preview deployments and align well with the existing production deployment patterns. The logic is sound and the implementation is consistent. However, there's one logical issue at line 171 where old log cleanup uses serverId instead of buildServerId, which could cause logs to be deleted from the wrong server. This should be fixed before merging to ensure complete correctness.
  • Pay close attention to packages/server/src/services/deployment.ts line 171

Last reviewed commit: 1e56fe7

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Preview deployments now respect the buildServerId configuration,
matching the behavior of production deployments. Previously, preview
builds always ran on the application server (serverId), ignoring any
configured build server.

Changes:
- deployPreviewApplication: use buildServerId || serverId for build execution
- rebuildPreviewApplication: same fix (catch block already had it)
- createDeploymentPreview: resolve buildServerId for log path and remote exec,
  store buildServerId in deployment record

Fixes Dokploy#3450
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

await removeLastTenDeployments(
deployment.previewDeploymentId,
"previewDeployment",
previewDeployment?.application?.serverId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use buildServerId instead of serverId for consistency

old logs will be cleaned up from the wrong server if buildServerId is different from serverId

Suggested change
previewDeployment?.application?.serverId,
buildServerId,

@kopandante
Copy link
Author

Superseded by #3784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant