Skip to content

Commit 8d0ae19

Browse files
committed
feat: make concurrent builds an OSS feature without license gating
1 parent 856cf33 commit 8d0ae19

8 files changed

Lines changed: 31 additions & 173 deletions

File tree

Lines changed: 12 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3-
const hasValidLicense = vi.fn();
43
const getWebServerSettings = vi.fn();
5-
const findFirstOrg = vi.fn();
64
const findFirstServer = vi.fn();
75

86
vi.mock("@dokploy/server/db", () => ({
97
db: {
108
query: {
11-
organization: {
12-
findFirst: (...args: unknown[]) => findFirstOrg(...args),
13-
},
149
server: {
1510
findFirst: (...args: unknown[]) => findFirstServer(...args),
1611
},
@@ -19,91 +14,56 @@ vi.mock("@dokploy/server/db", () => ({
1914
}));
2015

2116
vi.mock("@dokploy/server/db/schema", () => ({
22-
organization: {},
2317
server: {},
2418
}));
2519

26-
vi.mock("@dokploy/server/services/proprietary/license-key", () => ({
27-
hasValidLicense: (...args: unknown[]) => hasValidLicense(...args),
28-
}));
29-
3020
vi.mock("@dokploy/server/services/web-server-settings", () => ({
3121
getWebServerSettings: (...args: unknown[]) => getWebServerSettings(...args),
3222
}));
3323

3424
vi.mock("drizzle-orm", () => ({ eq: vi.fn() }));
3525

36-
import {
37-
assertBuildsConcurrencyAllowed,
38-
resolveBuildsConcurrency,
39-
} from "../../server/queues/concurrency";
26+
import { resolveBuildsConcurrency } from "../../server/queues/concurrency";
4027
import { LOCAL_PARTITION } from "../../server/queues/in-memory-queue";
4128

42-
describe("resolveBuildsConcurrency (enterprise gating)", () => {
29+
describe("resolveBuildsConcurrency", () => {
4330
beforeEach(() => {
4431
vi.clearAllMocks();
45-
findFirstOrg.mockResolvedValue({ id: "org-1" });
4632
});
4733

4834
describe("local web server partition", () => {
49-
it("returns the configured concurrency when licensed", async () => {
35+
it("returns the configured concurrency", async () => {
5036
getWebServerSettings.mockResolvedValue({ buildsConcurrency: 5 });
51-
hasValidLicense.mockResolvedValue(true);
5237

5338
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(5);
5439
});
5540

56-
it("clamps to the free max (2) when there is no valid license", async () => {
57-
getWebServerSettings.mockResolvedValue({ buildsConcurrency: 10 });
58-
hasValidLicense.mockResolvedValue(false);
59-
60-
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(2);
61-
});
62-
63-
it("allows the free max (2) without a license", async () => {
64-
getWebServerSettings.mockResolvedValue({ buildsConcurrency: 2 });
65-
hasValidLicense.mockResolvedValue(false);
66-
67-
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(2);
68-
});
69-
70-
it("does not cap the value when licensed (N allowed)", async () => {
41+
it("does not cap high values", async () => {
7142
getWebServerSettings.mockResolvedValue({ buildsConcurrency: 999 });
72-
hasValidLicense.mockResolvedValue(true);
7343

7444
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(
7545
999,
7646
);
7747
});
7848

49+
it("floors values below 1 to 1", async () => {
50+
getWebServerSettings.mockResolvedValue({ buildsConcurrency: 0 });
51+
52+
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(1);
53+
});
54+
7955
it("defaults to 1 when settings are missing", async () => {
8056
getWebServerSettings.mockResolvedValue(undefined);
81-
hasValidLicense.mockResolvedValue(true);
8257

8358
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(1);
8459
});
8560
});
8661

8762
describe("remote server partition", () => {
88-
it("returns the server concurrency when its org is licensed", async () => {
89-
findFirstServer.mockResolvedValue({
90-
buildsConcurrency: 4,
91-
organizationId: "org-1",
92-
});
93-
hasValidLicense.mockResolvedValue(true);
63+
it("returns the server concurrency", async () => {
64+
findFirstServer.mockResolvedValue({ buildsConcurrency: 4 });
9465

9566
await expect(resolveBuildsConcurrency("server-1")).resolves.toBe(4);
96-
expect(hasValidLicense).toHaveBeenCalledWith("org-1");
97-
});
98-
99-
it("clamps to the free max (2) when the server org is not licensed", async () => {
100-
findFirstServer.mockResolvedValue({
101-
buildsConcurrency: 8,
102-
organizationId: "org-1",
103-
});
104-
hasValidLicense.mockResolvedValue(false);
105-
106-
await expect(resolveBuildsConcurrency("server-1")).resolves.toBe(2);
10767
});
10868

10969
it("defaults to 1 for an unknown server", async () => {
@@ -119,30 +79,3 @@ describe("resolveBuildsConcurrency (enterprise gating)", () => {
11979
await expect(resolveBuildsConcurrency(LOCAL_PARTITION)).resolves.toBe(1);
12080
});
12181
});
122-
123-
describe("assertBuildsConcurrencyAllowed", () => {
124-
beforeEach(() => {
125-
vi.clearAllMocks();
126-
});
127-
128-
it("allows up to the free max (2) without checking the license", async () => {
129-
await expect(
130-
assertBuildsConcurrencyAllowed(2, "org-1"),
131-
).resolves.toBeUndefined();
132-
expect(hasValidLicense).not.toHaveBeenCalled();
133-
});
134-
135-
it("allows more than 2 when licensed", async () => {
136-
hasValidLicense.mockResolvedValue(true);
137-
await expect(
138-
assertBuildsConcurrencyAllowed(5, "org-1"),
139-
).resolves.toBeUndefined();
140-
});
141-
142-
it("rejects more than 2 without a license", async () => {
143-
hasValidLicense.mockResolvedValue(false);
144-
await expect(assertBuildsConcurrencyAllowed(3, "org-1")).rejects.toThrow(
145-
/enterprise license/i,
146-
);
147-
});
148-
});

‎apps/dokploy/components/dashboard/settings/servers/actions/builds-concurrency.tsx‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { Button } from "@/components/ui/button";
44
import { Input } from "@/components/ui/input";
55
import { api } from "@/utils/api";
66

7-
// Free tier may set up to 2 concurrent builds; enterprise unlocks more.
8-
const FREE_MAX_CONCURRENCY = 2;
9-
const ENTERPRISE_MAX_CONCURRENCY = 100;
7+
const MAX_CONCURRENCY = 100;
108

119
interface Props {
1210
/**
@@ -20,14 +18,10 @@ interface Props {
2018

2119
/**
2220
* Control to set the number of concurrent builds, either for a remote server
23-
* (`serverId` provided) or the local web server (omitted). Available to
24-
* everyone self-hosted up to FREE_MAX_CONCURRENCY; higher values require a
25-
* valid enterprise license. Not shown in cloud.
21+
* (`serverId` provided) or the local web server (omitted). Not shown in cloud.
2622
*/
2723
export const BuildsConcurrency = ({ serverId, label }: Props) => {
2824
const { data: isCloud } = api.settings.isCloud.useQuery();
29-
const { data: haveValidLicense } =
30-
api.licenseKey.haveValidLicenseKey.useQuery();
3125

3226
const serverQuery = api.server.one.useQuery(
3327
{ serverId: serverId ?? "" },
@@ -59,10 +53,7 @@ export const BuildsConcurrency = ({ serverId, label }: Props) => {
5953
// Concurrent builds are a self-hosted feature; not shown in cloud.
6054
if (isCloud) return null;
6155

62-
const max = haveValidLicense
63-
? ENTERPRISE_MAX_CONCURRENCY
64-
: FREE_MAX_CONCURRENCY;
65-
const clamp = (n: number) => Math.min(max, Math.max(1, n));
56+
const clamp = (n: number) => Math.min(MAX_CONCURRENCY, Math.max(1, n));
6657

6758
const handleSave = async () => {
6859
const parsed = clamp(Number.parseInt(value, 10) || 1);
@@ -101,7 +92,7 @@ export const BuildsConcurrency = ({ serverId, label }: Props) => {
10192
<Input
10293
type="number"
10394
min={1}
104-
max={max}
95+
max={MAX_CONCURRENCY}
10596
value={value}
10697
onChange={(e) => setValue(e.target.value)}
10798
className="w-20"

‎apps/dokploy/pages/dashboard/settings/deployments.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const Page = () => {
2929
<CardDescription>
3030
Configure how many deployments can build at the same time on
3131
each server. Builds of the same service are always serialized.
32-
Free plan allows up to 2 concurrent builds; an enterprise
33-
license unlocks more.
3432
</CardDescription>
3533
</CardHeader>
3634
<CardContent className="flex flex-col gap-6">

‎apps/dokploy/server/api/routers/server.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
redis,
4747
server,
4848
} from "@/server/db/schema";
49-
import { assertBuildsConcurrencyAllowed } from "@/server/queues/concurrency";
5049
import { applyDockerCleanupSchedule } from "@/server/utils/docker-cleanup";
5150

5251
export const serverRouter = createTRPCRouter({
@@ -491,10 +490,6 @@ export const serverRouter = createTRPCRouter({
491490
message: "You are not authorized to update this server",
492491
});
493492
}
494-
await assertBuildsConcurrencyAllowed(
495-
input.buildsConcurrency,
496-
ctx.session.activeOrganizationId,
497-
);
498493
return await updateServerById(input.serverId, {
499494
buildsConcurrency: input.buildsConcurrency,
500495
});

‎apps/dokploy/server/api/routers/settings.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import {
7171
projects,
7272
server,
7373
} from "@/server/db/schema";
74-
import { assertBuildsConcurrencyAllowed } from "@/server/queues/concurrency";
7574
import { cleanAllDeploymentQueue } from "@/server/queues/queueSetup";
7675
import { removeJob, schedule } from "@/server/utils/backup";
7776
import packageInfo from "../../../package.json";
@@ -480,11 +479,6 @@ export const settingsRouter = createTRPCRouter({
480479
});
481480
}
482481

483-
await assertBuildsConcurrencyAllowed(
484-
input.buildsConcurrency,
485-
ctx.session.activeOrganizationId,
486-
);
487-
488482
await updateWebServerSettings({
489483
buildsConcurrency: input.buildsConcurrency,
490484
});
Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
import { db } from "@dokploy/server/db";
2-
import { organization, server } from "@dokploy/server/db/schema";
3-
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
2+
import { server } from "@dokploy/server/db/schema";
43
import { getWebServerSettings } from "@dokploy/server/services/web-server-settings";
5-
import { TRPCError } from "@trpc/server";
64
import { eq } from "drizzle-orm";
75
import { LOCAL_PARTITION } from "./in-memory-queue";
86

97
/**
108
* Resolve the effective builds concurrency for a queue partition.
119
*
12-
* Concurrent deployments (concurrency > 1) are an enterprise feature: without a
13-
* valid license the effective concurrency is always clamped to 1, so the
14-
* community experience is unchanged and an expired license degrades gracefully
15-
* back to sequential deployments instead of breaking anything.
16-
*
1710
* - `LOCAL_PARTITION` -> concurrency stored on the web server settings (the
18-
* local Dokploy web server), gated by the owner organization's license.
19-
* - any other partition -> concurrency stored on the matching `server` row,
20-
* gated by that server's organization license.
11+
* local Dokploy web server).
12+
* - any other partition -> concurrency stored on the matching `server` row.
2113
*/
2214
export const resolveBuildsConcurrency = async (
2315
partition: string,
2416
): Promise<number> => {
2517
try {
2618
if (partition === LOCAL_PARTITION) {
27-
return await resolveLocalConcurrency();
19+
const settings = await getWebServerSettings();
20+
return normalize(settings?.buildsConcurrency ?? 1);
2821
}
29-
return await resolveServerConcurrency(partition);
22+
23+
const currentServer = await db.query.server.findFirst({
24+
where: eq(server.serverId, partition),
25+
columns: { buildsConcurrency: true },
26+
});
27+
return normalize(currentServer?.buildsConcurrency ?? 1);
3028
} catch (error) {
3129
console.error(
3230
"Failed to resolve builds concurrency, defaulting to 1",
@@ -36,55 +34,4 @@ export const resolveBuildsConcurrency = async (
3634
}
3735
};
3836

39-
// Max concurrent builds allowed without an enterprise license. With a valid
40-
// license the value is unbounded (N) — only the free tier is capped.
41-
export const FREE_MAX_CONCURRENCY = 2;
42-
43-
const clamp = (value: number, licensed: boolean): number => {
44-
const min = Math.max(1, Math.floor(value));
45-
return licensed ? min : Math.min(FREE_MAX_CONCURRENCY, min);
46-
};
47-
48-
/**
49-
* Validate a requested builds-concurrency value before persisting it. Free tier
50-
* may set up to FREE_MAX_CONCURRENCY; anything higher requires a valid
51-
* enterprise license. Throws a TRPCError when the value is not allowed.
52-
*/
53-
export const assertBuildsConcurrencyAllowed = async (
54-
value: number,
55-
organizationId: string,
56-
): Promise<void> => {
57-
if (value <= FREE_MAX_CONCURRENCY) return;
58-
const licensed = await hasValidLicense(organizationId);
59-
if (!licensed) {
60-
throw new TRPCError({
61-
code: "FORBIDDEN",
62-
message: `A valid enterprise license is required to set more than ${FREE_MAX_CONCURRENCY} concurrent builds.`,
63-
});
64-
}
65-
};
66-
67-
const resolveLocalConcurrency = async (): Promise<number> => {
68-
const settings = await getWebServerSettings();
69-
const buildsConcurrency = settings?.buildsConcurrency ?? 1;
70-
71-
// Self-hosted is single-tenant; gate on any organization's license.
72-
const anyOrg = await db.query.organization.findFirst({
73-
columns: { id: true },
74-
});
75-
const licensed = anyOrg ? await hasValidLicense(anyOrg.id) : false;
76-
77-
return clamp(buildsConcurrency, licensed);
78-
};
79-
80-
const resolveServerConcurrency = async (serverId: string): Promise<number> => {
81-
const currentServer = await db.query.server.findFirst({
82-
where: eq(server.serverId, serverId),
83-
columns: { buildsConcurrency: true, organizationId: true },
84-
});
85-
86-
if (!currentServer) return 1;
87-
88-
const licensed = await hasValidLicense(currentServer.organizationId);
89-
return clamp(currentServer.buildsConcurrency, licensed);
90-
};
37+
const normalize = (value: number): number => Math.max(1, Math.floor(value));

‎apps/dokploy/server/queues/queueSetup.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type { DeploymentJob } from "./queue-types";
1212
* Deployment queue.
1313
*
1414
* Self-hosted uses an in-memory, per-group FIFO queue with configurable
15-
* concurrency per server (enterprise-gated). Cloud does not use the queue at
16-
* all — deployments run directly in the background — so we expose a no-op.
15+
* concurrency per server. Cloud does not use the queue at all — deployments
16+
* run directly in the background — so we expose a no-op.
1717
*/
1818

1919
interface DeploymentQueue {

‎packages/server/src/db/schema/web-server-settings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const webServerSettings = pgTable("webServerSettings", {
105105
}),
106106
// Deployment Configuration (self-hosted only)
107107
remoteServersOnly: boolean("remoteServersOnly").notNull().default(false),
108-
// Concurrent builds on the local web server (enterprise-gated to > 1)
108+
// Concurrent builds on the local web server
109109
buildsConcurrency: integer("buildsConcurrency").notNull().default(1),
110110
// Auth Configuration (self-hosted only)
111111
enforceSSO: boolean("enforceSSO").notNull().default(false),

0 commit comments

Comments
 (0)