mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-18 13:45:23 +02:00
Compare commits
2 Commits
v0.25.11
...
feat/add-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1379b2118f | ||
|
|
794cd79973 |
@@ -46,7 +46,7 @@ COPY --from=build /prod/dokploy/node_modules ./node_modules
|
||||
|
||||
|
||||
# Install docker
|
||||
RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh --version 28.5.2 && rm get-docker.sh && curl https://rclone.org/install.sh | bash
|
||||
RUN curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && rm get-docker.sh && curl https://rclone.org/install.sh | bash
|
||||
|
||||
# Install Nixpacks and tsx
|
||||
# | VERBOSE=1 VERSION=1.21.0 bash
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
DATABASE_URL="postgres://dokploy:amukds4wi9001583845717ad2@localhost:5432/dokploy"
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
NODE_ENV=development
|
||||
311
apps/dokploy/__test__/env/environment.test.ts
vendored
311
apps/dokploy/__test__/env/environment.test.ts
vendored
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
prepareEnvironmentVariables,
|
||||
prepareEnvironmentVariablesForShell,
|
||||
} from "@dokploy/server/index";
|
||||
import { prepareEnvironmentVariables } from "@dokploy/server/index";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const projectEnv = `
|
||||
@@ -335,310 +332,4 @@ IS_DEV=\${{environment.DEVELOPMENT}}
|
||||
"IS_DEV=0",
|
||||
]);
|
||||
});
|
||||
|
||||
it("handles environment variables with single quotes in values", () => {
|
||||
const envWithSingleQuotes = `
|
||||
ENV_VARIABLE='ENVITONME'NT'
|
||||
ANOTHER_VAR='value with 'quotes' inside'
|
||||
SIMPLE_VAR=no-quotes
|
||||
`;
|
||||
|
||||
const serviceWithSingleQuotes = `
|
||||
TEST_VAR=\${{environment.ENV_VARIABLE}}
|
||||
ANOTHER_TEST=\${{environment.ANOTHER_VAR}}
|
||||
SIMPLE=\${{environment.SIMPLE_VAR}}
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariables(
|
||||
serviceWithSingleQuotes,
|
||||
"",
|
||||
envWithSingleQuotes,
|
||||
);
|
||||
|
||||
expect(resolved).toEqual([
|
||||
"TEST_VAR=ENVITONME'NT",
|
||||
"ANOTHER_TEST=value with 'quotes' inside",
|
||||
"SIMPLE=no-quotes",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("prepareEnvironmentVariablesForShell (shell escaping)", () => {
|
||||
it("escapes single quotes in environment variable values", () => {
|
||||
const serviceEnv = `
|
||||
ENV_VARIABLE='ENVITONME'NT'
|
||||
ANOTHER_VAR='value with 'quotes' inside'
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// shell-quote should wrap these in double quotes
|
||||
expect(resolved).toEqual([
|
||||
`"ENV_VARIABLE=ENVITONME'NT"`,
|
||||
`"ANOTHER_VAR=value with 'quotes' inside"`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("escapes double quotes in environment variable values", () => {
|
||||
const serviceEnv = `
|
||||
MESSAGE="Hello "World""
|
||||
QUOTED_PATH="/path/to/"file""
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// shell-quote wraps in single quotes when there are double quotes inside
|
||||
expect(resolved).toEqual([
|
||||
`'MESSAGE=Hello "World"'`,
|
||||
`'QUOTED_PATH=/path/to/"file"'`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("escapes dollar signs in environment variable values", () => {
|
||||
const serviceEnv = `
|
||||
PRICE=$100
|
||||
VARIABLE=$HOME/path
|
||||
TEMPLATE=Hello $USER
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// Dollar signs should be escaped to prevent variable expansion
|
||||
for (const env of resolved) {
|
||||
expect(env).toContain("$");
|
||||
}
|
||||
});
|
||||
|
||||
it("escapes backticks in environment variable values", () => {
|
||||
const serviceEnv = `
|
||||
COMMAND=\`echo "test"\`
|
||||
NESTED=value with \`backticks\` inside
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// Backticks are escaped/removed by dotenv parsing, but values should be safely quoted
|
||||
expect(resolved.length).toBe(2);
|
||||
expect(resolved[0]).toContain("COMMAND");
|
||||
expect(resolved[1]).toContain("NESTED");
|
||||
});
|
||||
|
||||
it("handles environment variables with spaces", () => {
|
||||
const serviceEnv = `
|
||||
FULL_NAME="John Doe"
|
||||
MESSAGE='Hello World'
|
||||
SENTENCE=This is a test
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// shell-quote uses single quotes for strings with spaces
|
||||
expect(resolved).toEqual([
|
||||
`'FULL_NAME=John Doe'`,
|
||||
`'MESSAGE=Hello World'`,
|
||||
`'SENTENCE=This is a test'`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("handles environment variables with backslashes", () => {
|
||||
const serviceEnv = `
|
||||
WINDOWS_PATH=C:\\Users\\Documents
|
||||
ESCAPED=value\\with\\backslashes
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// Backslashes should be properly escaped
|
||||
expect(resolved.length).toBe(2);
|
||||
for (const env of resolved) {
|
||||
expect(env).toContain("\\");
|
||||
}
|
||||
});
|
||||
|
||||
it("handles simple environment variables without special characters", () => {
|
||||
const serviceEnv = `
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
DEBUG=true
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// shell-quote escapes the = sign in some cases
|
||||
expect(resolved).toEqual([
|
||||
"NODE_ENV\\=production",
|
||||
"PORT\\=3000",
|
||||
"DEBUG\\=true",
|
||||
]);
|
||||
});
|
||||
|
||||
it("handles environment variables with mixed special characters", () => {
|
||||
const serviceEnv = `
|
||||
COMPLEX='value with "double" and 'single' quotes'
|
||||
BASH_COMMAND=echo "$HOME" && echo 'test'
|
||||
WEIRD=\`echo "$VAR"\` with 'quotes' and "more"
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// All should be escaped, none should throw errors
|
||||
expect(resolved.length).toBe(3);
|
||||
// Verify each can be safely used in shell
|
||||
for (const env of resolved) {
|
||||
expect(typeof env).toBe("string");
|
||||
expect(env.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("handles environment variables with newlines", () => {
|
||||
const serviceEnv = `
|
||||
MULTILINE="line1
|
||||
line2
|
||||
line3"
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(1);
|
||||
expect(resolved[0]).toContain("MULTILINE");
|
||||
});
|
||||
|
||||
it("handles empty environment variable values", () => {
|
||||
const serviceEnv = `
|
||||
EMPTY=
|
||||
EMPTY_QUOTED=""
|
||||
EMPTY_SINGLE=''
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
// shell-quote escapes the = sign for empty values
|
||||
expect(resolved).toEqual([
|
||||
"EMPTY\\=",
|
||||
"EMPTY_QUOTED\\=",
|
||||
"EMPTY_SINGLE\\=",
|
||||
]);
|
||||
});
|
||||
|
||||
it("handles environment variables with equals signs in values", () => {
|
||||
const serviceEnv = `
|
||||
EQUATION=a=b+c
|
||||
CONNECTION_STRING=user=admin;password=test
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(2);
|
||||
expect(resolved[0]).toContain("EQUATION");
|
||||
expect(resolved[1]).toContain("CONNECTION_STRING");
|
||||
});
|
||||
|
||||
it("resolves and escapes environment variables together", () => {
|
||||
const projectEnv = `
|
||||
BASE_URL=https://example.com
|
||||
API_KEY='secret-key-with-quotes'
|
||||
`;
|
||||
|
||||
const environmentEnv = `
|
||||
ENV_NAME=production
|
||||
DB_PASS='pa$$word'
|
||||
`;
|
||||
|
||||
const serviceEnv = `
|
||||
FULL_URL=\${{project.BASE_URL}}/api
|
||||
AUTH_KEY=\${{project.API_KEY}}
|
||||
ENVIRONMENT=\${{environment.ENV_NAME}}
|
||||
DB_PASSWORD=\${{environment.DB_PASS}}
|
||||
CUSTOM='value with 'quotes' inside'
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(
|
||||
serviceEnv,
|
||||
projectEnv,
|
||||
environmentEnv,
|
||||
);
|
||||
|
||||
expect(resolved.length).toBe(5);
|
||||
// All resolved values should be properly escaped
|
||||
for (const env of resolved) {
|
||||
expect(typeof env).toBe("string");
|
||||
}
|
||||
});
|
||||
|
||||
it("handles environment variables with semicolons and ampersands", () => {
|
||||
const serviceEnv = `
|
||||
COMMAND=echo "test" && echo "test2"
|
||||
MULTIPLE=cmd1; cmd2; cmd3
|
||||
URL_WITH_PARAMS=https://example.com?a=1&b=2&c=3
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(3);
|
||||
// These should be safely escaped to prevent command injection
|
||||
for (const env of resolved) {
|
||||
expect(typeof env).toBe("string");
|
||||
expect(env.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("handles environment variables with pipes and redirects", () => {
|
||||
const serviceEnv = `
|
||||
PIPE_COMMAND=cat file | grep test
|
||||
REDIRECT=echo "test" > output.txt
|
||||
BOTH=cat input.txt | grep pattern > output.txt
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(3);
|
||||
// Pipes and redirects should be safely quoted
|
||||
expect(resolved[0]).toContain("PIPE_COMMAND");
|
||||
expect(resolved[1]).toContain("REDIRECT");
|
||||
expect(resolved[2]).toContain("BOTH");
|
||||
// At least one should contain a pipe
|
||||
const hasPipe = resolved.some((env) => env.includes("|"));
|
||||
expect(hasPipe).toBe(true);
|
||||
});
|
||||
|
||||
it("handles environment variables with parentheses and brackets", () => {
|
||||
const serviceEnv = `
|
||||
MATH=(a+b)*c
|
||||
ARRAY=[1,2,3]
|
||||
JSON={"key":"value"}
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(3);
|
||||
expect(resolved[0]).toContain("(");
|
||||
expect(resolved[1]).toContain("[");
|
||||
expect(resolved[2]).toContain("{");
|
||||
});
|
||||
|
||||
it("handles very long environment variable values", () => {
|
||||
const longValue = "a".repeat(10000);
|
||||
const serviceEnv = `LONG_VAR=${longValue}`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(1);
|
||||
expect(resolved[0]).toContain("LONG_VAR");
|
||||
expect(resolved[0]?.length).toBeGreaterThan(10000);
|
||||
});
|
||||
|
||||
it("handles special unicode characters in environment variables", () => {
|
||||
const serviceEnv = `
|
||||
EMOJI=Hello 🌍 World 🚀
|
||||
CHINESE=你好世界
|
||||
SPECIAL=café résumé naïve
|
||||
`;
|
||||
|
||||
const resolved = prepareEnvironmentVariablesForShell(serviceEnv, "", "");
|
||||
|
||||
expect(resolved.length).toBe(3);
|
||||
expect(resolved[0]).toContain("🌍");
|
||||
expect(resolved[1]).toContain("你好");
|
||||
expect(resolved[2]).toContain("café");
|
||||
});
|
||||
});
|
||||
|
||||
809
apps/dokploy/__test__/queues/grouped-queue.test.ts
Normal file
809
apps/dokploy/__test__/queues/grouped-queue.test.ts
Normal file
@@ -0,0 +1,809 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { GroupedQueue } from "../../server/queues/grouped-queue-wrapper";
|
||||
|
||||
describe("GroupedQueue", () => {
|
||||
describe("Basic functionality", () => {
|
||||
it("should process a single job with concurrency 1", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
await queue.add("group1", { id: "job1" });
|
||||
|
||||
// Wait for processing to complete
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(processed).toEqual(["job1"]);
|
||||
expect(queue.isIdle()).toBe(true);
|
||||
});
|
||||
|
||||
it("should process jobs in FIFO order within a group", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add multiple jobs to the same group
|
||||
await Promise.all([
|
||||
queue.add("group1", { id: "job1" }),
|
||||
queue.add("group1", { id: "job2" }),
|
||||
queue.add("group1", { id: "job3" }),
|
||||
]);
|
||||
|
||||
// Wait for all processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
expect(processed).toEqual(["job1", "job2", "job3"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Concurrency 1 with multiple groups", () => {
|
||||
it("should process one group at a time with concurrency 1", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; group: string }>(1);
|
||||
const processed: string[] = [];
|
||||
const activeGroups: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
activeGroups.push(data.group);
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
activeGroups.pop();
|
||||
});
|
||||
|
||||
// Add jobs to 3 different groups
|
||||
const promises = [
|
||||
queue.add("app1", { id: "job1", group: "app1" }),
|
||||
queue.add("app2", { id: "job2", group: "app2" }),
|
||||
queue.add("app3", { id: "job3", group: "app3" }),
|
||||
];
|
||||
|
||||
// Check after 30ms - only one should be processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
expect(activeGroups.length).toBeLessThanOrEqual(1);
|
||||
|
||||
// Wait for all to complete
|
||||
await Promise.all(promises);
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
expect(processed).toHaveLength(3);
|
||||
expect(queue.isIdle()).toBe(true);
|
||||
});
|
||||
|
||||
it("should process groups sequentially with concurrency 1", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; group: string }>(1);
|
||||
const processingOrder: string[] = [];
|
||||
const startTimes: Map<string, number> = new Map();
|
||||
const endTimes: Map<string, number> = new Map();
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
startTimes.set(data.id, Date.now());
|
||||
processingOrder.push(`start-${data.group}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
endTimes.set(data.id, Date.now());
|
||||
processingOrder.push(`end-${data.group}`);
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", group: "app1" }),
|
||||
queue.add("app2", { id: "job2", group: "app2" }),
|
||||
queue.add("app3", { id: "job3", group: "app3" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Verify sequential processing
|
||||
expect(processingOrder).toEqual([
|
||||
"start-app1",
|
||||
"end-app1",
|
||||
"start-app2",
|
||||
"end-app2",
|
||||
"start-app3",
|
||||
"end-app3",
|
||||
]);
|
||||
|
||||
// Verify jobs don't overlap
|
||||
const job1End = endTimes.get("job1")!;
|
||||
const job2Start = startTimes.get("job2")!;
|
||||
const job2End = endTimes.get("job2")!;
|
||||
const job3Start = startTimes.get("job3")!;
|
||||
|
||||
expect(job2Start).toBeGreaterThanOrEqual(job1End);
|
||||
expect(job3Start).toBeGreaterThanOrEqual(job2End);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Concurrency 3 with 4 groups", () => {
|
||||
it("should process up to 3 groups simultaneously", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; group: string }>(3);
|
||||
const activeGroups = new Set<string>();
|
||||
const maxConcurrent = { value: 0 };
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
activeGroups.add(data.group);
|
||||
maxConcurrent.value = Math.max(maxConcurrent.value, activeGroups.size);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
activeGroups.delete(data.group);
|
||||
});
|
||||
|
||||
// Add 4 jobs to different groups
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", group: "app1" }),
|
||||
queue.add("app2", { id: "job2", group: "app2" }),
|
||||
queue.add("app3", { id: "job3", group: "app3" }),
|
||||
queue.add("app4", { id: "job4", group: "app4" }),
|
||||
]);
|
||||
|
||||
// Check during processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
// Should have processed 3 groups simultaneously
|
||||
expect(maxConcurrent.value).toBe(3);
|
||||
expect(activeGroups.size).toBeLessThanOrEqual(3);
|
||||
|
||||
// Wait for all to complete
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
expect(queue.isIdle()).toBe(true);
|
||||
});
|
||||
|
||||
it("should process 4th group after one of the first 3 completes", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; group: string }>(3);
|
||||
const processingOrder: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
processingOrder.push(`start-${data.group}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
processingOrder.push(`end-${data.group}`);
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", group: "app1" }),
|
||||
queue.add("app2", { id: "job2", group: "app2" }),
|
||||
queue.add("app3", { id: "job3", group: "app3" }),
|
||||
queue.add("app4", { id: "job4", group: "app4" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
|
||||
// First 3 should start together
|
||||
const firstThree = processingOrder.slice(0, 3);
|
||||
expect(firstThree).toContain("start-app1");
|
||||
expect(firstThree).toContain("start-app2");
|
||||
expect(firstThree).toContain("start-app3");
|
||||
|
||||
// 4th should start after one completes
|
||||
const app4StartIndex = processingOrder.indexOf("start-app4");
|
||||
expect(app4StartIndex).toBeGreaterThan(0);
|
||||
expect(app4StartIndex).toBeLessThan(processingOrder.length - 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Multiple jobs per group", () => {
|
||||
it("should process jobs sequentially within same group", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(3);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add 3 jobs to same group
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1" }),
|
||||
queue.add("app1", { id: "job2" }),
|
||||
queue.add("app1", { id: "job3" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
// Should process in order
|
||||
expect(processed).toEqual(["job1", "job2", "job3"]);
|
||||
});
|
||||
|
||||
it("should process multiple groups with multiple jobs each", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; group: string }>(2);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
processed.push(`${data.group}-${data.id}`);
|
||||
});
|
||||
|
||||
// Add jobs to 2 groups, 2 jobs each
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", group: "app1" }),
|
||||
queue.add("app1", { id: "job2", group: "app1" }),
|
||||
queue.add("app2", { id: "job1", group: "app2" }),
|
||||
queue.add("app2", { id: "job2", group: "app2" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
// Should process both groups, jobs within each group in order
|
||||
expect(processed).toHaveLength(4);
|
||||
expect(processed.filter((p) => p.startsWith("app1"))).toEqual([
|
||||
"app1-job1",
|
||||
"app1-job2",
|
||||
]);
|
||||
expect(processed.filter((p) => p.startsWith("app2"))).toEqual([
|
||||
"app2-job1",
|
||||
"app2-job2",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Error handling", () => {
|
||||
it("should reject job on handler error", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
|
||||
queue.setHandler(async () => {
|
||||
throw new Error("Test error");
|
||||
});
|
||||
|
||||
await expect(queue.add("group1", { id: "job1" })).rejects.toThrow(
|
||||
"Test error",
|
||||
);
|
||||
});
|
||||
|
||||
it("should continue processing other jobs after error", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
if (data.id === "job2") {
|
||||
throw new Error("Job 2 error");
|
||||
}
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
await expect(
|
||||
queue.add("group1", { id: "job1" }),
|
||||
).resolves.toBeUndefined();
|
||||
await expect(queue.add("group1", { id: "job2" })).rejects.toThrow();
|
||||
await expect(
|
||||
queue.add("group1", { id: "job3" }),
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(processed).toEqual(["job1", "job3"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Queue management", () => {
|
||||
it("should clear group tasks", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs without awaiting - they'll start processing
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
|
||||
// Clear immediately - job1 might be processing, but job2 should be cleared
|
||||
queue.clearGroup("group1");
|
||||
|
||||
// Use Promise.allSettled to handle both promises properly
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 might succeed or fail depending on timing
|
||||
// job2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe("Queue cleared");
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Job1 might have processed, but job2 should not
|
||||
expect(processed.length).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("should return correct group length", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
|
||||
queue.setHandler(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Add jobs without awaiting - check length immediately
|
||||
const promises = [
|
||||
queue.add("group1", { id: "job1" }),
|
||||
queue.add("group1", { id: "job2" }),
|
||||
queue.add("group1", { id: "job3" }),
|
||||
];
|
||||
|
||||
// Check length immediately - at least some should be pending
|
||||
// (job1 might be processing, but job2 and job3 should be pending)
|
||||
const length = queue.getGroupLength("group1");
|
||||
expect(length).toBeGreaterThanOrEqual(0);
|
||||
|
||||
// Wait for all to complete
|
||||
await Promise.all(promises);
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
// After processing should be 0
|
||||
expect(queue.getGroupLength("group1")).toBe(0);
|
||||
});
|
||||
|
||||
it("should close queue and reject pending tasks", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
|
||||
queue.setHandler(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Add first job and wait a bit to ensure it starts processing
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
// Add second job without awaiting
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
|
||||
// Wait a tiny bit to ensure job2 is queued
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Close queue - job2 should be rejected
|
||||
await queue.close();
|
||||
|
||||
// Use Promise.allSettled to handle both promises properly
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 might succeed or fail depending on timing
|
||||
// job2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe("Queue closed");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Concurrency edge cases", () => {
|
||||
it("should handle concurrency 1 with 1 app correctly", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
await queue.add("app1", { id: "job1" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(processed).toEqual(["job1"]);
|
||||
expect(queue.getActiveGroupsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("should handle concurrency 1 with 3 apps correctly", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; app: string }>(1);
|
||||
const processingTimes: Map<string, { start: number; end: number }> =
|
||||
new Map();
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
const start = Date.now();
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
const end = Date.now();
|
||||
processingTimes.set(data.app, { start, end });
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", app: "app1" }),
|
||||
queue.add("app2", { id: "job2", app: "app2" }),
|
||||
queue.add("app3", { id: "job3", app: "app3" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Verify sequential processing
|
||||
const app1 = processingTimes.get("app1")!;
|
||||
const app2 = processingTimes.get("app2")!;
|
||||
const app3 = processingTimes.get("app3")!;
|
||||
|
||||
expect(app2.start).toBeGreaterThanOrEqual(app1.end);
|
||||
expect(app3.start).toBeGreaterThanOrEqual(app2.end);
|
||||
expect(queue.getActiveGroupsCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("should handle 4 apps with concurrency 3 correctly", async () => {
|
||||
const queue = new GroupedQueue<{ id: string; app: string }>(3);
|
||||
const concurrentCounts: number[] = [];
|
||||
|
||||
queue.setHandler(async () => {
|
||||
// Track concurrent processing
|
||||
const interval = setInterval(() => {
|
||||
concurrentCounts.push(queue.getActiveGroupsCount());
|
||||
}, 10);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
clearInterval(interval);
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
queue.add("app1", { id: "job1", app: "app1" }),
|
||||
queue.add("app2", { id: "job2", app: "app2" }),
|
||||
queue.add("app3", { id: "job3", app: "app3" }),
|
||||
queue.add("app4", { id: "job4", app: "app4" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
// Should never exceed concurrency of 3
|
||||
const maxConcurrent = Math.max(...concurrentCounts);
|
||||
expect(maxConcurrent).toBeLessThanOrEqual(3);
|
||||
expect(queue.getActiveGroupsCount()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Idle state", () => {
|
||||
it("should be idle when no jobs are processing", () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
expect(queue.isIdle()).toBe(true);
|
||||
});
|
||||
|
||||
it("should not be idle while processing", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
let isIdleDuringProcessing = false;
|
||||
|
||||
queue.setHandler(async () => {
|
||||
isIdleDuringProcessing = queue.isIdle();
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
});
|
||||
|
||||
await queue.add("group1", { id: "job1" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
|
||||
expect(isIdleDuringProcessing).toBe(false);
|
||||
expect(queue.isIdle()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Concurrency management", () => {
|
||||
it("should get current concurrency", () => {
|
||||
const queue1 = new GroupedQueue<{ id: string }>(1);
|
||||
const queue2 = new GroupedQueue<{ id: string }>(5);
|
||||
const queue3 = new GroupedQueue<{ id: string }>(10);
|
||||
|
||||
expect(queue1.getConcurrency()).toBe(1);
|
||||
expect(queue2.getConcurrency()).toBe(5);
|
||||
expect(queue3.getConcurrency()).toBe(10);
|
||||
});
|
||||
|
||||
it("should set concurrency dynamically", () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
expect(queue.getConcurrency()).toBe(1);
|
||||
|
||||
queue.setConcurrency(3);
|
||||
expect(queue.getConcurrency()).toBe(3);
|
||||
|
||||
queue.setConcurrency(5);
|
||||
expect(queue.getConcurrency()).toBe(5);
|
||||
});
|
||||
|
||||
it("should throw error when setting concurrency less than 1", () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
expect(() => queue.setConcurrency(0)).toThrow(
|
||||
"Concurrency must be at least 1",
|
||||
);
|
||||
expect(() => queue.setConcurrency(-1)).toThrow(
|
||||
"Concurrency must be at least 1",
|
||||
);
|
||||
});
|
||||
|
||||
it("should process next group when concurrency increases", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs to 3 different groups with concurrency 1
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group2", { id: "job2" });
|
||||
const job3Promise = queue.add("group3", { id: "job3" });
|
||||
|
||||
// Wait a bit to ensure job1 starts processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Increase concurrency to 3 - should allow group2 and group3 to start
|
||||
queue.setConcurrency(3);
|
||||
|
||||
// Wait for all to complete
|
||||
await Promise.all([job1Promise, job2Promise, job3Promise]);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(processed).toHaveLength(3);
|
||||
expect(processed).toContain("job1");
|
||||
expect(processed).toContain("job2");
|
||||
expect(processed).toContain("job3");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Clear all pending tasks", () => {
|
||||
it("should clear all pending tasks across all groups", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add multiple jobs to different groups
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
const job3Promise = queue.add("group2", { id: "job3" });
|
||||
const job4Promise = queue.add("group2", { id: "job4" });
|
||||
const job5Promise = queue.add("group3", { id: "job5" });
|
||||
|
||||
// Wait a bit to ensure job1 starts processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Clear all pending tasks
|
||||
const clearedCount = queue.clearAllPendingTasks();
|
||||
|
||||
// Should have cleared 4 pending tasks (job2, job3, job4, job5)
|
||||
// job1 is processing so it's not in the queue anymore
|
||||
expect(clearedCount).toBe(4);
|
||||
|
||||
// Handle all promises
|
||||
const results = await Promise.allSettled([
|
||||
job1Promise,
|
||||
job2Promise,
|
||||
job3Promise,
|
||||
job4Promise,
|
||||
job5Promise,
|
||||
]);
|
||||
|
||||
// job1 should succeed (it was processing)
|
||||
const job1Result = results[0];
|
||||
expect(job1Result.status).toBe("fulfilled");
|
||||
|
||||
// All pending jobs should be rejected
|
||||
for (let i = 1; i < results.length; i++) {
|
||||
const result = results[i];
|
||||
if (result && result.status === "rejected") {
|
||||
expect(result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for job1 to complete
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
// Only job1 should have processed
|
||||
expect(processed).toHaveLength(1);
|
||||
expect(processed).toContain("job1");
|
||||
});
|
||||
|
||||
it("should not clear tasks that are currently processing", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs - first one will start processing immediately
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
|
||||
// Wait to ensure job1 is processing (it's been shifted from tasks)
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
|
||||
// Clear all pending - should only clear job2, not job1
|
||||
// job1 is already executing (not in tasks array)
|
||||
const clearedCount = queue.clearAllPendingTasks();
|
||||
|
||||
expect(clearedCount).toBe(1);
|
||||
|
||||
// Handle all promises
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 should succeed (it was processing)
|
||||
const job1Result = results[0];
|
||||
expect(job1Result.status).toBe("fulfilled");
|
||||
|
||||
// job2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result && job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
// Only job1 should have processed
|
||||
expect(processed).toHaveLength(1);
|
||||
expect(processed).toContain("job1");
|
||||
});
|
||||
|
||||
it("should return 0 when no pending tasks", () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const clearedCount = queue.clearAllPendingTasks();
|
||||
expect(clearedCount).toBe(0);
|
||||
});
|
||||
|
||||
it("should clear tasks from multiple groups", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs to multiple groups
|
||||
const promises = [
|
||||
queue.add("group1", { id: "job1" }),
|
||||
queue.add("group1", { id: "job2" }),
|
||||
queue.add("group2", { id: "job3" }),
|
||||
queue.add("group2", { id: "job4" }),
|
||||
queue.add("group3", { id: "job5" }),
|
||||
];
|
||||
|
||||
// Wait a bit for first job to start (it gets shifted from tasks)
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Clear all pending
|
||||
const clearedCount = queue.clearAllPendingTasks();
|
||||
|
||||
// Should clear 4 tasks (job2, job3, job4, job5)
|
||||
// job1 is processing so it's not in the queue anymore
|
||||
expect(clearedCount).toBe(4);
|
||||
|
||||
// Handle all promises
|
||||
const results = await Promise.allSettled(promises);
|
||||
|
||||
// job1 should succeed
|
||||
const job1Result = results[0];
|
||||
expect(job1Result?.status).toBe("fulfilled");
|
||||
|
||||
// Others should be rejected
|
||||
for (let i = 1; i < results.length; i++) {
|
||||
const result = results[i];
|
||||
if (result && result.status === "rejected") {
|
||||
expect(result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Only first job should process
|
||||
expect(processed.length).toBeLessThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Concurrency change with pending tasks", () => {
|
||||
it("should clear pending tasks when concurrency changes", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs with concurrency 1
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
const job3Promise = queue.add("group2", { id: "job3" });
|
||||
|
||||
// Wait for job1 to start processing (it gets shifted from tasks)
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Change concurrency - should clear pending tasks via clearAllPendingTasks
|
||||
queue.setConcurrency(3);
|
||||
|
||||
// Handle all promises
|
||||
const results = await Promise.allSettled([
|
||||
job1Promise,
|
||||
job2Promise,
|
||||
job3Promise,
|
||||
]);
|
||||
|
||||
// job1 should succeed (it was processing)
|
||||
const job1Result = results[0];
|
||||
expect(job1Result.status).toBe("fulfilled");
|
||||
|
||||
// Pending jobs should be rejected (job2 and job3 were in queue when cleared)
|
||||
const job2Result = results[1];
|
||||
const job3Result = results[2];
|
||||
|
||||
// At least one of the pending jobs should be rejected
|
||||
const rejectedCount = [job2Result, job3Result].filter(
|
||||
(r) => r && r.status === "rejected",
|
||||
).length;
|
||||
expect(rejectedCount).toBeGreaterThan(0);
|
||||
|
||||
// Verify rejection messages
|
||||
if (job2Result && job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
if (job3Result && job3Result.status === "rejected") {
|
||||
expect(job3Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// job1 should have processed, others may or may not depending on timing
|
||||
expect(processed.length).toBeGreaterThanOrEqual(1);
|
||||
expect(processed).toContain("job1");
|
||||
});
|
||||
|
||||
it("should allow new jobs after concurrency change", async () => {
|
||||
const queue = new GroupedQueue<{ id: string }>(1);
|
||||
const processed: string[] = [];
|
||||
|
||||
queue.setHandler(async (data) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add job with concurrency 1
|
||||
const job1Promise = queue.add("group1", { id: "job1" });
|
||||
const job2Promise = queue.add("group1", { id: "job2" });
|
||||
|
||||
// Wait for job1 to start (it gets shifted from tasks)
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Change concurrency to 3 - this calls clearAllPendingTasks internally
|
||||
queue.setConcurrency(3);
|
||||
|
||||
// Handle all promises
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 should succeed (it was processing)
|
||||
const job1Result = results[0];
|
||||
expect(job1Result.status).toBe("fulfilled");
|
||||
|
||||
// job2 should be rejected (it was in queue when cleared)
|
||||
const job2Result = results[1];
|
||||
if (job2Result && job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
} else {
|
||||
// If job2 wasn't rejected, it means it started processing before clear
|
||||
// This is acceptable as it's a timing issue
|
||||
}
|
||||
|
||||
// Add new jobs after concurrency change - they should work
|
||||
await Promise.all([
|
||||
queue.add("group2", { id: "job3" }),
|
||||
queue.add("group3", { id: "job4" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// job1, job3, and job4 should have processed
|
||||
expect(processed.length).toBeGreaterThanOrEqual(2);
|
||||
expect(processed).toContain("job1");
|
||||
});
|
||||
});
|
||||
});
|
||||
313
apps/dokploy/__test__/queues/queue-manager.test.ts
Normal file
313
apps/dokploy/__test__/queues/queue-manager.test.ts
Normal file
@@ -0,0 +1,313 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { QueueManager } from "../../server/queues/queue-manager";
|
||||
|
||||
describe("QueueManager", () => {
|
||||
let manager: QueueManager;
|
||||
|
||||
beforeEach(() => {
|
||||
manager = new QueueManager();
|
||||
});
|
||||
|
||||
describe("Queue creation and retrieval", () => {
|
||||
it("should create a queue with default concurrency 1", () => {
|
||||
const queue = manager.getQueue("test-queue");
|
||||
expect(queue.getConcurrency()).toBe(1);
|
||||
});
|
||||
|
||||
it("should create a queue with custom concurrency", () => {
|
||||
const queue = manager.getQueue("test-queue", 5);
|
||||
expect(queue.getConcurrency()).toBe(5);
|
||||
});
|
||||
|
||||
it("should return the same queue instance for the same name", () => {
|
||||
const queue1 = manager.getQueue("test-queue", 3);
|
||||
const queue2 = manager.getQueue("test-queue", 5);
|
||||
expect(queue1).toBe(queue2);
|
||||
// Concurrency should remain as first set
|
||||
expect(queue1.getConcurrency()).toBe(3);
|
||||
});
|
||||
|
||||
it("should create different queues for different names", () => {
|
||||
const queue1 = manager.getQueue("queue1", 2);
|
||||
const queue2 = manager.getQueue("queue2", 4);
|
||||
expect(queue1).not.toBe(queue2);
|
||||
expect(queue1.getConcurrency()).toBe(2);
|
||||
expect(queue2.getConcurrency()).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Handler management", () => {
|
||||
it("should set handler for a queue", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
manager.setHandler("test-queue", async (data: { id: string }) => {
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
await manager.add("test-queue", "group1", { id: "job1" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
expect(processed).toEqual(["job1"]);
|
||||
});
|
||||
|
||||
it("should handle different handlers for different queues", async () => {
|
||||
const queue1Processed: string[] = [];
|
||||
const queue2Processed: string[] = [];
|
||||
|
||||
manager.setHandler("queue1", async (data: { id: string }) => {
|
||||
queue1Processed.push(data.id);
|
||||
});
|
||||
|
||||
manager.setHandler("queue2", async (data: { id: string }) => {
|
||||
queue2Processed.push(data.id);
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
manager.add("queue1", "group1", { id: "job1" }),
|
||||
manager.add("queue2", "group1", { id: "job2" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
expect(queue1Processed).toEqual(["job1"]);
|
||||
expect(queue2Processed).toEqual(["job2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Job management", () => {
|
||||
it("should add jobs to correct queue and group", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
manager.setHandler("test-queue", async (data: { id: string }) => {
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
await manager.add("test-queue", "group1", { id: "job1" });
|
||||
await manager.add("test-queue", "group2", { id: "job2" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
expect(processed).toContain("job1");
|
||||
expect(processed).toContain("job2");
|
||||
});
|
||||
|
||||
it("should create queue with concurrency when adding job", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
// Create queue with concurrency first (without handler)
|
||||
manager.getQueue("new-queue", 3);
|
||||
|
||||
// Set handler
|
||||
manager.setHandler("new-queue", async (data: { id: string }) => {
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Now add job - it should process
|
||||
await manager.add("new-queue", "group1", { id: "job1" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
const queue = manager.getQueue("new-queue");
|
||||
expect(queue.getConcurrency()).toBe(3);
|
||||
expect(processed).toEqual(["job1"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Queue operations", () => {
|
||||
it("should clear group in specific queue", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
manager.setHandler("test-queue", async (data: { id: string }) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
processed.push(data.id);
|
||||
});
|
||||
|
||||
// Add jobs but don't await - they'll start processing
|
||||
const job1Promise = manager.add("test-queue", "group1", { id: "job1" });
|
||||
const job2Promise = manager.add("test-queue", "group1", { id: "job2" });
|
||||
|
||||
// Clear immediately - job1 might be processing, but job2 should be cleared
|
||||
manager.clearGroup("test-queue", "group1");
|
||||
|
||||
// Use Promise.allSettled to handle both promises properly
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 might succeed or fail depending on timing
|
||||
// job2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe("Queue cleared");
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
// Job1 might have processed, but job2 should not
|
||||
expect(processed.length).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("should get group length for specific queue", async () => {
|
||||
manager.setHandler("test-queue", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Add jobs without awaiting - check length immediately
|
||||
const job1Promise = manager.add("test-queue", "group1", { id: "job1" });
|
||||
const job2Promise = manager.add("test-queue", "group1", { id: "job2" });
|
||||
|
||||
// Check length immediately - at least one should be pending
|
||||
// (job1 might be processing, but job2 should be pending)
|
||||
const length = manager.getGroupLength("test-queue", "group1");
|
||||
expect(length).toBeGreaterThanOrEqual(0);
|
||||
|
||||
// Wait for both to complete
|
||||
await Promise.all([job1Promise, job2Promise]);
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
expect(manager.getGroupLength("test-queue", "group1")).toBe(0);
|
||||
});
|
||||
|
||||
it("should get total length for specific queue", async () => {
|
||||
manager.setHandler("test-queue", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
});
|
||||
|
||||
// Add jobs without awaiting - check length immediately
|
||||
const promises = [
|
||||
manager.add("test-queue", "group1", { id: "job1" }),
|
||||
manager.add("test-queue", "group2", { id: "job2" }),
|
||||
manager.add("test-queue", "group3", { id: "job3" }),
|
||||
];
|
||||
|
||||
// Check length immediately - at least some should be pending
|
||||
const length = manager.getTotalLength("test-queue");
|
||||
expect(length).toBeGreaterThanOrEqual(0);
|
||||
|
||||
// Wait for all to complete
|
||||
await Promise.all(promises);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(manager.getTotalLength("test-queue")).toBe(0);
|
||||
});
|
||||
|
||||
it("should check if queue is idle", async () => {
|
||||
manager.setHandler("test-queue", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
});
|
||||
|
||||
expect(manager.isIdle("test-queue")).toBe(true);
|
||||
|
||||
await manager.add("test-queue", "group1", { id: "job1" });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(manager.isIdle("test-queue")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Queue lifecycle", () => {
|
||||
it("should close a specific queue", async () => {
|
||||
manager.setHandler("test-queue", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
// Add first job and wait a bit to ensure it starts processing
|
||||
const job1Promise = manager.add("test-queue", "group1", { id: "job1" });
|
||||
// Add second job without awaiting
|
||||
const job2Promise = manager.add("test-queue", "group1", { id: "job2" });
|
||||
|
||||
// Wait a tiny bit to ensure job2 is queued
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Close queue - job2 should be rejected
|
||||
await manager.closeQueue("test-queue");
|
||||
|
||||
// Use Promise.allSettled to handle both promises properly
|
||||
const results = await Promise.allSettled([job1Promise, job2Promise]);
|
||||
|
||||
// job1 might succeed or fail depending on timing
|
||||
// job2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe("Queue closed");
|
||||
}
|
||||
|
||||
expect(manager.getQueueNames()).not.toContain("test-queue");
|
||||
});
|
||||
|
||||
it("should close all queues", async () => {
|
||||
manager.setHandler("queue1", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
manager.setHandler("queue2", async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
});
|
||||
|
||||
await manager.add("queue1", "group1", { id: "job1" });
|
||||
await manager.add("queue2", "group1", { id: "job2" });
|
||||
|
||||
await manager.closeAll();
|
||||
|
||||
expect(manager.getQueueNames()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should get all queue names", () => {
|
||||
manager.getQueue("queue1");
|
||||
manager.getQueue("queue2");
|
||||
manager.getQueue("queue3");
|
||||
|
||||
const names = manager.getQueueNames();
|
||||
expect(names).toContain("queue1");
|
||||
expect(names).toContain("queue2");
|
||||
expect(names).toContain("queue3");
|
||||
expect(names).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Multiple queues with different concurrency", () => {
|
||||
it("should handle multiple queues with different concurrency settings", async () => {
|
||||
const queue1Processed: string[] = [];
|
||||
const queue2Processed: string[] = [];
|
||||
|
||||
// Create queues with specific concurrency FIRST, before setting handlers
|
||||
const queue1 = manager.getQueue("queue1", 1);
|
||||
const queue2 = manager.getQueue("queue2", 3);
|
||||
|
||||
// Verify concurrency is set correctly before proceeding
|
||||
expect(queue1.getConcurrency()).toBe(1);
|
||||
expect(queue2.getConcurrency()).toBe(3);
|
||||
|
||||
manager.setHandler("queue1", async (data: { id: string }) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
queue1Processed.push(data.id);
|
||||
});
|
||||
|
||||
manager.setHandler("queue2", async (data: { id: string }) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
queue2Processed.push(data.id);
|
||||
});
|
||||
|
||||
// Queue1 with concurrency 1 (sequential)
|
||||
await Promise.all([
|
||||
manager.add("queue1", "app1", { id: "job1" }),
|
||||
manager.add("queue1", "app2", { id: "job2" }),
|
||||
]);
|
||||
|
||||
// Queue2 with concurrency 3 (parallel)
|
||||
await Promise.all([
|
||||
manager.add("queue2", "app1", { id: "job1" }),
|
||||
manager.add("queue2", "app2", { id: "job2" }),
|
||||
manager.add("queue2", "app3", { id: "job3" }),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
expect(queue1Processed).toHaveLength(2);
|
||||
expect(queue2Processed).toHaveLength(3);
|
||||
|
||||
// Verify concurrency settings are still correct
|
||||
expect(manager.getQueue("queue1").getConcurrency()).toBe(1);
|
||||
expect(manager.getQueue("queue2").getConcurrency()).toBe(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
250
apps/dokploy/__test__/queues/queue-setup.test.ts
Normal file
250
apps/dokploy/__test__/queues/queue-setup.test.ts
Normal file
@@ -0,0 +1,250 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import type { DeploymentJob } from "../../server/queues/queue-types";
|
||||
import {
|
||||
getConcurrency,
|
||||
myQueue,
|
||||
setConcurrency,
|
||||
} from "../../server/queues/queueSetup";
|
||||
|
||||
describe("queueSetup", () => {
|
||||
beforeEach(() => {
|
||||
// Reset concurrency to default (1) before each test
|
||||
setConcurrency(1);
|
||||
// Clear all pending tasks
|
||||
myQueue.clearAllPendingTasks();
|
||||
});
|
||||
|
||||
describe("getConcurrency", () => {
|
||||
it("should return default concurrency of 1", () => {
|
||||
const concurrency = getConcurrency();
|
||||
expect(concurrency).toBe(1);
|
||||
});
|
||||
|
||||
it("should return current concurrency after setting it", () => {
|
||||
setConcurrency(3);
|
||||
expect(getConcurrency()).toBe(3);
|
||||
|
||||
setConcurrency(5);
|
||||
expect(getConcurrency()).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setConcurrency", () => {
|
||||
it("should set concurrency successfully", () => {
|
||||
const clearedCount = setConcurrency(3);
|
||||
expect(getConcurrency()).toBe(3);
|
||||
expect(clearedCount).toBe(0); // No pending tasks to clear
|
||||
});
|
||||
|
||||
it("should throw error for concurrency less than 1", () => {
|
||||
expect(() => setConcurrency(0)).toThrow("Concurrency must be at least 1");
|
||||
expect(() => setConcurrency(-1)).toThrow(
|
||||
"Concurrency must be at least 1",
|
||||
);
|
||||
});
|
||||
|
||||
it("should return 0 cleared builds when no pending tasks", () => {
|
||||
const clearedCount = setConcurrency(2);
|
||||
expect(clearedCount).toBe(0);
|
||||
expect(getConcurrency()).toBe(2);
|
||||
});
|
||||
|
||||
it("should clear pending builds when concurrency changes", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
// Set handler
|
||||
myQueue.setHandler(async (job: DeploymentJob) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
if (job.applicationType === "application") {
|
||||
processed.push(job.applicationId);
|
||||
} else if (job.applicationType === "compose") {
|
||||
processed.push(job.composeId);
|
||||
} else if (job.applicationType === "application-preview") {
|
||||
processed.push(job.previewDeploymentId);
|
||||
}
|
||||
});
|
||||
|
||||
// Add jobs to different groups
|
||||
const job1: DeploymentJob = {
|
||||
applicationId: "app1",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
const job2: DeploymentJob = {
|
||||
applicationId: "app2",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
const job3: DeploymentJob = {
|
||||
applicationId: "app3",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
|
||||
// Add jobs without awaiting
|
||||
const promise1 = myQueue.add("application:app1", job1);
|
||||
const promise2 = myQueue.add("application:app2", job2);
|
||||
const promise3 = myQueue.add("application:app3", job3);
|
||||
|
||||
// Wait for first job to start processing
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Change concurrency - should clear pending builds
|
||||
const clearedCount = setConcurrency(3);
|
||||
|
||||
// Should have cleared 2 pending builds (app2 and app3)
|
||||
expect(clearedCount).toBe(2);
|
||||
expect(getConcurrency()).toBe(3);
|
||||
|
||||
// Handle all promises - use allSettled to handle both resolved and rejected
|
||||
const results = await Promise.allSettled([promise1, promise2, promise3]);
|
||||
|
||||
// job1 should succeed (it was processing), others should be rejected
|
||||
const job1Result = results[0];
|
||||
if (job1Result.status === "fulfilled") {
|
||||
// Job1 completed successfully
|
||||
}
|
||||
|
||||
// Pending jobs should be rejected
|
||||
const job2Result = results[1];
|
||||
const job3Result = results[2];
|
||||
if (job2Result && job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
if (job3Result && job3Result.status === "rejected") {
|
||||
expect(job3Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
// Only first job should have processed
|
||||
expect(processed.length).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("should not clear builds when concurrency doesn't change", async () => {
|
||||
// Set to 2
|
||||
setConcurrency(2);
|
||||
expect(getConcurrency()).toBe(2);
|
||||
|
||||
// Set to 2 again - should not clear anything
|
||||
const clearedCount = setConcurrency(2);
|
||||
expect(clearedCount).toBe(0);
|
||||
expect(getConcurrency()).toBe(2);
|
||||
});
|
||||
|
||||
it("should allow new jobs after concurrency change", async () => {
|
||||
const processed: string[] = [];
|
||||
|
||||
myQueue.setHandler(async (job: DeploymentJob) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
if (job.applicationType === "application") {
|
||||
processed.push(job.applicationId);
|
||||
}
|
||||
});
|
||||
|
||||
// Add job with concurrency 1
|
||||
const job1: DeploymentJob = {
|
||||
applicationId: "app1",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
const job2: DeploymentJob = {
|
||||
applicationId: "app2",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
|
||||
const promise1 = myQueue.add("application:app1", job1);
|
||||
const promise2 = myQueue.add("application:app2", job2);
|
||||
|
||||
// Wait for first job to start
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Change concurrency to 3
|
||||
const clearedCount = setConcurrency(3);
|
||||
expect(clearedCount).toBe(1); // app2 should be cleared
|
||||
|
||||
// Handle all promises - use allSettled to handle both resolved and rejected
|
||||
const results = await Promise.allSettled([promise1, promise2]);
|
||||
|
||||
// job1 should succeed (it was processing)
|
||||
const job1Result = results[0];
|
||||
if (job1Result.status === "fulfilled") {
|
||||
// Job1 completed successfully
|
||||
}
|
||||
|
||||
// app2 should be rejected
|
||||
const job2Result = results[1];
|
||||
if (job2Result.status === "rejected") {
|
||||
expect(job2Result.reason.message).toBe(
|
||||
"Concurrency changed - queue cleared",
|
||||
);
|
||||
}
|
||||
|
||||
// Add new jobs after concurrency change - they should work
|
||||
const job3: DeploymentJob = {
|
||||
applicationId: "app3",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
const job4: DeploymentJob = {
|
||||
applicationId: "app4",
|
||||
titleLog: "Test",
|
||||
descriptionLog: "Test",
|
||||
type: "deploy",
|
||||
applicationType: "application",
|
||||
server: false,
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
myQueue.add("application:app3", job3),
|
||||
myQueue.add("application:app4", job4),
|
||||
]);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
// app1, app3, and app4 should have processed
|
||||
expect(processed.length).toBeGreaterThanOrEqual(2);
|
||||
expect(processed).toContain("app1");
|
||||
});
|
||||
|
||||
it("should handle multiple concurrency changes correctly", () => {
|
||||
// Start at 1
|
||||
expect(getConcurrency()).toBe(1);
|
||||
|
||||
// Change to 3
|
||||
setConcurrency(3);
|
||||
expect(getConcurrency()).toBe(3);
|
||||
|
||||
// Change to 5
|
||||
setConcurrency(5);
|
||||
expect(getConcurrency()).toBe(5);
|
||||
|
||||
// Change back to 1
|
||||
setConcurrency(1);
|
||||
expect(getConcurrency()).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,65 +0,0 @@
|
||||
import { Scissors } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { api } from "@/utils/api";
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
type: "application" | "compose";
|
||||
}
|
||||
|
||||
export const KillBuild = ({ id, type }: Props) => {
|
||||
const { mutateAsync, isLoading } =
|
||||
type === "application"
|
||||
? api.application.killBuild.useMutation()
|
||||
: api.compose.killBuild.useMutation();
|
||||
|
||||
return (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" className="w-fit" isLoading={isLoading}>
|
||||
Kill Build
|
||||
<Scissors className="size-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you sure to kill the build?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will kill the build process
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
applicationId: id || "",
|
||||
composeId: id || "",
|
||||
})
|
||||
.then(() => {
|
||||
toast.success("Build killed successfully");
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
});
|
||||
}}
|
||||
>
|
||||
Confirm
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
};
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
import { api, type RouterOutputs } from "@/utils/api";
|
||||
import { ShowRollbackSettings } from "../rollbacks/show-rollback-settings";
|
||||
import { CancelQueues } from "./cancel-queues";
|
||||
import { KillBuild } from "./kill-build";
|
||||
import { RefreshToken } from "./refresh-token";
|
||||
import { ShowDeployment } from "./show-deployment";
|
||||
|
||||
@@ -144,9 +143,6 @@ export const ShowDeployments = ({
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
{(type === "application" || type === "compose") && (
|
||||
<KillBuild id={id} type={type} />
|
||||
)}
|
||||
{(type === "application" || type === "compose") && (
|
||||
<CancelQueues id={id} type={type} />
|
||||
)}
|
||||
|
||||
@@ -79,7 +79,7 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => {
|
||||
>
|
||||
<Button
|
||||
variant="default"
|
||||
isLoading={data?.applicationStatus === "running"}
|
||||
// isLoading={data?.applicationStatus === "running"}
|
||||
className="flex items-center gap-1.5 group focus-visible:ring-2 focus-visible:ring-offset-2"
|
||||
>
|
||||
<Tooltip>
|
||||
|
||||
@@ -182,16 +182,7 @@ export const ShowPreviewDeployments = ({ applicationId }: Props) => {
|
||||
id={deployment.previewDeploymentId}
|
||||
type="previewDeployment"
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
>
|
||||
<RocketIcon className="size-4" />
|
||||
Deployments
|
||||
</Button>
|
||||
</ShowDeploymentsModal>
|
||||
/>
|
||||
|
||||
<AddPreviewDomain
|
||||
previewDeploymentId={`${deployment.previewDeploymentId}`}
|
||||
|
||||
@@ -86,7 +86,7 @@ export const ShowVolumeBackups = ({
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Schedule volume backups to run automatically at specified
|
||||
intervals
|
||||
intervals.
|
||||
</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
|
||||
@@ -150,8 +150,8 @@ export const AddApplication = ({ environmentId, projectName }: Props) => {
|
||||
placeholder="Frontend"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value || "";
|
||||
const serviceName = slugify(val.trim());
|
||||
const val = e.target.value?.trim() || "";
|
||||
const serviceName = slugify(val);
|
||||
form.setValue("appName", `${slug}-${serviceName}`);
|
||||
field.onChange(val);
|
||||
}}
|
||||
|
||||
@@ -161,8 +161,8 @@ export const AddCompose = ({ environmentId, projectName }: Props) => {
|
||||
placeholder="Frontend"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value || "";
|
||||
const serviceName = slugify(val.trim());
|
||||
const val = e.target.value?.trim() || "";
|
||||
const serviceName = slugify(val);
|
||||
form.setValue("appName", `${slug}-${serviceName}`);
|
||||
field.onChange(val);
|
||||
}}
|
||||
|
||||
@@ -395,8 +395,8 @@ export const AddDatabase = ({ environmentId, projectName }: Props) => {
|
||||
placeholder="Name"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value || "";
|
||||
const serviceName = slugify(val.trim());
|
||||
const val = e.target.value?.trim() || "";
|
||||
const serviceName = slugify(val);
|
||||
form.setValue("appName", `${slug}-${serviceName}`);
|
||||
field.onChange(val);
|
||||
}}
|
||||
|
||||
@@ -1261,10 +1261,8 @@ export const HandleNotifications = ({ notificationId }: Props) => {
|
||||
});
|
||||
}
|
||||
toast.success("Connection Success");
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
`Error testing the provider ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
} catch {
|
||||
toast.error("Error testing the provider");
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -15,6 +15,7 @@ import { api } from "@/utils/api";
|
||||
import { ShowModalLogs } from "../../web-server/show-modal-logs";
|
||||
import { TerminalModal } from "../../web-server/terminal-modal";
|
||||
import { GPUSupportModal } from "../gpu-support-modal";
|
||||
import { ChangeConcurrencyModal } from "../change-concurrency-modal";
|
||||
|
||||
export const ShowDokployActions = () => {
|
||||
const { t } = useTranslation("settings");
|
||||
@@ -101,6 +102,14 @@ export const ShowDokployActions = () => {
|
||||
>
|
||||
Reload Redis
|
||||
</DropdownMenuItem>
|
||||
<ChangeConcurrencyModal>
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
onSelect={(e) => e.preventDefault()}
|
||||
>
|
||||
Change Concurrency
|
||||
</DropdownMenuItem>
|
||||
</ChangeConcurrencyModal>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ShowStorageActions } from "./show-storage-actions";
|
||||
import { ShowTraefikActions } from "./show-traefik-actions";
|
||||
import { ToggleDockerCleanup } from "./toggle-docker-cleanup";
|
||||
import { ChangeConcurrencyModal } from "../change-concurrency-modal";
|
||||
|
||||
interface Props {
|
||||
serverId: string;
|
||||
@@ -37,6 +39,16 @@ export const ShowServerActions = ({ serverId }: Props) => {
|
||||
<ShowTraefikActions serverId={serverId} />
|
||||
<ShowStorageActions serverId={serverId} />
|
||||
<ToggleDockerCleanup serverId={serverId} />
|
||||
<div className="col-span-2">
|
||||
<ChangeConcurrencyModal
|
||||
serverId={serverId}
|
||||
trigger={
|
||||
<Button variant="outline" className="w-full">
|
||||
Change Concurrency
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
"use client";
|
||||
|
||||
import { InfoIcon, Loader2 } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { api } from "@/utils/api";
|
||||
|
||||
interface Props {
|
||||
serverId?: string;
|
||||
trigger?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const ChangeConcurrencyModal = ({ serverId, trigger }: Props) => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [concurrency, setConcurrency] = useState<number | "">("");
|
||||
|
||||
const { data, isLoading: isLoadingCurrent } =
|
||||
api.settings.getDeploymentConcurrency.useQuery(
|
||||
{ serverId },
|
||||
{
|
||||
enabled: isOpen,
|
||||
onSuccess: (data) => {
|
||||
if (concurrency === "") {
|
||||
setConcurrency(data.concurrency);
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const { mutateAsync, isLoading } =
|
||||
api.settings.setDeploymentConcurrency.useMutation();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (
|
||||
typeof concurrency !== "number" ||
|
||||
concurrency < 1 ||
|
||||
concurrency > 20
|
||||
) {
|
||||
toast.error("Concurrency must be between 1 and 20");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await mutateAsync({ concurrency, serverId });
|
||||
if (result.clearedBuilds > 0) {
|
||||
toast.warning(
|
||||
`Concurrency updated. ${result.clearedBuilds} pending build${result.clearedBuilds > 1 ? "s were" : " was"} cancelled.`,
|
||||
);
|
||||
} else {
|
||||
toast.success("Concurrency updated successfully");
|
||||
}
|
||||
setIsOpen(false);
|
||||
} catch (error) {
|
||||
toast.error("Failed to update concurrency");
|
||||
}
|
||||
};
|
||||
|
||||
const serverType = serverId ? "Remote Server" : "Dokploy Server";
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogTrigger asChild>
|
||||
{trigger || (
|
||||
<Button variant="outline" size="sm">
|
||||
Change Concurrency
|
||||
</Button>
|
||||
)}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Deployment Concurrency - {serverType}</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure how many deployments can run simultaneously on this
|
||||
server.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="concurrency">Concurrency</Label>
|
||||
<Input
|
||||
id="concurrency"
|
||||
type="number"
|
||||
min={1}
|
||||
max={20}
|
||||
value={concurrency}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setConcurrency(value === "" ? "" : Number.parseInt(value, 10));
|
||||
}}
|
||||
placeholder="Enter concurrency (1-20)"
|
||||
disabled={isLoading || isLoadingCurrent}
|
||||
/>
|
||||
{isLoadingCurrent && (
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
Loading current concurrency...
|
||||
</div>
|
||||
)}
|
||||
{!isLoadingCurrent && data && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Current: {data.concurrency}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<Alert>
|
||||
<InfoIcon className="h-4 w-4" />
|
||||
<AlertDescription className="text-sm">
|
||||
<div className="space-y-1 mt-1">
|
||||
<p>
|
||||
<strong>Default:</strong> 1 deployment at a time
|
||||
(sequential)
|
||||
</p>
|
||||
<p>
|
||||
<strong>Higher values:</strong> More deployments in
|
||||
parallel, but will use more RAM and CPU resources.
|
||||
</p>
|
||||
{serverId && (
|
||||
<p className="text-muted-foreground text-xs mt-2">
|
||||
This setting applies to deployments on this remote server.
|
||||
</p>
|
||||
)}
|
||||
{!serverId && (
|
||||
<p className="text-muted-foreground text-xs mt-2">
|
||||
This setting applies to deployments on the Dokploy server.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<Alert variant="destructive">
|
||||
<InfoIcon className="h-4 w-4" />
|
||||
<AlertDescription className="text-sm font-medium">
|
||||
⚠️ <strong>Warning:</strong> Changing concurrency will cancel all
|
||||
pending builds. Currently running builds will continue, but
|
||||
queued builds will be cancelled.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => setIsOpen(false)}
|
||||
disabled={isLoading}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading || isLoadingCurrent}>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Updating...
|
||||
</>
|
||||
) : (
|
||||
"Update Concurrency"
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCaption,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
@@ -67,6 +68,7 @@ export const ShowUsers = () => {
|
||||
) : (
|
||||
<div className="flex flex-col gap-4 min-h-[25vh]">
|
||||
<Table>
|
||||
<TableCaption>See all users</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[100px]">Email</TableHead>
|
||||
@@ -109,75 +111,35 @@ export const ShowUsers = () => {
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="text-right flex justify-end">
|
||||
{member.role !== "owner" && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<span className="sr-only">
|
||||
Open menu
|
||||
</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>
|
||||
Actions
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>
|
||||
Actions
|
||||
</DropdownMenuLabel>
|
||||
|
||||
{member.role !== "owner" && (
|
||||
<AddUserPermissions
|
||||
userId={member.user.id}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isCloud && (
|
||||
<DialogAction
|
||||
title="Delete User"
|
||||
description="Are you sure you want to delete this user?"
|
||||
type="destructive"
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
userId: member.user.id,
|
||||
})
|
||||
.then(() => {
|
||||
toast.success(
|
||||
"User deleted successfully",
|
||||
);
|
||||
refetch();
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error(
|
||||
"Error deleting destination",
|
||||
);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<DropdownMenuItem
|
||||
className="w-full cursor-pointer text-red-500 hover:!text-red-600"
|
||||
onSelect={(e) => e.preventDefault()}
|
||||
>
|
||||
Delete User
|
||||
</DropdownMenuItem>
|
||||
</DialogAction>
|
||||
)}
|
||||
|
||||
<DialogAction
|
||||
title="Unlink User"
|
||||
description="Are you sure you want to unlink this user?"
|
||||
type="destructive"
|
||||
onClick={async () => {
|
||||
if (!isCloud) {
|
||||
const orgCount =
|
||||
await utils.user.checkUserOrganizations.fetch(
|
||||
{
|
||||
userId: member.user.id,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(orgCount);
|
||||
|
||||
if (orgCount === 1) {
|
||||
{member.role !== "owner" && (
|
||||
<>
|
||||
{!isCloud && (
|
||||
<DialogAction
|
||||
title="Delete User"
|
||||
description="Are you sure you want to delete this user?"
|
||||
type="destructive"
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
userId: member.user.id,
|
||||
})
|
||||
@@ -189,40 +151,86 @@ export const ShowUsers = () => {
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error(
|
||||
"Error deleting user",
|
||||
"Error deleting destination",
|
||||
);
|
||||
});
|
||||
return;
|
||||
}}
|
||||
>
|
||||
<DropdownMenuItem
|
||||
className="w-full cursor-pointer text-red-500 hover:!text-red-600"
|
||||
onSelect={(e) =>
|
||||
e.preventDefault()
|
||||
}
|
||||
>
|
||||
Delete User
|
||||
</DropdownMenuItem>
|
||||
</DialogAction>
|
||||
)}
|
||||
|
||||
<DialogAction
|
||||
title="Unlink User"
|
||||
description="Are you sure you want to unlink this user?"
|
||||
type="destructive"
|
||||
onClick={async () => {
|
||||
if (!isCloud) {
|
||||
const orgCount =
|
||||
await utils.user.checkUserOrganizations.fetch(
|
||||
{
|
||||
userId: member.user.id,
|
||||
},
|
||||
);
|
||||
|
||||
console.log(orgCount);
|
||||
|
||||
if (orgCount === 1) {
|
||||
await mutateAsync({
|
||||
userId: member.user.id,
|
||||
})
|
||||
.then(() => {
|
||||
toast.success(
|
||||
"User deleted successfully",
|
||||
);
|
||||
refetch();
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error(
|
||||
"Error deleting user",
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { error } =
|
||||
await authClient.organization.removeMember(
|
||||
{
|
||||
memberIdOrEmail: member.id,
|
||||
},
|
||||
);
|
||||
const { error } =
|
||||
await authClient.organization.removeMember(
|
||||
{
|
||||
memberIdOrEmail: member.id,
|
||||
},
|
||||
);
|
||||
|
||||
if (!error) {
|
||||
toast.success(
|
||||
"User unlinked successfully",
|
||||
);
|
||||
refetch();
|
||||
} else {
|
||||
toast.error("Error unlinking user");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DropdownMenuItem
|
||||
className="w-full cursor-pointer text-red-500 hover:!text-red-600"
|
||||
onSelect={(e) => e.preventDefault()}
|
||||
if (!error) {
|
||||
toast.success(
|
||||
"User unlinked successfully",
|
||||
);
|
||||
refetch();
|
||||
} else {
|
||||
toast.error(
|
||||
"Error unlinking user",
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Unlink User
|
||||
</DropdownMenuItem>
|
||||
</DialogAction>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
className="w-full cursor-pointer text-red-500 hover:!text-red-600"
|
||||
onSelect={(e) => e.preventDefault()}
|
||||
>
|
||||
Unlink User
|
||||
</DropdownMenuItem>
|
||||
</DialogAction>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
|
||||
@@ -44,20 +44,14 @@ export function TimeBadge() {
|
||||
.padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
const formattedTime = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: serverTime.timezone,
|
||||
timeStyle: "medium",
|
||||
hour12: false,
|
||||
}).format(time);
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center rounded-full border p-1 text-xs whitespace-nowrap max-w-full overflow-hidden gap-1">
|
||||
<div className="inline-flex items-center px-1 gap-1">
|
||||
<span className="hidden sm:inline">Server Time:</span>
|
||||
<span className="font-medium tabular-nums">{formattedTime}</span>
|
||||
</div>
|
||||
<span className="hidden sm:inline text-primary/70 border rounded-full bg-foreground/5 px-1.5 py-0.5">
|
||||
{serverTime.timezone} | {getUtcOffset(serverTime.timezone)}
|
||||
<div className="inline-flex items-center gap-2 rounded-md border px-2 py-1 text-xs sm:text-sm whitespace-nowrap max-w-full overflow-hidden">
|
||||
<span className="hidden sm:inline">Server Time:</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{time.toLocaleTimeString()}
|
||||
</span>
|
||||
<span className="hidden sm:inline text-muted-foreground">
|
||||
({serverTime.timezone} | {getUtcOffset(serverTime.timezone)})
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
-- Fix inconsistent date formats in environment.createdAt field
|
||||
-- Convert PostgreSQL timestamp format to ISO 8601 format
|
||||
-- This addresses issue #2992 where old environments have PostgreSQL timestamp format
|
||||
-- while new ones have ISO 8601 format
|
||||
|
||||
UPDATE "environment"
|
||||
SET "createdAt" = to_char("createdAt"::timestamptz, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')
|
||||
WHERE "createdAt" NOT LIKE '%T%';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -848,13 +848,6 @@
|
||||
"when": 1762632540024,
|
||||
"tag": "0120_lame_captain_midlands",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 121,
|
||||
"version": "7",
|
||||
"when": 1763755037033,
|
||||
"tag": "0121_rainy_cargill",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dokploy",
|
||||
"version": "v0.25.11",
|
||||
"version": "v0.25.6",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
@@ -98,7 +98,6 @@
|
||||
"bl": "6.0.11",
|
||||
"boxen": "^7.1.1",
|
||||
"bullmq": "5.4.2",
|
||||
"shell-quote": "^1.8.1",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^0.2.1",
|
||||
@@ -158,7 +157,6 @@
|
||||
"zod-form-data": "^2.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/shell-quote": "^1.7.5",
|
||||
"@types/adm-zip": "^0.5.7",
|
||||
"@types/bcrypt": "5.0.2",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
|
||||
@@ -253,12 +253,8 @@ export default async function handler(
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`application:${jobData.applicationId}`,
|
||||
jobData,
|
||||
);
|
||||
} catch (error) {
|
||||
res.status(400).json({ message: "Error deploying Application", error });
|
||||
|
||||
@@ -183,12 +183,8 @@ export default async function handler(
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`compose:${jobData.composeId}`,
|
||||
jobData,
|
||||
);
|
||||
} catch (error) {
|
||||
res.status(400).json({ message: "Error deploying Compose", error });
|
||||
|
||||
@@ -132,12 +132,8 @@ export default async function handler(
|
||||
continue;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`application:${jobData.applicationId}`,
|
||||
jobData,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -170,12 +166,8 @@ export default async function handler(
|
||||
}
|
||||
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`compose:${jobData.composeId}`,
|
||||
jobData,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -250,12 +242,8 @@ export default async function handler(
|
||||
continue;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`application:${jobData.applicationId}`,
|
||||
jobData,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -296,12 +284,8 @@ export default async function handler(
|
||||
}
|
||||
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`compose:${jobData.composeId}`,
|
||||
jobData,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -495,12 +479,8 @@ export default async function handler(
|
||||
continue;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
`preview:${jobData.previewDeploymentId}`,
|
||||
jobData,
|
||||
);
|
||||
}
|
||||
return res.status(200).json({ message: "Apps Deployed" });
|
||||
|
||||
@@ -59,9 +59,8 @@ import {
|
||||
} from "@/server/db/schema";
|
||||
import type { DeploymentJob } from "@/server/queues/queue-types";
|
||||
import {
|
||||
addJobAsync,
|
||||
cleanQueuesByApplication,
|
||||
killDockerBuild,
|
||||
myQueue,
|
||||
} from "@/server/queues/queueSetup";
|
||||
import { cancelDeployment, deploy } from "@/server/utils/deploy";
|
||||
import { uploadFileSchema } from "@/utils/schema";
|
||||
@@ -339,14 +338,9 @@ export const applicationRouter = createTRPCRouter({
|
||||
await deploy(jobData);
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
);
|
||||
// Fire and forget - UI doesn't wait for deployment to complete
|
||||
addJobAsync(`application:${jobData.applicationId}`, jobData);
|
||||
return { success: true, message: "Deployment queued" };
|
||||
}),
|
||||
saveEnvironment: protectedProcedure
|
||||
.input(apiSaveEnvironmentVariables)
|
||||
@@ -704,14 +698,8 @@ export const applicationRouter = createTRPCRouter({
|
||||
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
);
|
||||
addJobAsync(`application:${jobData.applicationId}`, jobData);
|
||||
return { success: true, message: "Deployment queued" };
|
||||
}),
|
||||
|
||||
cleanQueues: protectedProcedure
|
||||
@@ -729,21 +717,7 @@ export const applicationRouter = createTRPCRouter({
|
||||
}
|
||||
await cleanQueuesByApplication(input.applicationId);
|
||||
}),
|
||||
killBuild: protectedProcedure
|
||||
.input(apiFindOneApplication)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const application = await findApplicationById(input.applicationId);
|
||||
if (
|
||||
application.environment.project.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to kill this build",
|
||||
});
|
||||
}
|
||||
await killDockerBuild("application", application.serverId);
|
||||
}),
|
||||
|
||||
readTraefikConfig: protectedProcedure
|
||||
.input(apiFindOneApplication)
|
||||
.query(async ({ input, ctx }) => {
|
||||
@@ -816,14 +790,8 @@ export const applicationRouter = createTRPCRouter({
|
||||
return true;
|
||||
}
|
||||
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
);
|
||||
// Fire and forget - UI doesn't wait for deployment to complete
|
||||
addJobAsync(`application:${jobData.applicationId}`, jobData);
|
||||
return true;
|
||||
}),
|
||||
updateTraefikConfig: protectedProcedure
|
||||
|
||||
@@ -59,11 +59,7 @@ import {
|
||||
compose as composeTable,
|
||||
} from "@/server/db/schema";
|
||||
import type { DeploymentJob } from "@/server/queues/queue-types";
|
||||
import {
|
||||
cleanQueuesByCompose,
|
||||
killDockerBuild,
|
||||
myQueue,
|
||||
} from "@/server/queues/queueSetup";
|
||||
import { addJobAsync, cleanQueuesByCompose } from "@/server/queues/queueSetup";
|
||||
import { cancelDeployment, deploy } from "@/server/utils/deploy";
|
||||
import { generatePassword } from "@/templates/utils";
|
||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
|
||||
@@ -252,21 +248,6 @@ export const composeRouter = createTRPCRouter({
|
||||
await cleanQueuesByCompose(input.composeId);
|
||||
return { success: true, message: "Queues cleaned successfully" };
|
||||
}),
|
||||
killBuild: protectedProcedure
|
||||
.input(apiFindCompose)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const compose = await findComposeById(input.composeId);
|
||||
if (
|
||||
compose.environment.project.organizationId !==
|
||||
ctx.session.activeOrganizationId
|
||||
) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not authorized to kill this build",
|
||||
});
|
||||
}
|
||||
await killDockerBuild("compose", compose.serverId);
|
||||
}),
|
||||
|
||||
loadServices: protectedProcedure
|
||||
.input(apiFetchServices)
|
||||
@@ -420,14 +401,7 @@ export const composeRouter = createTRPCRouter({
|
||||
await deploy(jobData);
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
);
|
||||
addJobAsync(`compose:${jobData.composeId}`, jobData);
|
||||
return { success: true, message: "Deployment queued" };
|
||||
}),
|
||||
redeploy: protectedProcedure
|
||||
@@ -456,14 +430,7 @@ export const composeRouter = createTRPCRouter({
|
||||
await deploy(jobData);
|
||||
return true;
|
||||
}
|
||||
await myQueue.add(
|
||||
"deployments",
|
||||
{ ...jobData },
|
||||
{
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
);
|
||||
addJobAsync(`compose:${jobData.composeId}`, jobData);
|
||||
return { success: true, message: "Redeployment queued" };
|
||||
}),
|
||||
stop: protectedProcedure
|
||||
|
||||
@@ -47,19 +47,15 @@ export const destinationRouter = createTRPCRouter({
|
||||
input;
|
||||
try {
|
||||
const rcloneFlags = [
|
||||
`--s3-access-key-id="${accessKey}"`,
|
||||
`--s3-secret-access-key="${secretAccessKey}"`,
|
||||
`--s3-region="${region}"`,
|
||||
`--s3-endpoint="${endpoint}"`,
|
||||
`--s3-access-key-id=${accessKey}`,
|
||||
`--s3-secret-access-key=${secretAccessKey}`,
|
||||
`--s3-region=${region}`,
|
||||
`--s3-endpoint=${endpoint}`,
|
||||
"--s3-no-check-bucket",
|
||||
"--s3-force-path-style",
|
||||
"--retries 1",
|
||||
"--low-level-retries 1",
|
||||
"--timeout 10s",
|
||||
"--contimeout 5s",
|
||||
];
|
||||
if (provider) {
|
||||
rcloneFlags.unshift(`--s3-provider="${provider}"`);
|
||||
rcloneFlags.unshift(`--s3-provider=${provider}`);
|
||||
}
|
||||
const rcloneDestination = `:s3:${bucket}`;
|
||||
const rcloneCommand = `rclone ls ${rcloneFlags.join(" ")} "${rcloneDestination}"`;
|
||||
|
||||
@@ -111,7 +111,7 @@ export const notificationRouter = createTRPCRouter({
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
message: "Error testing the notification",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
@@ -228,7 +228,7 @@ export const notificationRouter = createTRPCRouter({
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
message: "Error testing the notification",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
@@ -285,7 +285,7 @@ export const notificationRouter = createTRPCRouter({
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
message: "Error testing the notification",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
findEnvironmentById,
|
||||
findPostgresById,
|
||||
findProjectById,
|
||||
getMountPath,
|
||||
IS_CLOUD,
|
||||
rebuildDatabase,
|
||||
removePostgresById,
|
||||
@@ -38,7 +37,6 @@ import {
|
||||
postgres as postgresTable,
|
||||
} from "@/server/db/schema";
|
||||
import { cancelJobs } from "@/server/utils/backup";
|
||||
|
||||
export const postgresRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(apiCreatePostgres)
|
||||
@@ -81,13 +79,11 @@ export const postgresRouter = createTRPCRouter({
|
||||
);
|
||||
}
|
||||
|
||||
const mountPath = getMountPath(input.dockerImage);
|
||||
|
||||
await createMount({
|
||||
serviceId: newPostgres.postgresId,
|
||||
serviceType: "postgres",
|
||||
volumeName: `${newPostgres.appName}-data`,
|
||||
mountPath: mountPath,
|
||||
mountPath: "/var/lib/postgresql/data",
|
||||
type: "volume",
|
||||
});
|
||||
|
||||
@@ -286,16 +282,12 @@ export const postgresRouter = createTRPCRouter({
|
||||
const backups = await findBackupsByDbId(input.postgresId, "postgres");
|
||||
|
||||
const cleanupOperations = [
|
||||
async () => await removeService(postgres?.appName, postgres.serverId),
|
||||
async () => await cancelJobs(backups),
|
||||
async () => await removePostgresById(input.postgresId),
|
||||
removeService(postgres.appName, postgres.serverId),
|
||||
cancelJobs(backups),
|
||||
removePostgresById(input.postgresId),
|
||||
];
|
||||
|
||||
for (const operation of cleanupOperations) {
|
||||
try {
|
||||
await operation();
|
||||
} catch (_) {}
|
||||
}
|
||||
await Promise.allSettled(cleanupOperations);
|
||||
|
||||
return postgres;
|
||||
}),
|
||||
@@ -371,7 +363,6 @@ export const postgresRouter = createTRPCRouter({
|
||||
message: "You are not authorized to update this Postgres",
|
||||
});
|
||||
}
|
||||
|
||||
const service = await updatePostgresById(postgresId, {
|
||||
...rest,
|
||||
});
|
||||
|
||||
@@ -587,7 +587,7 @@ export const settingsRouter = createTRPCRouter({
|
||||
return ports.some((port) => port.targetPort === 8080);
|
||||
}),
|
||||
|
||||
readStatsLogs: protectedProcedure
|
||||
readStatsLogs: adminProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
path: "/read-stats-logs",
|
||||
@@ -650,7 +650,7 @@ export const settingsRouter = createTRPCRouter({
|
||||
const processedLogs = processLogs(rawConfig as string, input?.dateRange);
|
||||
return processedLogs || [];
|
||||
}),
|
||||
haveActivateRequests: protectedProcedure.query(async () => {
|
||||
haveActivateRequests: adminProcedure.query(async () => {
|
||||
if (IS_CLOUD) {
|
||||
return true;
|
||||
}
|
||||
@@ -665,7 +665,7 @@ export const settingsRouter = createTRPCRouter({
|
||||
|
||||
return !!parsedConfig?.accessLog?.filePath;
|
||||
}),
|
||||
toggleRequests: protectedProcedure
|
||||
toggleRequests: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
enable: z.boolean(),
|
||||
@@ -835,7 +835,7 @@ export const settingsRouter = createTRPCRouter({
|
||||
const ports = await readPorts("dokploy-traefik", input?.serverId);
|
||||
return ports;
|
||||
}),
|
||||
updateLogCleanup: protectedProcedure
|
||||
updateLogCleanup: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
cronExpression: z.string().nullable(),
|
||||
@@ -851,7 +851,7 @@ export const settingsRouter = createTRPCRouter({
|
||||
return stopLogCleanup();
|
||||
}),
|
||||
|
||||
getLogCleanupStatus: protectedProcedure.query(async () => {
|
||||
getLogCleanupStatus: adminProcedure.query(async () => {
|
||||
return getLogCleanupStatus();
|
||||
}),
|
||||
|
||||
@@ -862,4 +862,49 @@ export const settingsRouter = createTRPCRouter({
|
||||
const ips = process.env.DOKPLOY_CLOUD_IPS?.split(",");
|
||||
return ips;
|
||||
}),
|
||||
getDeploymentConcurrency: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
serverId: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
// For now, remote servers use the same queue as dokploy server
|
||||
// In the future, we could implement per-server queues
|
||||
const { getConcurrency } = await import("@/server/queues/queueSetup");
|
||||
return {
|
||||
concurrency: getConcurrency(),
|
||||
serverId: input.serverId,
|
||||
};
|
||||
}),
|
||||
setDeploymentConcurrency: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
concurrency: z.number().int().min(1).max(20),
|
||||
serverId: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
// For now, remote servers use the same queue as dokploy server
|
||||
// In the future, we could implement per-server queues
|
||||
const { setConcurrency, getConcurrency } = await import(
|
||||
"@/server/queues/queueSetup"
|
||||
);
|
||||
const currentConcurrency = getConcurrency();
|
||||
const clearedCount = setConcurrency(input.concurrency);
|
||||
const serverType = input.serverId ? "remote server" : "Dokploy server";
|
||||
|
||||
let message = `${serverType} deployment concurrency updated from ${currentConcurrency} to ${input.concurrency}. Changes take effect immediately.`;
|
||||
if (clearedCount > 0) {
|
||||
message += ` ${clearedCount} pending build${clearedCount > 1 ? "s were" : " was"} cancelled due to concurrency change.`;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message,
|
||||
concurrency: input.concurrency,
|
||||
serverId: input.serverId,
|
||||
clearedBuilds: clearedCount,
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -8,67 +8,77 @@ import {
|
||||
updateCompose,
|
||||
updatePreviewDeployment,
|
||||
} from "@dokploy/server";
|
||||
import { type Job, Worker } from "bullmq";
|
||||
import type { DeploymentJob } from "./queue-types";
|
||||
import { redisConfig } from "./redis-connection";
|
||||
import { myQueue } from "./queueSetup";
|
||||
|
||||
export const deploymentWorker = new Worker(
|
||||
"deployments",
|
||||
async (job: Job<DeploymentJob>) => {
|
||||
try {
|
||||
if (job.data.applicationType === "application") {
|
||||
await updateApplicationStatus(job.data.applicationId, "running");
|
||||
// Set the handler for processing deployment jobs
|
||||
console.log("Setting deployment queue handler");
|
||||
myQueue.setHandler(async (job: DeploymentJob) => {
|
||||
const jobId =
|
||||
job.applicationType === "application"
|
||||
? job.applicationId
|
||||
: job.applicationType === "compose"
|
||||
? job.composeId
|
||||
: job.previewDeploymentId;
|
||||
console.log("Handler called with job:", job.applicationType, jobId);
|
||||
try {
|
||||
if (job.applicationType === "application") {
|
||||
await updateApplicationStatus(job.applicationId, "running");
|
||||
|
||||
if (job.data.type === "redeploy") {
|
||||
await rebuildApplication({
|
||||
applicationId: job.data.applicationId,
|
||||
titleLog: job.data.titleLog,
|
||||
descriptionLog: job.data.descriptionLog,
|
||||
});
|
||||
} else if (job.data.type === "deploy") {
|
||||
await deployApplication({
|
||||
applicationId: job.data.applicationId,
|
||||
titleLog: job.data.titleLog,
|
||||
descriptionLog: job.data.descriptionLog,
|
||||
});
|
||||
}
|
||||
} else if (job.data.applicationType === "compose") {
|
||||
await updateCompose(job.data.composeId, {
|
||||
composeStatus: "running",
|
||||
if (job.type === "redeploy") {
|
||||
await rebuildApplication({
|
||||
applicationId: job.applicationId,
|
||||
titleLog: job.titleLog,
|
||||
descriptionLog: job.descriptionLog,
|
||||
});
|
||||
if (job.data.type === "deploy") {
|
||||
await deployCompose({
|
||||
composeId: job.data.composeId,
|
||||
titleLog: job.data.titleLog,
|
||||
descriptionLog: job.data.descriptionLog,
|
||||
});
|
||||
} else if (job.data.type === "redeploy") {
|
||||
await rebuildCompose({
|
||||
composeId: job.data.composeId,
|
||||
titleLog: job.data.titleLog,
|
||||
descriptionLog: job.data.descriptionLog,
|
||||
});
|
||||
}
|
||||
} else if (job.data.applicationType === "application-preview") {
|
||||
await updatePreviewDeployment(job.data.previewDeploymentId, {
|
||||
previewStatus: "running",
|
||||
} else if (job.type === "deploy") {
|
||||
await deployApplication({
|
||||
applicationId: job.applicationId,
|
||||
titleLog: job.titleLog,
|
||||
descriptionLog: job.descriptionLog,
|
||||
});
|
||||
}
|
||||
} else if (job.applicationType === "compose") {
|
||||
await updateCompose(job.composeId, {
|
||||
composeStatus: "running",
|
||||
});
|
||||
if (job.type === "deploy") {
|
||||
await deployCompose({
|
||||
composeId: job.composeId,
|
||||
titleLog: job.titleLog,
|
||||
descriptionLog: job.descriptionLog,
|
||||
});
|
||||
} else if (job.type === "redeploy") {
|
||||
await rebuildCompose({
|
||||
composeId: job.composeId,
|
||||
titleLog: job.titleLog,
|
||||
descriptionLog: job.descriptionLog,
|
||||
});
|
||||
}
|
||||
} else if (job.applicationType === "application-preview") {
|
||||
await updatePreviewDeployment(job.previewDeploymentId, {
|
||||
previewStatus: "running",
|
||||
});
|
||||
|
||||
if (job.type === "deploy") {
|
||||
await deployPreviewApplication({
|
||||
applicationId: job.applicationId,
|
||||
titleLog: job.titleLog,
|
||||
descriptionLog: job.descriptionLog,
|
||||
previewDeploymentId: job.previewDeploymentId,
|
||||
});
|
||||
|
||||
if (job.data.type === "deploy") {
|
||||
await deployPreviewApplication({
|
||||
applicationId: job.data.applicationId,
|
||||
titleLog: job.data.titleLog,
|
||||
descriptionLog: job.data.descriptionLog,
|
||||
previewDeploymentId: job.data.previewDeploymentId,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error", error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error processing deployment job", error);
|
||||
throw error; // Re-throw to let the queue handle retries if needed
|
||||
}
|
||||
});
|
||||
|
||||
// Export for compatibility (no longer needed but kept for imports)
|
||||
export const deploymentWorker = {
|
||||
run: () => {
|
||||
// Queue starts processing automatically when jobs are added
|
||||
console.log("Deployment queue handler initialized");
|
||||
},
|
||||
{
|
||||
autorun: false,
|
||||
connection: redisConfig,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
256
apps/dokploy/server/queues/grouped-queue-wrapper.ts
Normal file
256
apps/dokploy/server/queues/grouped-queue-wrapper.ts
Normal file
@@ -0,0 +1,256 @@
|
||||
/**
|
||||
* In-memory grouped queue implementation
|
||||
* Each group processes one job at a time (FIFO per group)
|
||||
* Multiple groups can process in parallel
|
||||
*/
|
||||
|
||||
type Task<T> = {
|
||||
data: T;
|
||||
resolve: () => void;
|
||||
reject: (error: Error) => void;
|
||||
};
|
||||
|
||||
type GroupQueue<T> = {
|
||||
tasks: Task<T>[];
|
||||
processing: boolean;
|
||||
};
|
||||
|
||||
export class GroupedQueue<T> {
|
||||
private groups: Map<string, GroupQueue<T>> = new Map();
|
||||
private handler?: (data: T) => Promise<void>;
|
||||
private concurrency: number;
|
||||
private activeGroups: Set<string> = new Set();
|
||||
|
||||
constructor(concurrency = 4) {
|
||||
this.concurrency = concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the handler function that processes each job
|
||||
*/
|
||||
setHandler(handler: (data: T) => Promise<void>) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a job to a group queue
|
||||
*/
|
||||
async add(groupId: string, data: T): Promise<void> {
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(
|
||||
`Adding job to group ${groupId}, handler set: ${!!this.handler}`,
|
||||
);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.groups.has(groupId)) {
|
||||
this.groups.set(groupId, {
|
||||
tasks: [],
|
||||
processing: false,
|
||||
});
|
||||
}
|
||||
|
||||
const group = this.groups.get(groupId)!;
|
||||
group.tasks.push({
|
||||
data,
|
||||
resolve,
|
||||
reject,
|
||||
});
|
||||
|
||||
// Start processing if not already processing and under concurrency limit
|
||||
if (!group.processing && this.activeGroups.size < this.concurrency) {
|
||||
this.processGroup(groupId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Process jobs in a group queue
|
||||
*/
|
||||
private async processGroup(groupId: string): Promise<void> {
|
||||
const group = this.groups.get(groupId);
|
||||
if (!group || group.processing) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for handler to be set if not available
|
||||
if (!this.handler) {
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(`Handler not set yet for group ${groupId}, waiting...`);
|
||||
}
|
||||
// Retry after a short delay
|
||||
setTimeout(() => {
|
||||
if (this.handler && group.tasks.length > 0) {
|
||||
this.processGroup(groupId);
|
||||
}
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check concurrency limit
|
||||
if (this.activeGroups.size >= this.concurrency) {
|
||||
return;
|
||||
}
|
||||
|
||||
group.processing = true;
|
||||
this.activeGroups.add(groupId);
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(`Processing group ${groupId}, tasks: ${group.tasks.length}`);
|
||||
}
|
||||
|
||||
while (group.tasks.length > 0) {
|
||||
const task = group.tasks.shift()!;
|
||||
|
||||
try {
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(`Executing handler for group ${groupId}`);
|
||||
}
|
||||
await this.handler!(task.data);
|
||||
task.resolve();
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(`Handler completed for group ${groupId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.error(`Handler error for group ${groupId}:`, error);
|
||||
}
|
||||
task.reject(error instanceof Error ? error : new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
group.processing = false;
|
||||
this.activeGroups.delete(groupId);
|
||||
|
||||
// Try to process another group if there are waiting groups
|
||||
this.processNextGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next available group
|
||||
*/
|
||||
private processNextGroup(): void {
|
||||
if (this.activeGroups.size >= this.concurrency) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find a group with pending tasks that's not currently processing
|
||||
for (const [groupId, group] of this.groups.entries()) {
|
||||
if (
|
||||
!group.processing &&
|
||||
group.tasks.length > 0 &&
|
||||
!this.activeGroups.has(groupId)
|
||||
) {
|
||||
this.processGroup(groupId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all tasks for a specific group
|
||||
*/
|
||||
clearGroup(groupId: string): void {
|
||||
const group = this.groups.get(groupId);
|
||||
if (group) {
|
||||
// Reject all pending tasks
|
||||
for (const task of group.tasks) {
|
||||
task.reject(new Error("Queue cleared"));
|
||||
}
|
||||
group.tasks = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all pending tasks across all groups
|
||||
* This is useful when changing concurrency settings
|
||||
* Note: This only clears tasks in the queue, not the currently executing task
|
||||
*/
|
||||
clearAllPendingTasks(): number {
|
||||
let clearedCount = 0;
|
||||
for (const [groupId, group] of this.groups.entries()) {
|
||||
// Clear all pending tasks in the queue
|
||||
// The currently executing task is not in group.tasks (it was already shifted)
|
||||
if (group.tasks.length > 0) {
|
||||
clearedCount += group.tasks.length;
|
||||
for (const task of group.tasks) {
|
||||
task.reject(new Error("Concurrency changed - queue cleared"));
|
||||
}
|
||||
group.tasks = [];
|
||||
}
|
||||
}
|
||||
return clearedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of pending tasks for a group
|
||||
*/
|
||||
getGroupLength(groupId: string): number {
|
||||
return this.groups.get(groupId)?.tasks.length ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total number of pending tasks across all groups
|
||||
*/
|
||||
getTotalLength(): number {
|
||||
let total = 0;
|
||||
for (const group of this.groups.values()) {
|
||||
total += group.tasks.length;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if queue is idle (no active processing)
|
||||
*/
|
||||
isIdle(): boolean {
|
||||
return this.activeGroups.size === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of active groups (for testing)
|
||||
*/
|
||||
getActiveGroupsCount(): number {
|
||||
return this.activeGroups.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the concurrency limit
|
||||
*/
|
||||
getConcurrency(): number {
|
||||
return this.concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the concurrency limit dynamically
|
||||
* This allows changing concurrency without recreating the queue
|
||||
* WARNING: This will clear all pending tasks when concurrency changes
|
||||
*/
|
||||
setConcurrency(concurrency: number): void {
|
||||
if (concurrency < 1) {
|
||||
throw new Error("Concurrency must be at least 1");
|
||||
}
|
||||
const concurrencyChanged = this.concurrency !== concurrency;
|
||||
this.concurrency = concurrency;
|
||||
|
||||
// If concurrency changed, clear all pending tasks
|
||||
if (concurrencyChanged) {
|
||||
this.clearAllPendingTasks();
|
||||
}
|
||||
|
||||
// Process next group if we now have capacity
|
||||
this.processNextGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the queue and reject all pending tasks
|
||||
*/
|
||||
async close(): Promise<void> {
|
||||
for (const [groupId, group] of this.groups.entries()) {
|
||||
for (const task of group.tasks) {
|
||||
task.reject(new Error("Queue closed"));
|
||||
}
|
||||
group.tasks = [];
|
||||
}
|
||||
this.groups.clear();
|
||||
this.activeGroups.clear();
|
||||
}
|
||||
}
|
||||
112
apps/dokploy/server/queues/queue-manager.ts
Normal file
112
apps/dokploy/server/queues/queue-manager.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Queue Manager - Manages multiple dynamic queues
|
||||
* Each queue can have its own concurrency configuration
|
||||
*/
|
||||
|
||||
import { GroupedQueue } from "./grouped-queue-wrapper";
|
||||
|
||||
export class QueueManager {
|
||||
private queues: Map<string, GroupedQueue<any>> = new Map();
|
||||
|
||||
/**
|
||||
* Get or create a queue with the specified name and concurrency
|
||||
* Note: If queue already exists, concurrency parameter is ignored
|
||||
*/
|
||||
getQueue<T>(name: string, concurrency = 1): GroupedQueue<T> {
|
||||
if (!this.queues.has(name)) {
|
||||
this.queues.set(name, new GroupedQueue<T>(concurrency));
|
||||
}
|
||||
return this.queues.get(name) as GroupedQueue<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler for a specific queue
|
||||
*/
|
||||
setHandler<T>(queueName: string, handler: (data: T) => Promise<void>): void {
|
||||
const queue = this.getQueue<T>(queueName);
|
||||
queue.setHandler(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a job to a specific queue and group
|
||||
* If concurrency is provided and queue doesn't exist, creates it with that concurrency
|
||||
*/
|
||||
async add<T>(
|
||||
queueName: string,
|
||||
groupId: string,
|
||||
data: T,
|
||||
concurrency?: number,
|
||||
): Promise<void> {
|
||||
// If concurrency is provided and queue doesn't exist, create with that concurrency
|
||||
if (concurrency !== undefined && !this.queues.has(queueName)) {
|
||||
this.queues.set(queueName, new GroupedQueue<T>(concurrency));
|
||||
}
|
||||
const queue = this.getQueue<T>(queueName);
|
||||
return queue.add(groupId, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all tasks for a specific group in a queue
|
||||
*/
|
||||
clearGroup(queueName: string, groupId: string): void {
|
||||
const queue = this.queues.get(queueName);
|
||||
if (queue) {
|
||||
queue.clearGroup(groupId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of pending tasks for a group in a queue
|
||||
*/
|
||||
getGroupLength(queueName: string, groupId: string): number {
|
||||
const queue = this.queues.get(queueName);
|
||||
return queue ? queue.getGroupLength(groupId) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total number of pending tasks across all groups in a queue
|
||||
*/
|
||||
getTotalLength(queueName: string): number {
|
||||
const queue = this.queues.get(queueName);
|
||||
return queue ? queue.getTotalLength() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a queue is idle
|
||||
*/
|
||||
isIdle(queueName: string): boolean {
|
||||
const queue = this.queues.get(queueName);
|
||||
return queue ? queue.isIdle() : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a specific queue
|
||||
*/
|
||||
async closeQueue(queueName: string): Promise<void> {
|
||||
const queue = this.queues.get(queueName);
|
||||
if (queue) {
|
||||
await queue.close();
|
||||
this.queues.delete(queueName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all queues
|
||||
*/
|
||||
async closeAll(): Promise<void> {
|
||||
const promises = Array.from(this.queues.keys()).map((name) =>
|
||||
this.closeQueue(name),
|
||||
);
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all queue names
|
||||
*/
|
||||
getQueueNames(): string[] {
|
||||
return Array.from(this.queues.keys());
|
||||
}
|
||||
}
|
||||
|
||||
// Singleton instance
|
||||
export const queueManager = new QueueManager();
|
||||
@@ -1,75 +1,110 @@
|
||||
import {
|
||||
execAsync,
|
||||
execAsyncRemote,
|
||||
} from "@dokploy/server/utils/process/execAsync";
|
||||
import { Queue } from "bullmq";
|
||||
import { redisConfig } from "./redis-connection";
|
||||
import { GroupedQueue } from "./grouped-queue-wrapper";
|
||||
import type { DeploymentJob } from "./queue-types";
|
||||
|
||||
const myQueue = new Queue("deployments", {
|
||||
connection: redisConfig,
|
||||
});
|
||||
// In-memory grouped queue: processes one job per group at a time
|
||||
// Multiple groups can process in parallel (up to concurrency limit)
|
||||
// Concurrency can be configured via DEPLOYMENT_QUEUE_CONCURRENCY env var (default: 1)
|
||||
// or dynamically via setConcurrency() function
|
||||
let DEPLOYMENT_CONCURRENCY = Number.parseInt(
|
||||
process.env.DEPLOYMENT_QUEUE_CONCURRENCY || "1",
|
||||
10,
|
||||
);
|
||||
|
||||
process.on("SIGTERM", () => {
|
||||
myQueue.close();
|
||||
// Validate concurrency is at least 1
|
||||
if (DEPLOYMENT_CONCURRENCY < 1) {
|
||||
DEPLOYMENT_CONCURRENCY = 1;
|
||||
}
|
||||
|
||||
const myQueue = new GroupedQueue<DeploymentJob>(DEPLOYMENT_CONCURRENCY);
|
||||
|
||||
// Initialize handler when this module is imported
|
||||
// Use dynamic import to avoid circular dependency
|
||||
// The handler will be set when deployments-queue.ts is imported
|
||||
let handlerInitialized = false;
|
||||
const initializeHandler = async () => {
|
||||
if (!handlerInitialized) {
|
||||
handlerInitialized = true;
|
||||
// This will set the handler
|
||||
await import("./deployments-queue");
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize handler immediately (non-blocking)
|
||||
void initializeHandler();
|
||||
|
||||
process.on("SIGTERM", async () => {
|
||||
await myQueue.close();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
myQueue.on("error", (error) => {
|
||||
if ((error as any).code === "ECONNREFUSED") {
|
||||
console.error(
|
||||
"Make sure you have installed Redis and it is running.",
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export const cleanQueuesByApplication = async (applicationId: string) => {
|
||||
const jobs = await myQueue.getJobs(["waiting", "delayed"]);
|
||||
|
||||
for (const job of jobs) {
|
||||
if (job?.data?.applicationId === applicationId) {
|
||||
await job.remove();
|
||||
console.log(`Removed job ${job.id} for application ${applicationId}`);
|
||||
}
|
||||
}
|
||||
const groupId = `application:${applicationId}`;
|
||||
myQueue.clearGroup(groupId);
|
||||
console.log(`Cleared queue for application ${applicationId}`);
|
||||
};
|
||||
|
||||
export const cleanQueuesByCompose = async (composeId: string) => {
|
||||
const jobs = await myQueue.getJobs(["waiting", "delayed"]);
|
||||
|
||||
for (const job of jobs) {
|
||||
if (job?.data?.composeId === composeId) {
|
||||
await job.remove();
|
||||
console.log(`Removed job ${job.id} for compose ${composeId}`);
|
||||
}
|
||||
}
|
||||
const groupId = `compose:${composeId}`;
|
||||
myQueue.clearGroup(groupId);
|
||||
console.log(`Cleared queue for compose ${composeId}`);
|
||||
};
|
||||
|
||||
export const killDockerBuild = async (
|
||||
type: "application" | "compose",
|
||||
serverId: string | null,
|
||||
) => {
|
||||
try {
|
||||
if (type === "application") {
|
||||
const command = `pkill -2 -f "docker build"`;
|
||||
/**
|
||||
* Add a job to the queue without awaiting (fire-and-forget)
|
||||
* This allows the API to return immediately while the job processes in the background
|
||||
* Errors are logged but don't block the response
|
||||
*/
|
||||
export const addJobAsync = (groupId: string, data: DeploymentJob): void => {
|
||||
// Fire and forget - don't await, but handle errors
|
||||
myQueue.add(groupId, data).catch((error) => {
|
||||
console.error(`Failed to queue job for group ${groupId}:`, error);
|
||||
});
|
||||
};
|
||||
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
} else if (type === "compose") {
|
||||
const command = `pkill -2 -f "docker compose"`;
|
||||
/**
|
||||
* Get the current deployment queue concurrency
|
||||
*/
|
||||
export const getConcurrency = (): number => {
|
||||
return myQueue.getConcurrency();
|
||||
};
|
||||
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
/**
|
||||
* Set the deployment queue concurrency dynamically
|
||||
* This updates the queue's concurrency setting immediately
|
||||
* WARNING: This will clear all pending builds when concurrency changes
|
||||
* @returns The number of pending builds that were cleared
|
||||
*/
|
||||
export const setConcurrency = (concurrency: number): number => {
|
||||
if (concurrency < 1) {
|
||||
throw new Error("Concurrency must be at least 1");
|
||||
}
|
||||
|
||||
const currentConcurrency = myQueue.getConcurrency();
|
||||
const concurrencyChanged = currentConcurrency !== concurrency;
|
||||
|
||||
// Get count of pending tasks before clearing (setConcurrency will clear them)
|
||||
let clearedCount = 0;
|
||||
if (concurrencyChanged) {
|
||||
// Get the count before setConcurrency clears them
|
||||
clearedCount = myQueue.getTotalLength();
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(
|
||||
`Concurrency changing from ${currentConcurrency} to ${concurrency}. Will clear ${clearedCount} pending builds.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the stored concurrency value
|
||||
DEPLOYMENT_CONCURRENCY = concurrency;
|
||||
|
||||
// Update the queue's concurrency dynamically (this will clear pending tasks)
|
||||
myQueue.setConcurrency(concurrency);
|
||||
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
console.log(`Deployment queue concurrency updated to ${concurrency}`);
|
||||
}
|
||||
|
||||
return clearedCount;
|
||||
};
|
||||
|
||||
export { myQueue };
|
||||
|
||||
@@ -4,11 +4,11 @@ import {
|
||||
createDefaultServerTraefikConfig,
|
||||
createDefaultTraefikConfig,
|
||||
IS_CLOUD,
|
||||
initCancelDeployments,
|
||||
initCronJobs,
|
||||
initializeNetwork,
|
||||
initSchedules,
|
||||
initVolumeBackupsCronJobs,
|
||||
initCancelDeployments,
|
||||
sendDokployRestartNotifications,
|
||||
setupDirectories,
|
||||
} from "@dokploy/server";
|
||||
@@ -66,6 +66,8 @@ void app.prepare().then(async () => {
|
||||
console.log(`Server Started on: http://${HOST}:${PORT}`);
|
||||
if (!IS_CLOUD) {
|
||||
console.log("Starting Deployment Worker");
|
||||
// Import the handler module to ensure it's initialized
|
||||
await import("./queues/deployments-queue");
|
||||
const { deploymentWorker } = await import("./queues/deployments-queue");
|
||||
await deploymentWorker.run();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"rotating-file-stream": "3.2.3",
|
||||
"shell-quote": "^1.8.1",
|
||||
"slugify": "^1.6.6",
|
||||
"ssh2": "1.15.0",
|
||||
"toml": "3.0.0",
|
||||
@@ -94,7 +93,6 @@
|
||||
"@types/qrcode": "^1.5.5",
|
||||
"@types/react": "^18.3.5",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/shell-quote": "^1.7.5",
|
||||
"@types/ssh2": "1.15.1",
|
||||
"@types/ws": "8.5.10",
|
||||
"drizzle-kit": "^0.30.6",
|
||||
|
||||
@@ -19,7 +19,6 @@ export type TemplateProps = {
|
||||
applicationType: string;
|
||||
buildLink: string;
|
||||
date: string;
|
||||
environmentName: string;
|
||||
};
|
||||
|
||||
export const BuildSuccessEmail = ({
|
||||
@@ -28,7 +27,6 @@ export const BuildSuccessEmail = ({
|
||||
applicationType = "application",
|
||||
buildLink = "https://dokploy.com/projects/dokploy-test/applications/dokploy-test",
|
||||
date = "2023-05-01T00:00:00.000Z",
|
||||
environmentName = "production",
|
||||
}: TemplateProps) => {
|
||||
const previewText = `Build success for ${applicationName}`;
|
||||
return (
|
||||
@@ -76,9 +74,6 @@ export const BuildSuccessEmail = ({
|
||||
<Text className="!leading-3">
|
||||
Application Name: <strong>{applicationName}</strong>
|
||||
</Text>
|
||||
<Text className="!leading-3">
|
||||
Environment: <strong>{environmentName}</strong>
|
||||
</Text>
|
||||
<Text className="!leading-3">
|
||||
Application Type: <strong>{applicationType}</strong>
|
||||
</Text>
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
import { sendBuildErrorNotifications } from "@dokploy/server/utils/notifications/build-error";
|
||||
import { sendBuildSuccessNotifications } from "@dokploy/server/utils/notifications/build-success";
|
||||
import {
|
||||
ExecError,
|
||||
execAsync,
|
||||
execAsyncRemote,
|
||||
} from "@dokploy/server/utils/process/execAsync";
|
||||
@@ -29,7 +28,6 @@ import { cloneGitlabRepository } from "@dokploy/server/utils/providers/gitlab";
|
||||
import { createTraefikConfig } from "@dokploy/server/utils/traefik/application";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { encodeBase64 } from "../utils/docker/utils";
|
||||
import { getDokployUrl } from "./admin";
|
||||
import {
|
||||
createDeployment,
|
||||
@@ -227,19 +225,9 @@ export const deployApplication = async ({
|
||||
buildLink,
|
||||
organizationId: application.environment.project.organizationId,
|
||||
domains: application.domains,
|
||||
environmentName: application.environment.name,
|
||||
});
|
||||
} catch (error) {
|
||||
let command = "";
|
||||
|
||||
// Only log details for non-ExecError errors
|
||||
if (!(error instanceof ExecError)) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const encodedMessage = encodeBase64(message);
|
||||
command += `echo "${encodedMessage}" | base64 -d >> "${deployment.logPath}";`;
|
||||
}
|
||||
|
||||
command += `echo "\nError occurred ❌, check the logs for details." >> ${deployment.logPath};`;
|
||||
const command = `echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath};`;
|
||||
if (application.serverId) {
|
||||
await execAsyncRemote(application.serverId, command);
|
||||
} else {
|
||||
@@ -285,7 +273,6 @@ export const rebuildApplication = async ({
|
||||
descriptionLog: string;
|
||||
}) => {
|
||||
const application = await findApplicationById(applicationId);
|
||||
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`;
|
||||
|
||||
const deployment = await createDeployment({
|
||||
applicationId: applicationId,
|
||||
@@ -306,43 +293,7 @@ export const rebuildApplication = async ({
|
||||
await mechanizeDockerContainer(application);
|
||||
await updateDeploymentStatus(deployment.deploymentId, "done");
|
||||
await updateApplicationStatus(applicationId, "done");
|
||||
|
||||
if (application.rollbackActive) {
|
||||
const tagImage =
|
||||
application.sourceType === "docker"
|
||||
? application.dockerImage
|
||||
: application.appName;
|
||||
await createRollback({
|
||||
appName: tagImage || "",
|
||||
deploymentId: deployment.deploymentId,
|
||||
});
|
||||
}
|
||||
|
||||
await sendBuildSuccessNotifications({
|
||||
projectName: application.environment.project.name,
|
||||
applicationName: application.name,
|
||||
applicationType: "application",
|
||||
buildLink,
|
||||
organizationId: application.environment.project.organizationId,
|
||||
domains: application.domains,
|
||||
environmentName: application.environment.name,
|
||||
});
|
||||
} catch (error) {
|
||||
let command = "";
|
||||
|
||||
// Only log details for non-ExecError errors
|
||||
if (!(error instanceof ExecError)) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const encodedMessage = encodeBase64(message);
|
||||
command += `echo "${encodedMessage}" | base64 -d >> "${deployment.logPath}";`;
|
||||
}
|
||||
|
||||
command += `echo "\nError occurred ❌, check the logs for details." >> ${deployment.logPath};`;
|
||||
if (application.serverId) {
|
||||
await execAsyncRemote(application.serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||
await updateApplicationStatus(applicationId, "error");
|
||||
throw error;
|
||||
|
||||
@@ -18,7 +18,6 @@ import type { ComposeSpecification } from "@dokploy/server/utils/docker/types";
|
||||
import { sendBuildErrorNotifications } from "@dokploy/server/utils/notifications/build-error";
|
||||
import { sendBuildSuccessNotifications } from "@dokploy/server/utils/notifications/build-success";
|
||||
import {
|
||||
ExecError,
|
||||
execAsync,
|
||||
execAsyncRemote,
|
||||
} from "@dokploy/server/utils/process/execAsync";
|
||||
@@ -33,7 +32,6 @@ import { cloneGitlabRepository } from "@dokploy/server/utils/providers/gitlab";
|
||||
import { getCreateComposeFileCommand } from "@dokploy/server/utils/providers/raw";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { encodeBase64 } from "../utils/docker/utils";
|
||||
import { getDokployUrl } from "./admin";
|
||||
import {
|
||||
createDeploymentCompose,
|
||||
@@ -269,24 +267,8 @@ export const deployCompose = async ({
|
||||
buildLink,
|
||||
organizationId: compose.environment.project.organizationId,
|
||||
domains: compose.domains,
|
||||
environmentName: compose.environment.name,
|
||||
});
|
||||
} catch (error) {
|
||||
let command = "";
|
||||
|
||||
// Only log details for non-ExecError errors
|
||||
if (!(error instanceof ExecError)) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const encodedMessage = encodeBase64(message);
|
||||
command += `echo "${encodedMessage}" | base64 -d >> "${deployment.logPath}";`;
|
||||
}
|
||||
|
||||
command += `echo "\nError occurred ❌, check the logs for details." >> ${deployment.logPath};`;
|
||||
if (compose.serverId) {
|
||||
await execAsyncRemote(compose.serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||
await updateCompose(composeId, {
|
||||
composeStatus: "error",
|
||||
@@ -359,21 +341,6 @@ export const rebuildCompose = async ({
|
||||
composeStatus: "done",
|
||||
});
|
||||
} catch (error) {
|
||||
let command = "";
|
||||
|
||||
// Only log details for non-ExecError errors
|
||||
if (!(error instanceof ExecError)) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const encodedMessage = encodeBase64(message);
|
||||
command += `echo "${encodedMessage}" | base64 -d >> "${deployment.logPath}";`;
|
||||
}
|
||||
|
||||
command += `echo "\nError occurred ❌, check the logs for details." >> ${deployment.logPath};`;
|
||||
if (compose.serverId) {
|
||||
await execAsyncRemote(compose.serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||
await updateCompose(composeId, {
|
||||
composeStatus: "error",
|
||||
@@ -408,7 +375,7 @@ export const removeCompose = async (
|
||||
} else {
|
||||
const command = `
|
||||
docker network disconnect ${compose.appName} dokploy-traefik;
|
||||
cd ${projectPath} && env -i PATH="$PATH" docker compose -p ${compose.appName} down ${
|
||||
cd ${projectPath} && docker compose -p ${compose.appName} down ${
|
||||
deleteVolumes ? "--volumes" : ""
|
||||
} && rm -rf ${projectPath}`;
|
||||
|
||||
@@ -435,7 +402,7 @@ export const startCompose = async (composeId: string) => {
|
||||
const projectPath = join(COMPOSE_PATH, compose.appName, "code");
|
||||
const path =
|
||||
compose.sourceType === "raw" ? "docker-compose.yml" : compose.composePath;
|
||||
const baseCommand = `env -i PATH="$PATH" docker compose -p ${compose.appName} -f ${path} up -d`;
|
||||
const baseCommand = `docker compose -p ${compose.appName} -f ${path} up -d`;
|
||||
if (compose.composeType === "docker-compose") {
|
||||
if (compose.serverId) {
|
||||
await execAsyncRemote(
|
||||
@@ -470,17 +437,14 @@ export const stopCompose = async (composeId: string) => {
|
||||
if (compose.serverId) {
|
||||
await execAsyncRemote(
|
||||
compose.serverId,
|
||||
`cd ${join(COMPOSE_PATH, compose.appName)} && env -i PATH="$PATH" docker compose -p ${
|
||||
`cd ${join(COMPOSE_PATH, compose.appName)} && docker compose -p ${
|
||||
compose.appName
|
||||
} stop`,
|
||||
);
|
||||
} else {
|
||||
await execAsync(
|
||||
`env -i PATH="$PATH" docker compose -p ${compose.appName} stop`,
|
||||
{
|
||||
cwd: join(COMPOSE_PATH, compose.appName),
|
||||
},
|
||||
);
|
||||
await execAsync(`docker compose -p ${compose.appName} stop`, {
|
||||
cwd: join(COMPOSE_PATH, compose.appName),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,18 +13,6 @@ import { TRPCError } from "@trpc/server";
|
||||
import { eq, getTableColumns } from "drizzle-orm";
|
||||
import { validUniqueServerAppName } from "./project";
|
||||
|
||||
export function getMountPath(dockerImage: string): string {
|
||||
const versionMatch = dockerImage.match(/postgres:(\d+)/);
|
||||
|
||||
if (versionMatch?.[1]) {
|
||||
const version = Number.parseInt(versionMatch[1], 10);
|
||||
if (version >= 18) {
|
||||
return `/var/lib/postgresql/${version}/data`;
|
||||
}
|
||||
}
|
||||
return "/var/lib/postgresql/data";
|
||||
}
|
||||
|
||||
export type Postgres = typeof postgres.$inferSelect;
|
||||
|
||||
export const createPostgres = async (input: typeof apiCreatePostgres._type) => {
|
||||
|
||||
@@ -59,8 +59,10 @@ export const getUpdateData = async (): Promise<IUpdateData> => {
|
||||
let currentDigest: string;
|
||||
try {
|
||||
currentDigest = await getServiceImageDigest();
|
||||
} catch (error) {
|
||||
// TODO: Docker versions 29.0.0 change the way to get the service image digest, so we need to update this in the future we upgrade to that version.
|
||||
} catch {
|
||||
// Docker service might not exist locally
|
||||
// You can run the # Installation command for docker service create mentioned in the below docs to test it locally:
|
||||
// https://docs.dokploy.com/docs/core/manual-installation
|
||||
return DEFAULT_UPDATE_DATA;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export const initializePostgres = async () => {
|
||||
Mounts: [
|
||||
{
|
||||
Type: "volume",
|
||||
Source: "dokploy-postgres",
|
||||
Source: "dokploy-postgres-database",
|
||||
Target: "/var/lib/postgresql/data",
|
||||
},
|
||||
],
|
||||
|
||||
@@ -14,7 +14,7 @@ export const initializeRedis = async () => {
|
||||
Mounts: [
|
||||
{
|
||||
Type: "volume",
|
||||
Source: "dokploy-redis",
|
||||
Source: "redis-data-volume",
|
||||
Target: "/data",
|
||||
},
|
||||
],
|
||||
|
||||
@@ -2,8 +2,7 @@ import { dirname, join } from "node:path";
|
||||
import { paths } from "@dokploy/server/constants";
|
||||
import type { InferResultType } from "@dokploy/server/types/with";
|
||||
import boxen from "boxen";
|
||||
import { quote } from "shell-quote";
|
||||
import { writeDomainsToCompose } from "../docker/domain";
|
||||
import { writeDomainsToComposeRemote } from "../docker/domain";
|
||||
import {
|
||||
encodeBase64,
|
||||
getEnviromentVariablesObject,
|
||||
@@ -23,7 +22,7 @@ export const getBuildComposeCommand = async (compose: ComposeNested) => {
|
||||
const projectPath = join(COMPOSE_PATH, compose.appName, "code");
|
||||
const exportEnvCommand = getExportEnvCommand(compose);
|
||||
|
||||
const newCompose = await writeDomainsToCompose(compose, domains);
|
||||
const newCompose = await writeDomainsToComposeRemote(compose, domains);
|
||||
const logContent = `
|
||||
App Name: ${appName}
|
||||
Build Compose 🐳
|
||||
@@ -53,8 +52,9 @@ Compose Type: ${composeType} ✅`;
|
||||
|
||||
cd "${projectPath}";
|
||||
|
||||
${exportEnvCommand}
|
||||
${compose.isolatedDeployment ? `docker network inspect ${compose.appName} >/dev/null 2>&1 || docker network create --attachable ${compose.appName}` : ""}
|
||||
env -i PATH="$PATH" ${exportEnvCommand} docker ${command.split(" ").join(" ")} 2>&1 || { echo "Error: ❌ Docker command failed"; exit 1; }
|
||||
docker ${command.split(" ").join(" ")} 2>&1 || { echo "Error: ❌ Docker command failed"; exit 1; }
|
||||
${compose.isolatedDeployment ? `docker network connect ${compose.appName} $(docker ps --filter "name=dokploy-traefik" -q) >/dev/null 2>&1` : ""}
|
||||
|
||||
echo "Docker Compose Deployed: ✅";
|
||||
@@ -65,6 +65,7 @@ Compose Type: ${composeType} ✅`;
|
||||
`;
|
||||
|
||||
return bashCommand;
|
||||
// return await execAsyncRemote(compose.serverId, bashCommand);
|
||||
};
|
||||
|
||||
const sanitizeCommand = (command: string) => {
|
||||
@@ -136,8 +137,8 @@ const getExportEnvCommand = (compose: ComposeNested) => {
|
||||
compose.environment.project.env,
|
||||
);
|
||||
const exports = Object.entries(envVars)
|
||||
.map(([key, value]) => `${key}=${quote([value])}`)
|
||||
.join(" ");
|
||||
.map(([key, value]) => `export ${key}=${JSON.stringify(value)}`)
|
||||
.join("\n");
|
||||
|
||||
return exports ? `${exports}` : "";
|
||||
return exports ? `\n# Export environment variables\n${exports}\n` : "";
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import {
|
||||
getEnviromentVariablesObject,
|
||||
prepareEnvironmentVariablesForShell,
|
||||
prepareEnvironmentVariables,
|
||||
} from "@dokploy/server/utils/docker/utils";
|
||||
import { quote } from "shell-quote";
|
||||
import {
|
||||
getBuildAppDirectory,
|
||||
getDockerContextPath,
|
||||
@@ -41,14 +40,14 @@ export const getDockerCommand = (application: ApplicationNested) => {
|
||||
commandArgs.push("--no-cache");
|
||||
}
|
||||
|
||||
const args = prepareEnvironmentVariablesForShell(
|
||||
const args = prepareEnvironmentVariables(
|
||||
buildArgs,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
);
|
||||
|
||||
for (const arg of args) {
|
||||
commandArgs.push("--build-arg", arg);
|
||||
commandArgs.push("--build-arg", `'${arg}'`);
|
||||
}
|
||||
|
||||
const secrets = getEnviromentVariablesObject(
|
||||
@@ -58,7 +57,7 @@ export const getDockerCommand = (application: ApplicationNested) => {
|
||||
);
|
||||
|
||||
const joinedSecrets = Object.entries(secrets)
|
||||
.map(([key, value]) => `${key}=${quote([value])}`)
|
||||
.map(([key, value]) => `${key}='${value.replace(/'/g, "'\"'\"'")}'`)
|
||||
.join(" ");
|
||||
|
||||
for (const key in secrets) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prepareEnvironmentVariablesForShell } from "../docker/utils";
|
||||
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||
import { getBuildAppDirectory } from "../filesystem/directory";
|
||||
import type { ApplicationNested } from ".";
|
||||
|
||||
@@ -6,7 +6,7 @@ export const getHerokuCommand = (application: ApplicationNested) => {
|
||||
const { env, appName, cleanCache } = application;
|
||||
|
||||
const buildAppDirectory = getBuildAppDirectory(application);
|
||||
const envVariables = prepareEnvironmentVariablesForShell(
|
||||
const envVariables = prepareEnvironmentVariables(
|
||||
env,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
@@ -26,7 +26,7 @@ export const getHerokuCommand = (application: ApplicationNested) => {
|
||||
}
|
||||
|
||||
for (const env of envVariables) {
|
||||
args.push("--env", env);
|
||||
args.push("--env", `'${env}'`);
|
||||
}
|
||||
|
||||
const command = `pack ${args.join(" ")}`;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from "node:path";
|
||||
import { getStaticCommand } from "@dokploy/server/utils/builders/static";
|
||||
import { nanoid } from "nanoid";
|
||||
import { prepareEnvironmentVariablesForShell } from "../docker/utils";
|
||||
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||
import { getBuildAppDirectory } from "../filesystem/directory";
|
||||
import type { ApplicationNested } from ".";
|
||||
|
||||
@@ -10,7 +10,7 @@ export const getNixpacksCommand = (application: ApplicationNested) => {
|
||||
|
||||
const buildAppDirectory = getBuildAppDirectory(application);
|
||||
const buildContainerId = `${appName}-${nanoid(10)}`;
|
||||
const envVariables = prepareEnvironmentVariablesForShell(
|
||||
const envVariables = prepareEnvironmentVariables(
|
||||
env,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
@@ -23,7 +23,7 @@ export const getNixpacksCommand = (application: ApplicationNested) => {
|
||||
}
|
||||
|
||||
for (const env of envVariables) {
|
||||
args.push("--env", env);
|
||||
args.push("--env", `'${env}'`);
|
||||
}
|
||||
|
||||
if (publishDirectory) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prepareEnvironmentVariablesForShell } from "../docker/utils";
|
||||
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||
import { getBuildAppDirectory } from "../filesystem/directory";
|
||||
import type { ApplicationNested } from ".";
|
||||
|
||||
@@ -6,7 +6,7 @@ export const getPaketoCommand = (application: ApplicationNested) => {
|
||||
const { env, appName, cleanCache } = application;
|
||||
|
||||
const buildAppDirectory = getBuildAppDirectory(application);
|
||||
const envVariables = prepareEnvironmentVariablesForShell(
|
||||
const envVariables = prepareEnvironmentVariables(
|
||||
env,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
@@ -26,7 +26,7 @@ export const getPaketoCommand = (application: ApplicationNested) => {
|
||||
}
|
||||
|
||||
for (const env of envVariables) {
|
||||
args.push("--env", env);
|
||||
args.push("--env", `'${env}'`);
|
||||
}
|
||||
|
||||
const command = `pack ${args.join(" ")}`;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { nanoid } from "nanoid";
|
||||
import { quote } from "shell-quote";
|
||||
import {
|
||||
parseEnvironmentKeyValuePair,
|
||||
prepareEnvironmentVariables,
|
||||
prepareEnvironmentVariablesForShell,
|
||||
} from "../docker/utils";
|
||||
import { getBuildAppDirectory } from "../filesystem/directory";
|
||||
import type { ApplicationNested } from ".";
|
||||
@@ -20,7 +18,7 @@ const calculateSecretsHash = (envVariables: string[]): string => {
|
||||
export const getRailpackCommand = (application: ApplicationNested) => {
|
||||
const { env, appName, cleanCache } = application;
|
||||
const buildAppDirectory = getBuildAppDirectory(application);
|
||||
const envVariables = prepareEnvironmentVariablesForShell(
|
||||
const envVariables = prepareEnvironmentVariables(
|
||||
env,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
@@ -37,7 +35,7 @@ export const getRailpackCommand = (application: ApplicationNested) => {
|
||||
];
|
||||
|
||||
for (const env of envVariables) {
|
||||
prepareArgs.push("--env", env);
|
||||
prepareArgs.push("--env", `'${env}'`);
|
||||
}
|
||||
|
||||
// Calculate secrets hash for layer invalidation
|
||||
@@ -65,18 +63,12 @@ export const getRailpackCommand = (application: ApplicationNested) => {
|
||||
];
|
||||
|
||||
// Add secrets properly formatted
|
||||
// Use prepareEnvironmentVariables (without ForShell) to get raw values for parsing
|
||||
const rawEnvVariables = prepareEnvironmentVariables(
|
||||
env,
|
||||
application.environment.project.env,
|
||||
application.environment.env,
|
||||
);
|
||||
const exportEnvs = [];
|
||||
for (const pair of rawEnvVariables) {
|
||||
for (const pair of envVariables) {
|
||||
const [key, value] = parseEnvironmentKeyValuePair(pair);
|
||||
if (key && value) {
|
||||
buildArgs.push("--secret", `id=${key},env=${key}`);
|
||||
exportEnvs.push(`export ${key}=${quote([value])}`);
|
||||
exportEnvs.push(`export ${key}='${value}'`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +77,6 @@ export const getRailpackCommand = (application: ApplicationNested) => {
|
||||
const bashCommand = `
|
||||
|
||||
# Ensure we have a builder with containerd
|
||||
|
||||
export RAILPACK_VERSION=${application.railpackVersion}
|
||||
bash -c "$(curl -fsSL https://railpack.com/install.sh)"
|
||||
docker buildx create --use --name builder-containerd --driver docker-container || true
|
||||
docker buildx use builder-containerd
|
||||
|
||||
@@ -108,7 +97,7 @@ docker ${buildArgs.join(" ")} || {
|
||||
exit 1;
|
||||
}
|
||||
echo "✅ Railpack build completed." ;
|
||||
docker buildx rm builder-containerd
|
||||
docker buildx rm builder-containerd || true
|
||||
`;
|
||||
|
||||
return bashCommand;
|
||||
|
||||
@@ -102,7 +102,7 @@ export const readComposeFile = async (compose: Compose) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export const writeDomainsToCompose = async (
|
||||
export const writeDomainsToComposeRemote = async (
|
||||
compose: Compose,
|
||||
domains: Domain[],
|
||||
) => {
|
||||
@@ -120,16 +120,19 @@ echo "❌ Error: Compose file not found";
|
||||
exit 1;
|
||||
`;
|
||||
}
|
||||
|
||||
const composeString = stringify(composeConverted, { lineWidth: 1000 });
|
||||
const encodedContent = encodeBase64(composeString);
|
||||
return `echo "${encodedContent}" | base64 -d > "${path}";`;
|
||||
if (compose.serverId) {
|
||||
const composeString = stringify(composeConverted, { lineWidth: 1000 });
|
||||
const encodedContent = encodeBase64(composeString);
|
||||
return `echo "${encodedContent}" | base64 -d > "${path}";`;
|
||||
}
|
||||
} catch (error) {
|
||||
// @ts-ignore
|
||||
return `echo "❌ Has occurred an error: ${error?.message || error}";
|
||||
return `echo "❌ Has occured an error: ${error?.message || error}";
|
||||
exit 1;
|
||||
`;
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
export const addDomainToCompose = async (
|
||||
compose: Compose,
|
||||
|
||||
@@ -5,7 +5,6 @@ import { docker, paths } from "@dokploy/server/constants";
|
||||
import type { Compose } from "@dokploy/server/services/compose";
|
||||
import type { ContainerInfo, ResourceRequirements } from "dockerode";
|
||||
import { parse } from "dotenv";
|
||||
import { quote } from "shell-quote";
|
||||
import type { ApplicationNested } from "../builders";
|
||||
import type { MariadbNested } from "../databases/mariadb";
|
||||
import type { MongoNested } from "../databases/mongo";
|
||||
@@ -311,21 +310,6 @@ export const prepareEnvironmentVariables = (
|
||||
return resolvedVars;
|
||||
};
|
||||
|
||||
export const prepareEnvironmentVariablesForShell = (
|
||||
serviceEnv: string | null,
|
||||
projectEnv?: string | null,
|
||||
environmentEnv?: string | null,
|
||||
): string[] => {
|
||||
const envVars = prepareEnvironmentVariables(
|
||||
serviceEnv,
|
||||
projectEnv,
|
||||
environmentEnv,
|
||||
);
|
||||
// Using shell-quote library to properly escape shell arguments
|
||||
// This is the standard way to handle special characters in shell commands
|
||||
return envVars.map((env) => quote([env]));
|
||||
};
|
||||
|
||||
export const parseEnvironmentKeyValuePair = (
|
||||
pair: string,
|
||||
): [string, string] => {
|
||||
|
||||
@@ -7,8 +7,8 @@ import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
sendDiscordNotification,
|
||||
sendEmailNotification,
|
||||
sendGotifyNotification,
|
||||
sendLarkNotification,
|
||||
sendGotifyNotification,
|
||||
sendNtfyNotification,
|
||||
sendSlackNotification,
|
||||
sendTelegramNotification,
|
||||
@@ -52,287 +52,279 @@ export const sendBuildErrorNotifications = async ({
|
||||
for (const notification of notificationList) {
|
||||
const { email, discord, telegram, slack, gotify, ntfy, lark } =
|
||||
notification;
|
||||
try {
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
BuildFailedEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
applicationType,
|
||||
errorMessage: errorMessage,
|
||||
buildLink,
|
||||
date: date.toLocaleString(),
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Build failed for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
BuildFailedEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
applicationType,
|
||||
errorMessage: errorMessage,
|
||||
buildLink,
|
||||
date: date.toLocaleString(),
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(email, "Build failed for dokploy", template);
|
||||
}
|
||||
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`⚠️` Build Failed"),
|
||||
color: 0xed4245,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Type"),
|
||||
value: applicationType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Failed",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⚠️`", "Error Message"),
|
||||
value: `\`\`\`${truncatedErrorMessage}\`\`\``,
|
||||
},
|
||||
{
|
||||
name: decorate("`🧷`", "Build Link"),
|
||||
value: `[Click here to access build link](${buildLink})`,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Build Notification",
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`⚠️` Build Failed"),
|
||||
color: 0xed4245,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Type"),
|
||||
value: applicationType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Failed",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⚠️`", "Error Message"),
|
||||
value: `\`\`\`${truncatedErrorMessage}\`\`\``,
|
||||
},
|
||||
{
|
||||
name: decorate("`🧷`", "Build Link"),
|
||||
value: `[Click here to access build link](${buildLink})`,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Build Notification",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("⚠️", "Build Failed"),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("❔", `Type: ${applicationType}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("⚠️", `Error:\n${errorMessage}`)}` +
|
||||
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
|
||||
);
|
||||
}
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("⚠️", "Build Failed"),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("❔", `Type: ${applicationType}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("⚠️", `Error:\n${errorMessage}`)}` +
|
||||
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Build Failed",
|
||||
"warning",
|
||||
`view, Build details, ${buildLink}, clear=true;`,
|
||||
`🛠️Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`❔Type: ${applicationType}\n` +
|
||||
`🕒Date: ${date.toLocaleString()}\n` +
|
||||
`⚠️Error:\n${errorMessage}`,
|
||||
);
|
||||
}
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Build Failed",
|
||||
"warning",
|
||||
`view, Build details, ${buildLink}, clear=true;`,
|
||||
`🛠️Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`❔Type: ${applicationType}\n` +
|
||||
`🕒Date: ${date.toLocaleString()}\n` +
|
||||
`⚠️Error:\n${errorMessage}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
const inlineButton = [
|
||||
[
|
||||
{
|
||||
text: "Deployment Logs",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
];
|
||||
if (telegram) {
|
||||
const inlineButton = [
|
||||
[
|
||||
{
|
||||
text: "Deployment Logs",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>⚠️ Build Failed</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`,
|
||||
inlineButton,
|
||||
);
|
||||
}
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>⚠️ Build Failed</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`,
|
||||
inlineButton,
|
||||
);
|
||||
}
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#FF0000",
|
||||
pretext: ":warning: *Build Failed*",
|
||||
fields: [
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: applicationType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Error",
|
||||
value: `\`\`\`${errorMessage}\`\`\``,
|
||||
short: false,
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: "button",
|
||||
text: "View Build Details",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#FF0000",
|
||||
pretext: ":warning: *Build Failed*",
|
||||
fields: [
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: applicationType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Error",
|
||||
value: `\`\`\`${errorMessage}\`\`\``,
|
||||
short: false,
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: "button",
|
||||
text: "View Build Details",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
if (lark) {
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage = errorMessage.substring(0, limitCharacter);
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
},
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "⚠️ Build Failed",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "red",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Type:**\n${applicationType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: "View Build Details",
|
||||
},
|
||||
type: "danger",
|
||||
width: "default",
|
||||
size: "medium",
|
||||
behaviors: [
|
||||
{
|
||||
type: "open_url",
|
||||
default_url: buildLink,
|
||||
pc_url: "",
|
||||
ios_url: "",
|
||||
android_url: "",
|
||||
},
|
||||
],
|
||||
margin: "0px 0px 0px 0px",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "⚠️ Build Failed",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "red",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Type:**\n${applicationType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: "View Build Details",
|
||||
},
|
||||
type: "danger",
|
||||
width: "default",
|
||||
size: "medium",
|
||||
behaviors: [
|
||||
{
|
||||
type: "open_url",
|
||||
default_url: buildLink,
|
||||
pc_url: "",
|
||||
ios_url: "",
|
||||
android_url: "",
|
||||
},
|
||||
],
|
||||
margin: "0px 0px 0px 0px",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,8 +8,8 @@ import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
sendDiscordNotification,
|
||||
sendEmailNotification,
|
||||
sendGotifyNotification,
|
||||
sendLarkNotification,
|
||||
sendGotifyNotification,
|
||||
sendNtfyNotification,
|
||||
sendSlackNotification,
|
||||
sendTelegramNotification,
|
||||
@@ -22,7 +22,6 @@ interface Props {
|
||||
buildLink: string;
|
||||
organizationId: string;
|
||||
domains: Domain[];
|
||||
environmentName: string;
|
||||
}
|
||||
|
||||
export const sendBuildSuccessNotifications = async ({
|
||||
@@ -32,7 +31,6 @@ export const sendBuildSuccessNotifications = async ({
|
||||
buildLink,
|
||||
organizationId,
|
||||
domains,
|
||||
environmentName,
|
||||
}: Props) => {
|
||||
const date = new Date();
|
||||
const unixDate = ~~(Number(date) / 1000);
|
||||
@@ -55,295 +53,269 @@ export const sendBuildSuccessNotifications = async ({
|
||||
for (const notification of notificationList) {
|
||||
const { email, discord, telegram, slack, gotify, ntfy, lark } =
|
||||
notification;
|
||||
try {
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
BuildSuccessEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
applicationType,
|
||||
buildLink,
|
||||
date: date.toLocaleString(),
|
||||
environmentName,
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Build success for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
BuildSuccessEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
applicationType,
|
||||
buildLink,
|
||||
date: date.toLocaleString(),
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(email, "Build success for dokploy", template);
|
||||
}
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`✅` Build Successes"),
|
||||
color: 0x57f287,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`🌍`", "Environment"),
|
||||
value: environmentName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Type"),
|
||||
value: applicationType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Successful",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`🧷`", "Build Link"),
|
||||
value: `[Click here to access build link](${buildLink})`,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Build Notification",
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`✅` Build Success"),
|
||||
color: 0x57f287,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Type"),
|
||||
value: applicationType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Successful",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`🧷`", "Build Link"),
|
||||
value: `[Click here to access build link](${buildLink})`,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Build Notification",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("✅", "Build Success"),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("🌍", `Environment: ${environmentName}`)}` +
|
||||
`${decorate("❔", `Type: ${applicationType}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("✅", "Build Success"),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("❔", `Type: ${applicationType}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Build Success",
|
||||
"white_check_mark",
|
||||
`view, Build details, ${buildLink}, clear=true;`,
|
||||
`🛠Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`❔Type: ${applicationType}\n` +
|
||||
`🕒Date: ${date.toLocaleString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
const chunkArray = <T>(array: T[], chunkSize: number): T[][] =>
|
||||
Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) =>
|
||||
array.slice(i * chunkSize, i * chunkSize + chunkSize),
|
||||
);
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Build Success",
|
||||
"white_check_mark",
|
||||
`view, Build details, ${buildLink}, clear=true;`,
|
||||
`🛠Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`🌍Environment: ${environmentName}\n` +
|
||||
`❔Type: ${applicationType}\n` +
|
||||
`🕒Date: ${date.toLocaleString()}`,
|
||||
);
|
||||
}
|
||||
const inlineButton = [
|
||||
[
|
||||
{
|
||||
text: "Deployment Logs",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
...chunkArray(domains, 2).map((chunk) =>
|
||||
chunk.map((data) => ({
|
||||
text: data.host,
|
||||
url: `${data.https ? "https" : "http"}://${data.host}`,
|
||||
})),
|
||||
),
|
||||
];
|
||||
|
||||
if (telegram) {
|
||||
const chunkArray = <T>(array: T[], chunkSize: number): T[][] =>
|
||||
Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) =>
|
||||
array.slice(i * chunkSize, i * chunkSize + chunkSize),
|
||||
);
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>✅ Build Success</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||
inlineButton,
|
||||
);
|
||||
}
|
||||
|
||||
const inlineButton = [
|
||||
[
|
||||
{
|
||||
text: "Deployment Logs",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
...chunkArray(domains, 2).map((chunk) =>
|
||||
chunk.map((data) => ({
|
||||
text: data.host,
|
||||
url: `${data.https ? "https" : "http"}://${data.host}`,
|
||||
})),
|
||||
),
|
||||
];
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#00FF00",
|
||||
pretext: ":white_check_mark: *Build Success*",
|
||||
fields: [
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: applicationType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: "button",
|
||||
text: "View Build Details",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>✅ Build Success</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Environment:</b> ${environmentName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||
inlineButton,
|
||||
);
|
||||
}
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#00FF00",
|
||||
pretext: ":white_check_mark: *Build Success*",
|
||||
fields: [
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Environment",
|
||||
value: environmentName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: applicationType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: "button",
|
||||
text: "View Build Details",
|
||||
url: buildLink,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
if (lark) {
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
},
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "✅ Build Success",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "green",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Environment:**\n${environmentName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Type:**\n${applicationType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: "View Build Details",
|
||||
},
|
||||
type: "primary",
|
||||
width: "default",
|
||||
size: "medium",
|
||||
behaviors: [
|
||||
{
|
||||
type: "open_url",
|
||||
default_url: buildLink,
|
||||
pc_url: "",
|
||||
ios_url: "",
|
||||
android_url: "",
|
||||
},
|
||||
],
|
||||
margin: "0px 0px 0px 0px",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "✅ Build Success",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "green",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Type:**\n${applicationType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "button",
|
||||
text: {
|
||||
tag: "plain_text",
|
||||
content: "View Build Details",
|
||||
},
|
||||
type: "primary",
|
||||
width: "default",
|
||||
size: "medium",
|
||||
behaviors: [
|
||||
{
|
||||
type: "open_url",
|
||||
default_url: buildLink,
|
||||
pc_url: "",
|
||||
ios_url: "",
|
||||
android_url: "",
|
||||
},
|
||||
],
|
||||
margin: "0px 0px 0px 0px",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
sendDiscordNotification,
|
||||
sendEmailNotification,
|
||||
sendGotifyNotification,
|
||||
sendLarkNotification,
|
||||
sendGotifyNotification,
|
||||
sendNtfyNotification,
|
||||
sendSlackNotification,
|
||||
sendTelegramNotification,
|
||||
@@ -52,312 +52,309 @@ export const sendDatabaseBackupNotifications = async ({
|
||||
for (const notification of notificationList) {
|
||||
const { email, discord, telegram, slack, gotify, ntfy, lark } =
|
||||
notification;
|
||||
try {
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DatabaseBackupEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
databaseType,
|
||||
type,
|
||||
errorMessage,
|
||||
date: date.toLocaleString(),
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Database backup for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DatabaseBackupEmail({
|
||||
projectName,
|
||||
applicationName,
|
||||
databaseType,
|
||||
type,
|
||||
errorMessage,
|
||||
date: date.toLocaleString(),
|
||||
}),
|
||||
).catch();
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Database backup for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title:
|
||||
type === "success"
|
||||
? decorate(">", "`✅` Database Backup Successful")
|
||||
: decorate(">", "`❌` Database Backup Failed"),
|
||||
color: type === "success" ? 0x57f287 : 0xed4245,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Database"),
|
||||
value: databaseType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📂`", "Database Name"),
|
||||
value: databaseName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: type
|
||||
.replace("error", "Failed")
|
||||
.replace("success", "Successful"),
|
||||
inline: true,
|
||||
},
|
||||
...(type === "error" && errorMessage
|
||||
? [
|
||||
{
|
||||
name: decorate("`⚠️`", "Error Message"),
|
||||
value: `\`\`\`${errorMessage}\`\`\``,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Database Backup Notification",
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title:
|
||||
type === "success"
|
||||
? decorate(">", "`✅` Database Backup Successful")
|
||||
: decorate(">", "`❌` Database Backup Failed"),
|
||||
color: type === "success" ? 0x57f287 : 0xed4245,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`🛠️`", "Project"),
|
||||
value: projectName,
|
||||
inline: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
{
|
||||
name: decorate("`⚙️`", "Application"),
|
||||
value: applicationName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❔`", "Database"),
|
||||
value: databaseType,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📂`", "Database Name"),
|
||||
value: databaseName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: type
|
||||
.replace("error", "Failed")
|
||||
.replace("success", "Successful"),
|
||||
inline: true,
|
||||
},
|
||||
...(type === "error" && errorMessage
|
||||
? [
|
||||
{
|
||||
name: decorate("`⚠️`", "Error Message"),
|
||||
value: `\`\`\`${errorMessage}\`\`\``,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Database Backup Notification",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate(
|
||||
type === "success" ? "✅" : "❌",
|
||||
`Database Backup ${type === "success" ? "Successful" : "Failed"}`,
|
||||
),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("❔", `Type: ${databaseType}`)}` +
|
||||
`${decorate("📂", `Database Name: ${databaseName}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${type === "error" && errorMessage ? decorate("❌", `Error:\n${errorMessage}`) : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate(
|
||||
type === "success" ? "✅" : "❌",
|
||||
`Database Backup ${type === "success" ? "Successful" : "Failed"}`,
|
||||
`${type === "success" ? "white_check_mark" : "x"}`,
|
||||
"",
|
||||
`🛠Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`❔Type: ${databaseType}\n` +
|
||||
`📂Database Name: ${databaseName}` +
|
||||
`🕒Date: ${date.toLocaleString()}\n` +
|
||||
`${type === "error" && errorMessage ? `❌Error:\n${errorMessage}` : ""}`,
|
||||
);
|
||||
}
|
||||
),
|
||||
`${decorate("🛠️", `Project: ${projectName}`)}` +
|
||||
`${decorate("⚙️", `Application: ${applicationName}`)}` +
|
||||
`${decorate("❔", `Type: ${databaseType}`)}` +
|
||||
`${decorate("📂", `Database Name: ${databaseName}`)}` +
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${type === "error" && errorMessage ? decorate("❌", `Error:\n${errorMessage}`) : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
const isError = type === "error" && errorMessage;
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
`Database Backup ${type === "success" ? "Successful" : "Failed"}`,
|
||||
`${type === "success" ? "white_check_mark" : "x"}`,
|
||||
"",
|
||||
`🛠Project: ${projectName}\n` +
|
||||
`⚙️Application: ${applicationName}\n` +
|
||||
`❔Type: ${databaseType}\n` +
|
||||
`📂Database Name: ${databaseName}` +
|
||||
`🕒Date: ${date.toLocaleString()}\n` +
|
||||
`${type === "error" && errorMessage ? `❌Error:\n${errorMessage}` : ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
const statusEmoji = type === "success" ? "✅" : "❌";
|
||||
const typeStatus = type === "success" ? "Successful" : "Failed";
|
||||
const errorMsg = isError
|
||||
? `\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`
|
||||
: "";
|
||||
if (telegram) {
|
||||
const isError = type === "error" && errorMessage;
|
||||
|
||||
const messageText = `<b>${statusEmoji} Database Backup ${typeStatus}</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${databaseType}\n<b>Database Name:</b> ${databaseName}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}${isError ? errorMsg : ""}`;
|
||||
const statusEmoji = type === "success" ? "✅" : "❌";
|
||||
const typeStatus = type === "success" ? "Successful" : "Failed";
|
||||
const errorMsg = isError
|
||||
? `\n\n<b>Error:</b>\n<pre>${errorMessage}</pre>`
|
||||
: "";
|
||||
|
||||
await sendTelegramNotification(telegram, messageText);
|
||||
}
|
||||
const messageText = `<b>${statusEmoji} Database Backup ${typeStatus}</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${databaseType}\n<b>Database Name:</b> ${databaseName}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}${isError ? errorMsg : ""}`;
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: type === "success" ? "#00FF00" : "#FF0000",
|
||||
pretext:
|
||||
await sendTelegramNotification(telegram, messageText);
|
||||
}
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: type === "success" ? "#00FF00" : "#FF0000",
|
||||
pretext:
|
||||
type === "success"
|
||||
? ":white_check_mark: *Database Backup Successful*"
|
||||
: ":x: *Database Backup Failed*",
|
||||
fields: [
|
||||
...(type === "error" && errorMessage
|
||||
? [
|
||||
{
|
||||
title: "Error Message",
|
||||
value: errorMessage,
|
||||
short: false,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: databaseType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Database Name",
|
||||
value: databaseName,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: type,
|
||||
},
|
||||
{
|
||||
title: "Status",
|
||||
value: type === "success" ? "Successful" : "Failed",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage =
|
||||
errorMessage && errorMessage.length > limitCharacter
|
||||
? errorMessage.substring(0, limitCharacter)
|
||||
: errorMessage;
|
||||
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content:
|
||||
type === "success"
|
||||
? ":white_check_mark: *Database Backup Successful*"
|
||||
: ":x: *Database Backup Failed*",
|
||||
fields: [
|
||||
...(type === "error" && errorMessage
|
||||
? [
|
||||
{
|
||||
title: "Error Message",
|
||||
value: errorMessage,
|
||||
short: false,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: "Project",
|
||||
value: projectName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Application",
|
||||
value: applicationName,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: databaseType,
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Database Name",
|
||||
value: databaseName,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
{
|
||||
title: "Type",
|
||||
value: type,
|
||||
},
|
||||
{
|
||||
title: "Status",
|
||||
value: type === "success" ? "Successful" : "Failed",
|
||||
},
|
||||
],
|
||||
? "✅ Database Backup Successful"
|
||||
: "❌ Database Backup Failed",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
const limitCharacter = 800;
|
||||
const truncatedErrorMessage =
|
||||
errorMessage && errorMessage.length > limitCharacter
|
||||
? errorMessage.substring(0, limitCharacter)
|
||||
: errorMessage;
|
||||
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
},
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content:
|
||||
type === "success"
|
||||
? "✅ Database Backup Successful"
|
||||
: "❌ Database Backup Failed",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: type === "success" ? "green" : "red",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Database Type:**\n${databaseType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Status:**\n${type === "success" ? "Successful" : "Failed"}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Database Name:**\n${databaseName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
...(type === "error" && truncatedErrorMessage
|
||||
? [
|
||||
template: type === "success" ? "green" : "red",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
|
||||
content: `**Project:**\n${projectName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Database Type:**\n${databaseType}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Status:**\n${type === "success" ? "Successful" : "Failed"}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Application:**\n${applicationName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Database Name:**\n${databaseName}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
...(type === "error" && truncatedErrorMessage
|
||||
? [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Error Message:**\n\`\`\`\n${truncatedErrorMessage}\n\`\`\``,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
sendDiscordNotification,
|
||||
sendEmailNotification,
|
||||
sendGotifyNotification,
|
||||
sendLarkNotification,
|
||||
sendGotifyNotification,
|
||||
sendNtfyNotification,
|
||||
sendSlackNotification,
|
||||
sendTelegramNotification,
|
||||
@@ -39,185 +39,182 @@ export const sendDockerCleanupNotifications = async (
|
||||
for (const notification of notificationList) {
|
||||
const { email, discord, telegram, slack, gotify, ntfy, lark } =
|
||||
notification;
|
||||
try {
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DockerCleanupEmail({ message, date: date.toLocaleString() }),
|
||||
).catch();
|
||||
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Docker cleanup for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DockerCleanupEmail({ message, date: date.toLocaleString() }),
|
||||
).catch();
|
||||
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Docker cleanup for dokploy",
|
||||
template,
|
||||
);
|
||||
}
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`✅` Docker Cleanup"),
|
||||
color: 0x57f287,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Successful",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📜`", "Message"),
|
||||
value: `\`\`\`${message}\`\`\``,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Docker Cleanup Notification",
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`✅` Docker Cleanup"),
|
||||
color: 0x57f287,
|
||||
fields: [
|
||||
{
|
||||
name: decorate("`📅`", "Date"),
|
||||
value: `<t:${unixDate}:D>`,
|
||||
inline: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
{
|
||||
name: decorate("`⌚`", "Time"),
|
||||
value: `<t:${unixDate}:t>`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`❓`", "Type"),
|
||||
value: "Successful",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: decorate("`📜`", "Message"),
|
||||
value: `\`\`\`${message}\`\`\``,
|
||||
},
|
||||
],
|
||||
timestamp: date.toISOString(),
|
||||
footer: {
|
||||
text: "Dokploy Docker Cleanup Notification",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("✅", "Docker Cleanup"),
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("📜", `Message:\n${message}`)}`,
|
||||
);
|
||||
}
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("✅", "Docker Cleanup"),
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
|
||||
`${decorate("📜", `Message:\n${message}`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Docker Cleanup",
|
||||
"white_check_mark",
|
||||
"",
|
||||
`🕒Date: ${date.toLocaleString()}\n` + `📜Message:\n${message}`,
|
||||
);
|
||||
}
|
||||
if (ntfy) {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Docker Cleanup",
|
||||
"white_check_mark",
|
||||
"",
|
||||
`🕒Date: ${date.toLocaleString()}\n` + `📜Message:\n${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>✅ Docker Cleanup</b>\n\n<b>Message:</b> ${message}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||
);
|
||||
}
|
||||
if (telegram) {
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>✅ Docker Cleanup</b>\n\n<b>Message:</b> ${message}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#00FF00",
|
||||
pretext: ":white_check_mark: *Docker Cleanup*",
|
||||
fields: [
|
||||
{
|
||||
title: "Message",
|
||||
value: message,
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
{
|
||||
color: "#00FF00",
|
||||
pretext: ":white_check_mark: *Docker Cleanup*",
|
||||
fields: [
|
||||
{
|
||||
title: "Message",
|
||||
value: message,
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
{
|
||||
title: "Time",
|
||||
value: date.toLocaleString(),
|
||||
short: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
schema: "2.0",
|
||||
config: {
|
||||
update_multi: true,
|
||||
style: {
|
||||
text_size: {
|
||||
normal_v2: {
|
||||
default: "normal",
|
||||
pc: "normal",
|
||||
mobile: "heading",
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "✅ Docker Cleanup",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "green",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Status:**\nSuccessful`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Cleanup Details:**\n${message}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
header: {
|
||||
title: {
|
||||
tag: "plain_text",
|
||||
content: "✅ Docker Cleanup",
|
||||
},
|
||||
subtitle: {
|
||||
tag: "plain_text",
|
||||
content: "",
|
||||
},
|
||||
template: "green",
|
||||
padding: "12px 12px 12px 12px",
|
||||
},
|
||||
body: {
|
||||
direction: "vertical",
|
||||
padding: "12px 12px 12px 12px",
|
||||
elements: [
|
||||
{
|
||||
tag: "column_set",
|
||||
columns: [
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: "**Status:**\nSuccessful",
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Cleanup Details:**\n${message}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
{
|
||||
tag: "column",
|
||||
width: "weighted",
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: `**Date:**\n${format(date, "PP pp")}`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
],
|
||||
vertical_align: "top",
|
||||
weight: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ import { eq } from "drizzle-orm";
|
||||
import {
|
||||
sendDiscordNotification,
|
||||
sendEmailNotification,
|
||||
sendGotifyNotification,
|
||||
sendLarkNotification,
|
||||
sendGotifyNotification,
|
||||
sendNtfyNotification,
|
||||
sendSlackNotification,
|
||||
sendTelegramNotification,
|
||||
@@ -34,23 +34,18 @@ export const sendDokployRestartNotifications = async () => {
|
||||
const { email, discord, telegram, slack, gotify, ntfy, lark } =
|
||||
notification;
|
||||
|
||||
try {
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DokployRestartEmail({ date: date.toLocaleString() }),
|
||||
).catch();
|
||||
if (email) {
|
||||
const template = await renderAsync(
|
||||
DokployRestartEmail({ date: date.toLocaleString() }),
|
||||
).catch();
|
||||
await sendEmailNotification(email, "Dokploy Server Restarted", template);
|
||||
}
|
||||
|
||||
await sendEmailNotification(
|
||||
email,
|
||||
"Dokploy Server Restarted",
|
||||
template,
|
||||
);
|
||||
}
|
||||
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
if (discord) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${discord.decoration ? decoration : ""} ${text}`.trim();
|
||||
|
||||
try {
|
||||
await sendDiscordNotification(discord, {
|
||||
title: decorate(">", "`✅` Dokploy Server Restarted"),
|
||||
color: 0x57f287,
|
||||
@@ -76,19 +71,27 @@ export const sendDokployRestartNotifications = async () => {
|
||||
text: "Dokploy Restart Notification",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
if (gotify) {
|
||||
const decorate = (decoration: string, text: string) =>
|
||||
`${gotify.decoration ? decoration : ""} ${text}\n`;
|
||||
try {
|
||||
await sendGotifyNotification(
|
||||
gotify,
|
||||
decorate("✅", "Dokploy Server Restarted"),
|
||||
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (ntfy) {
|
||||
if (ntfy) {
|
||||
try {
|
||||
await sendNtfyNotification(
|
||||
ntfy,
|
||||
"Dokploy Server Restarted",
|
||||
@@ -96,17 +99,25 @@ export const sendDokployRestartNotifications = async () => {
|
||||
"",
|
||||
`🕒Date: ${date.toLocaleString()}`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
if (telegram) {
|
||||
try {
|
||||
await sendTelegramNotification(
|
||||
telegram,
|
||||
`<b>✅ Dokploy Server Restarted</b>\n\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
if (slack) {
|
||||
const { channel } = slack;
|
||||
try {
|
||||
await sendSlackNotification(slack, {
|
||||
channel: channel,
|
||||
attachments: [
|
||||
@@ -123,9 +134,13 @@ export const sendDokployRestartNotifications = async () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (lark) {
|
||||
if (lark) {
|
||||
try {
|
||||
await sendLarkNotification(lark, {
|
||||
msg_type: "interactive",
|
||||
card: {
|
||||
@@ -167,7 +182,7 @@ export const sendDokployRestartNotifications = async () => {
|
||||
elements: [
|
||||
{
|
||||
tag: "markdown",
|
||||
content: "**Status:**\nSuccessful",
|
||||
content: `**Status:**\nSuccessful`,
|
||||
text_align: "left",
|
||||
text_size: "normal_v2",
|
||||
},
|
||||
@@ -195,9 +210,9 @@ export const sendDokployRestartNotifications = async () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type {
|
||||
discord,
|
||||
email,
|
||||
gotify,
|
||||
lark,
|
||||
gotify,
|
||||
ntfy,
|
||||
slack,
|
||||
telegram,
|
||||
@@ -38,9 +38,6 @@ export const sendEmailNotification = async (
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new Error(
|
||||
`Failed to send email notification ${err instanceof Error ? err.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,23 +45,15 @@ export const sendDiscordNotification = async (
|
||||
connection: typeof discord.$inferInsert,
|
||||
embed: any,
|
||||
) => {
|
||||
try {
|
||||
const response = await fetch(connection.webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ embeds: [embed] }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to send discord notification ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("error", err);
|
||||
throw new Error(
|
||||
`Failed to send discord notification ${err instanceof Error ? err.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
// try {
|
||||
await fetch(connection.webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ embeds: [embed] }),
|
||||
});
|
||||
// } catch (err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
};
|
||||
|
||||
export const sendTelegramNotification = async (
|
||||
@@ -101,21 +90,13 @@ export const sendSlackNotification = async (
|
||||
message: any,
|
||||
) => {
|
||||
try {
|
||||
const response = await fetch(connection.webhookUrl, {
|
||||
await fetch(connection.webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(message),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to send slack notification ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("error", err);
|
||||
throw new Error(
|
||||
`Failed to send slack notification ${err instanceof Error ? err.message : "Unknown error"}`,
|
||||
);
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
export interface ExecErrorDetails {
|
||||
command: string;
|
||||
stdout?: string;
|
||||
stderr?: string;
|
||||
exitCode?: number;
|
||||
originalError?: Error;
|
||||
serverId?: string | null;
|
||||
}
|
||||
|
||||
export class ExecError extends Error {
|
||||
public readonly command: string;
|
||||
public readonly stdout?: string;
|
||||
public readonly stderr?: string;
|
||||
public readonly exitCode?: number;
|
||||
public readonly originalError?: Error;
|
||||
public readonly serverId?: string | null;
|
||||
|
||||
constructor(message: string, details: ExecErrorDetails) {
|
||||
super(message);
|
||||
this.name = "ExecError";
|
||||
this.command = details.command;
|
||||
this.stdout = details.stdout;
|
||||
this.stderr = details.stderr;
|
||||
this.exitCode = details.exitCode;
|
||||
this.originalError = details.originalError;
|
||||
this.serverId = details.serverId;
|
||||
|
||||
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, ExecError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a formatted error message with all details
|
||||
*/
|
||||
getDetailedMessage(): string {
|
||||
const parts = [
|
||||
`Command: ${this.command}`,
|
||||
this.exitCode !== undefined ? `Exit Code: ${this.exitCode}` : null,
|
||||
this.serverId ? `Server ID: ${this.serverId}` : "Location: Local",
|
||||
this.stderr ? `Stderr: ${this.stderr}` : null,
|
||||
this.stdout ? `Stdout: ${this.stdout}` : null,
|
||||
].filter(Boolean);
|
||||
|
||||
return `${this.message}\n${parts.join("\n")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this error is from a remote execution
|
||||
*/
|
||||
isRemote(): boolean {
|
||||
return !!this.serverId;
|
||||
}
|
||||
}
|
||||
@@ -2,43 +2,8 @@ import { exec, execFile } from "node:child_process";
|
||||
import util from "node:util";
|
||||
import { findServerById } from "@dokploy/server/services/server";
|
||||
import { Client } from "ssh2";
|
||||
import { ExecError } from "./ExecError";
|
||||
|
||||
// Re-export ExecError for easier imports
|
||||
export { ExecError } from "./ExecError";
|
||||
|
||||
const execAsyncBase = util.promisify(exec);
|
||||
|
||||
export const execAsync = async (
|
||||
command: string,
|
||||
options?: { cwd?: string; env?: NodeJS.ProcessEnv; shell?: string },
|
||||
): Promise<{ stdout: string; stderr: string }> => {
|
||||
try {
|
||||
const result = await execAsyncBase(command, options);
|
||||
return {
|
||||
stdout: result.stdout.toString(),
|
||||
stderr: result.stderr.toString(),
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
// @ts-ignore - exec error has these properties
|
||||
const exitCode = error.code;
|
||||
// @ts-ignore
|
||||
const stdout = error.stdout?.toString() || "";
|
||||
// @ts-ignore
|
||||
const stderr = error.stderr?.toString() || "";
|
||||
|
||||
throw new ExecError(`Command execution failed: ${error.message}`, {
|
||||
command,
|
||||
stdout,
|
||||
stderr,
|
||||
exitCode,
|
||||
originalError: error,
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
export const execAsync = util.promisify(exec);
|
||||
|
||||
interface ExecOptions {
|
||||
cwd?: string;
|
||||
@@ -56,16 +21,7 @@ export const execAsyncStream = (
|
||||
|
||||
const childProcess = exec(command, options, (error) => {
|
||||
if (error) {
|
||||
reject(
|
||||
new ExecError(`Command execution failed: ${error.message}`, {
|
||||
command,
|
||||
stdout: stdoutComplete,
|
||||
stderr: stderrComplete,
|
||||
// @ts-ignore
|
||||
exitCode: error.code,
|
||||
originalError: error,
|
||||
}),
|
||||
);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve({ stdout: stdoutComplete, stderr: stderrComplete });
|
||||
@@ -89,14 +45,7 @@ export const execAsyncStream = (
|
||||
|
||||
childProcess.on("error", (error) => {
|
||||
console.log(error);
|
||||
reject(
|
||||
new ExecError(`Command execution error: ${error.message}`, {
|
||||
command,
|
||||
stdout: stdoutComplete,
|
||||
stderr: stderrComplete,
|
||||
originalError: error,
|
||||
}),
|
||||
);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -159,14 +108,7 @@ export const execAsyncRemote = async (
|
||||
conn.exec(command, (err, stream) => {
|
||||
if (err) {
|
||||
onData?.(err.message);
|
||||
reject(
|
||||
new ExecError(`Remote command execution failed: ${err.message}`, {
|
||||
command,
|
||||
serverId,
|
||||
originalError: err,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
throw err;
|
||||
}
|
||||
stream
|
||||
.on("close", (code: number, _signal: string) => {
|
||||
@@ -174,18 +116,7 @@ export const execAsyncRemote = async (
|
||||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(
|
||||
new ExecError(
|
||||
`Remote command failed with exit code ${code}`,
|
||||
{
|
||||
command,
|
||||
stdout,
|
||||
stderr,
|
||||
exitCode: code,
|
||||
serverId,
|
||||
},
|
||||
),
|
||||
);
|
||||
reject(new Error(`Error occurred ❌: ${stderr}`));
|
||||
}
|
||||
})
|
||||
.on("data", (data: string) => {
|
||||
@@ -201,25 +132,17 @@ export const execAsyncRemote = async (
|
||||
.on("error", (err) => {
|
||||
conn.end();
|
||||
if (err.level === "client-authentication") {
|
||||
const errorMsg = `Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`;
|
||||
onData?.(errorMsg);
|
||||
onData?.(
|
||||
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
|
||||
);
|
||||
reject(
|
||||
new ExecError(errorMsg, {
|
||||
command,
|
||||
serverId,
|
||||
originalError: err,
|
||||
}),
|
||||
new Error(
|
||||
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
const errorMsg = `SSH connection error: ${err.message}`;
|
||||
onData?.(errorMsg);
|
||||
reject(
|
||||
new ExecError(errorMsg, {
|
||||
command,
|
||||
serverId,
|
||||
originalError: err,
|
||||
}),
|
||||
);
|
||||
onData?.(`SSH connection error: ${err.message}`);
|
||||
reject(new Error(`SSH connection error: ${err.message}`));
|
||||
}
|
||||
})
|
||||
.connect({
|
||||
|
||||
@@ -159,6 +159,7 @@ export const cloneGithubRepository = async ({
|
||||
const octokit = authGithub(githubProvider);
|
||||
const token = await getGithubToken(octokit);
|
||||
const repoclone = `github.com/${owner}/${repository}.git`;
|
||||
// await recreateDirectory(outputPath);
|
||||
command += `rm -rf ${outputPath};`;
|
||||
command += `mkdir -p ${outputPath};`;
|
||||
const cloneUrl = `https://oauth2:${token}@${repoclone}`;
|
||||
|
||||
@@ -290,7 +290,7 @@ export const validateGitlabProvider = async (gitlabProvider: Gitlab) => {
|
||||
|
||||
while (true) {
|
||||
const response = await fetch(
|
||||
`${gitlabProvider.gitlabUrl}/api/v4/projects?membership=true&page=${page}&per_page=${perPage}`,
|
||||
`${gitlabProvider.gitlabUrl}/api/v4/projects?membership=true&owned=true&page=${page}&per_page=${perPage}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${gitlabProvider.accessToken}`,
|
||||
|
||||
17
pnpm-lock.yaml
generated
17
pnpm-lock.yaml
generated
@@ -406,9 +406,6 @@ importers:
|
||||
rotating-file-stream:
|
||||
specifier: 3.2.3
|
||||
version: 3.2.3
|
||||
shell-quote:
|
||||
specifier: ^1.8.1
|
||||
version: 1.8.2
|
||||
slugify:
|
||||
specifier: ^1.6.6
|
||||
version: 1.6.6
|
||||
@@ -491,9 +488,6 @@ importers:
|
||||
'@types/react-dom':
|
||||
specifier: 18.3.0
|
||||
version: 18.3.0
|
||||
'@types/shell-quote':
|
||||
specifier: ^1.7.5
|
||||
version: 1.7.5
|
||||
'@types/ssh2':
|
||||
specifier: 1.15.1
|
||||
version: 1.15.1
|
||||
@@ -732,9 +726,6 @@ importers:
|
||||
rotating-file-stream:
|
||||
specifier: 3.2.3
|
||||
version: 3.2.3
|
||||
shell-quote:
|
||||
specifier: ^1.8.1
|
||||
version: 1.8.2
|
||||
slugify:
|
||||
specifier: ^1.6.6
|
||||
version: 1.6.6
|
||||
@@ -787,9 +778,6 @@ importers:
|
||||
'@types/react-dom':
|
||||
specifier: 18.3.0
|
||||
version: 18.3.0
|
||||
'@types/shell-quote':
|
||||
specifier: ^1.7.5
|
||||
version: 1.7.5
|
||||
'@types/ssh2':
|
||||
specifier: 1.15.1
|
||||
version: 1.15.1
|
||||
@@ -4045,9 +4033,6 @@ packages:
|
||||
'@types/readable-stream@4.0.20':
|
||||
resolution: {integrity: sha512-eLgbR5KwUh8+6pngBDxS32MymdCsCHnGtwHTrC0GDorbc7NbcnkZAWptDLgZiRk9VRas+B6TyRgPDucq4zRs8g==}
|
||||
|
||||
'@types/shell-quote@1.7.5':
|
||||
resolution: {integrity: sha512-+UE8GAGRPbJVQDdxi16dgadcBfQ+KG2vgZhV1+3A1XmHbmwcdwhCUwIdy+d3pAGrbvgRoVSjeI9vOWyq376Yzw==}
|
||||
|
||||
'@types/shimmer@1.2.0':
|
||||
resolution: {integrity: sha512-UE7oxhQLLd9gub6JKIAhDq06T0F6FnztwMNRvYgjeQSBeMc1ZG/tA47EwfduvkuQS8apbkM/lpLpWsaCeYsXVg==}
|
||||
|
||||
@@ -11398,8 +11383,6 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/node': 20.17.51
|
||||
|
||||
'@types/shell-quote@1.7.5': {}
|
||||
|
||||
'@types/shimmer@1.2.0': {}
|
||||
|
||||
'@types/ssh2@1.15.1':
|
||||
|
||||
Reference in New Issue
Block a user