Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/dokploy/__test__/deploy/github-webhook-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dokploy/pages/api/deploy/[refreshToken].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion apps/dokploy/pages/api/deploy/compose/[refreshToken].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
10 changes: 5 additions & 5 deletions apps/dokploy/pages/api/deploy/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -257,6 +257,7 @@ export default async function handler(
type: "deploy",
applicationType: "application",
server: !!app.serverId,
serverId: app.serverId ?? undefined,
};

const shouldDeployPaths = shouldDeploy(
Expand All @@ -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);
});
Expand Down Expand Up @@ -305,6 +305,7 @@ export default async function handler(
applicationType: "compose",
descriptionLog: `Hash: ${deploymentHash}`,
server: !!composeApp.serverId,
serverId: composeApp.serverId ?? undefined,
};

const shouldDeployPaths = shouldDeploy(
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
Loading