From 5849102a40e18b7282a4f31a38982a535a10a24d Mon Sep 17 00:00:00 2001 From: Totopo27 <35828647+Totopo27@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:15:35 -0600 Subject: [PATCH] fix(deploy): preserve remote serverId in webhook deployment jobs --- .../deploy/github-webhook-handler.test.ts | 37 +++++++++++++++++++ .../pages/api/deploy/[refreshToken].ts | 2 +- .../api/deploy/compose/[refreshToken].ts | 2 +- apps/dokploy/pages/api/deploy/github.ts | 10 ++--- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts b/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts index 6b61c97d7..d552cd76f 100644 --- a/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts +++ b/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts @@ -323,6 +323,43 @@ describe("GitHub app webhook auto-deploy", () => { expect(res.status).toHaveBeenCalledWith(200); expect(res.json).toHaveBeenCalledWith({ message: "No apps to deploy" }); }); + + it("passes serverId to queued jobs for remote servers", async () => { + mocks.applicationsFindMany.mockImplementation(({ where }) => { + const matches = + getConditionValue(where, "application.sourceType") === "github" && + getConditionValue(where, "application.autoDeploy") === true && + getConditionValue(where, "application.triggerType") === "push" && + getConditionValue(where, "application.branch") === "main"; + + return Promise.resolve( + matches + ? [ + { + applicationId: "remote-app-id", + serverId: "remote-server-id", + watchPaths: null, + }, + ] + : [], + ); + }); + const res = createResponse(); + + await handler(createPushRequest("main"), res); + + expect(mocks.queueAdd).toHaveBeenCalledWith( + "deployments", + expect.objectContaining({ + applicationId: "remote-app-id", + applicationType: "application", + server: true, + serverId: "remote-server-id", + }), + expect.anything(), + ); + expect(res.status).toHaveBeenCalledWith(200); + }); }); describe("GitHub app webhook preview deployments", () => { diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index 988a344d4..a11a91486 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -275,10 +275,10 @@ export default async function handler( type: "deploy", applicationType: "application", server: !!application.serverId, + serverId: application.serverId ?? undefined, }; if (IS_CLOUD && application.serverId) { - jobData.serverId = application.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); diff --git a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts index 06b4e768d..dd0376c4d 100644 --- a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts @@ -198,10 +198,10 @@ export default async function handler( applicationType: "compose", descriptionLog: `Hash: ${deploymentHash}`, server: !!composeResult.serverId, + serverId: composeResult.serverId ?? undefined, }; if (IS_CLOUD && composeResult.serverId) { - jobData.serverId = composeResult.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index bb39ed7d5..756361d08 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -144,10 +144,10 @@ export default async function handler( type: "deploy", applicationType: "application", server: !!app.serverId, + serverId: app.serverId ?? undefined, }; if (IS_CLOUD && app.serverId) { - jobData.serverId = app.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); @@ -183,10 +183,10 @@ export default async function handler( applicationType: "compose", descriptionLog: `Hash: ${deploymentHash}`, server: !!composeApp.serverId, + serverId: composeApp.serverId ?? undefined, }; if (IS_CLOUD && composeApp.serverId) { - jobData.serverId = composeApp.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); @@ -257,6 +257,7 @@ export default async function handler( type: "deploy", applicationType: "application", server: !!app.serverId, + serverId: app.serverId ?? undefined, }; const shouldDeployPaths = shouldDeploy( @@ -269,7 +270,6 @@ export default async function handler( } if (IS_CLOUD && app.serverId) { - jobData.serverId = app.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); @@ -305,6 +305,7 @@ export default async function handler( applicationType: "compose", descriptionLog: `Hash: ${deploymentHash}`, server: !!composeApp.serverId, + serverId: composeApp.serverId ?? undefined, }; const shouldDeployPaths = shouldDeploy( @@ -316,7 +317,6 @@ export default async function handler( continue; } if (IS_CLOUD && composeApp.serverId) { - jobData.serverId = composeApp.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); }); @@ -526,12 +526,12 @@ export default async function handler( type: "deploy", applicationType: "application-preview", server: !!app.serverId, + serverId: app.serverId ?? undefined, previewDeploymentId, }; if (previewDeploymentId) { if (IS_CLOUD && app.serverId) { - jobData.serverId = app.serverId; deploy(jobData).catch((error) => { console.error("Background deployment failed:", error); });