fix: use buildServerId for preview deployment build and service creation#3863
fix: use buildServerId for preview deployment build and service creation#3863kopandante wants to merge 2 commits intoDokploy:canaryfrom
Conversation
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.
Additional Comments (6)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Summary
Preview deployments ignore the
buildServerIdconfiguration, causing failures when a separate build server is configured. This PR fixes four bugs:Bug 1 —
buildRegistryunconditionally nulled (application.ts)Both
deployPreviewApplicationandrebuildPreviewApplicationsetapplication.buildRegistry = nullunconditionally. When a separate build server is configured,buildRegistryprovides the registry credentials needed to push/pull images between servers. Nulling it breaksgetAuthConfig()andgetImageName()inmechanizeDockerContainer.Fix: Only null
buildRegistrywhen there is no separate build server (!buildServerId || buildServerId === serverId), matching the regular deploy flow wheremechanizeDockerContainer(application)receives the original application withbuildRegistryintact.Bug 2 — Build runs on deploy server instead of build server (
application.ts)deployPreviewApplicationusesapplication.serverIdforexecAsyncRemote, andrebuildPreviewApplicationassignsconst serverId = application.serverId. Both ignorebuildServerId.Fix: Use
application.buildServerId || application.serverId, consistent withdeployApplication(L178) andrebuildApplication(L296).Bug 3 —
createServicedoesn't pass auth (builders/index.ts)docker.createService(settings)does not extractauthconfigfrom the settings object. In contrast,service.update(opts)does extractopts.authconfig. This means newly created Swarm services cannot pull from authenticated registries.Fix:
docker.createService(settings.authconfig, settings)— pass auth as the first argument per the dockerode API signature.Bug 4 — Log directory created on wrong server (
deployment.ts)createDeploymentPreviewusespreviewDeployment.application.serverIdforpaths(),findServerById(), andexecAsyncRemote(). The log directory is created on the deploy server, but the build command runs on the build server, causing "file not found" errors.Fix: Use
buildServerId || serverId, consistent withcreateDeployment(L87).Context
All four bugs only manifest when
buildServerIdis configured (separate build server). The regular deployment flow (deployApplication,rebuildApplication,createDeployment) already handles this correctly — preview deployments were simply never updated to use the same pattern.These fixes are verified in production on our Dokploy instance (v0.27.1 with equivalent chunk patches) running 21 applications across two servers.
Supersedes #3784 (which mixed these fixes with unrelated changes).
Test plan
Greptile Summary
This PR correctly fixes preview deployments to respect
buildServerIdconfiguration, making them consistent with the regular deployment flow. The changes properly handle:buildRegistrycredentials when using separate build serversHowever, the change to
docker.createService(settings.authconfig, settings)inbuilders/index.ts:185requires updating the test mocks and assertions inmechanizeDockerContainer.test.ts, as they currently expect a single-parameter call.Confidence Score: 3/5
createServicecall. Once tests are fixed, this should work correctly.apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts- all test cases need updating to handle the newcreateServicesignatureLast reviewed commit: 40a68b0
(5/5) You can turn off certain types of comments like style here!