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
65 changes: 65 additions & 0 deletions apps/dokploy/__test__/schedule/schedule-command-boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe("schedule command boundary", () => {
});
mocks.execAsyncRemote.mockResolvedValue({ stdout: "", stderr: "" });
mocks.getServiceContainer.mockResolvedValue({ Id: "container-one" });
mocks.spawnAsync.mockResolvedValue(undefined);
});

it("quotes remote application docker exec command and log paths", async () => {
Expand Down Expand Up @@ -119,6 +120,70 @@ describe("schedule command boundary", () => {
expect(command).toContain("tee -a '/tmp/deployment log;id.log'");
});

it("runs dokploy-server schedule scripts from the local schedule directory", async () => {
mocks.findScheduleById.mockResolvedValue({
appName: "schedule-one",
command: "",
shellType: "bash",
scheduleType: "dokploy-server",
});

await expect(runCommand("schedule-1")).resolves.toMatchObject({
deploymentId: "deployment-1",
status: "done",
});

expect(mocks.spawnAsync).toHaveBeenCalledTimes(1);
expect(mocks.spawnAsync).toHaveBeenCalledWith(
"bash",
["-c", "./script.sh"],
expect.any(Function),
{ cwd: "/local schedules/schedule-one" },
);
expect(mocks.execAsyncRemote).not.toHaveBeenCalled();
});

it("marks dokploy-server schedule runs as failed when the script fails", async () => {
mocks.findScheduleById.mockResolvedValue({
appName: "schedule-one",
command: "",
shellType: "bash",
scheduleType: "dokploy-server",
});
mocks.spawnAsync.mockRejectedValue(new Error("exit code 1"));

await expect(runCommand("schedule-1")).resolves.toMatchObject({
deploymentId: "deployment-1",
status: "error",
});
expect(mocks.updateDeploymentStatus).toHaveBeenCalledWith(
"deployment-1",
"error",
);
});

it("runs only the container command for application schedules", async () => {
mocks.findScheduleById.mockResolvedValue({
appName: "schedule-one",
application: { appName: "app-one", serverId: null },
command: "echo done",
shellType: "sh",
scheduleType: "application",
});

await expect(runCommand("schedule-1")).resolves.toMatchObject({
deploymentId: "deployment-1",
status: "done",
});

expect(mocks.spawnAsync).toHaveBeenCalledTimes(1);
expect(mocks.spawnAsync).toHaveBeenCalledWith(
"docker",
["exec", "container-one", "sh", "-c", "echo done"],
expect.any(Function),
);
});

it("rejects unsafe stored schedule app names before remote script execution", async () => {
mocks.findScheduleById.mockResolvedValue({
appName: "schedule;id",
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/utils/schedules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const runCommand = async (scheduleId: string) => {
throw error;
}
}
} else if (scheduleType === "dokploy-server") {
const writeStream = createWriteStream(deployment.logPath, { flags: "a" });
const { SCHEDULES_PATH } = paths();
const fullPath = getScheduleDirectory(SCHEDULES_PATH, appName);
Expand Down
Loading