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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/dokploy/__test__/deploy/github-webhook-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({
queueAdd: vi.fn(),
verify: vi.fn(),
shouldDeploy: vi.fn(),
matchesTag: vi.fn(),
}));

vi.mock("drizzle-orm", () => ({
Expand Down Expand Up @@ -63,6 +64,7 @@ vi.mock("@dokploy/server/db", () => ({
vi.mock("@dokploy/server", () => ({
IS_CLOUD: false,
shouldDeploy: mocks.shouldDeploy,
matchesTag: mocks.matchesTag,
checkUserRepositoryPermissions: vi.fn(),
createPreviewDeployment: vi.fn(),
createSecurityBlockedComment: vi.fn(),
Expand Down Expand Up @@ -167,6 +169,7 @@ describe("GitHub app webhook auto-deploy", () => {
});
mocks.verify.mockResolvedValue(true);
mocks.shouldDeploy.mockReturnValue(true);
mocks.matchesTag.mockReturnValue(true);
mocks.composeFindMany.mockResolvedValue([]);
mocks.queueAdd.mockResolvedValue({ id: "job-id" });

Expand Down
1 change: 1 addition & 0 deletions apps/dokploy/__test__/drop/drop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const baseApp: ApplicationNested = {
giteaRepository: "",
cleanCache: false,
watchPaths: [],
tagFilter: null,
rollbackRegistryId: "",
rollbackRegistry: null,
deployments: [],
Expand Down
25 changes: 25 additions & 0 deletions apps/dokploy/__test__/tag-filter/matches-tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { matchesTag } from "@dokploy/server";
import { describe, expect, it } from "vitest";

describe("matchesTag", () => {
it("deploys on any tag when filter is empty", () => {
expect(matchesTag(null, "web-v1.0.0")).toBe(true);
expect(matchesTag(undefined, "web-v1.0.0")).toBe(true);
expect(matchesTag("", "web-v1.0.0")).toBe(true);
});

it("matches a simple glob prefix", () => {
expect(matchesTag("web-*", "web-v0.7.1")).toBe(true);
expect(matchesTag("web-*", "api-v0.5.1")).toBe(false);
});

it("matches a brace-expansion glob for multiple prefixes", () => {
expect(matchesTag("{web-*,shared-*}", "web-v0.7.1")).toBe(true);
expect(matchesTag("{web-*,shared-*}", "shared-v0.5.1")).toBe(true);
expect(matchesTag("{web-*,shared-*}", "api-v0.5.1")).toBe(false);
});

it("does not match an unrelated tag name", () => {
expect(matchesTag("api-v*", "web-v0.7.1")).toBe(false);
});
});
1 change: 1 addition & 0 deletions apps/dokploy/__test__/traefik/traefik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const baseApp: ApplicationNested = {
dockerBuildStage: "",
registryUrl: "",
watchPaths: [],
tagFilter: null,
buildArgs: null,
buildSecrets: null,
isPreviewDeploymentsActive: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const GithubProviderSchema = z.object({
.regex(VALID_BRANCH_REGEX, "Invalid branch name"),
githubId: z.string().min(1, "Github Provider is required"),
watchPaths: z.array(z.string()).optional(),
tagFilter: z.string().optional(),
triggerType: z.enum(["push", "tag"]).default("push"),
enableSubmodules: z.boolean().default(false),
});
Expand All @@ -89,6 +90,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
},
githubId: "",
branch: "",
tagFilter: "",
triggerType: "push",
enableSubmodules: false,
},
Expand Down Expand Up @@ -140,6 +142,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
buildPath: data.buildPath || "/",
githubId: data.githubId || "",
watchPaths: data.watchPaths || [],
tagFilter: data.tagFilter || "",
triggerType: data.triggerType || "push",
enableSubmodules: data.enableSubmodules ?? false,
});
Expand All @@ -155,6 +158,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
buildPath: data.buildPath,
githubId: data.githubId,
watchPaths: data.watchPaths || [],
tagFilter: data.tagFilter,
triggerType: data.triggerType,
enableSubmodules: data.enableSubmodules,
})
Expand Down Expand Up @@ -552,6 +556,36 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
)}
/>
)}
{triggerType === "tag" && (
<FormField
control={form.control}
name="tagFilter"
render={({ field }) => (
<FormItem className="md:col-span-2">
<div className="flex items-center gap-2">
<FormLabel>Tag Filter</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircle className="size-4 text-muted-foreground hover:text-foreground transition-colors cursor-pointer" />
</TooltipTrigger>
<TooltipContent>
<p>
Only deploy on tags matching this glob (e.g.
web-*). Leave empty to deploy on any tag.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
<FormControl>
<Input placeholder="e.g. web-*" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}

<FormField
control={form.control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const GithubProviderSchema = z.object({
.regex(VALID_BRANCH_REGEX, "Invalid branch name"),
githubId: z.string().min(1, "Github Provider is required"),
watchPaths: z.array(z.string()).optional(),
tagFilter: z.string().optional(),
triggerType: z.enum(["push", "tag"]).default("push"),
enableSubmodules: z.boolean().default(false),
});
Expand Down Expand Up @@ -90,6 +91,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
githubId: "",
branch: "",
watchPaths: [],
tagFilter: "",
triggerType: "push",
enableSubmodules: false,
},
Expand Down Expand Up @@ -140,6 +142,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
composePath: data.composePath,
githubId: data.githubId || "",
watchPaths: data.watchPaths || [],
tagFilter: data.tagFilter || "",
triggerType: data.triggerType || "push",
enableSubmodules: data.enableSubmodules ?? false,
});
Expand All @@ -157,6 +160,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
sourceType: "github",
composeStatus: "idle",
watchPaths: data.watchPaths,
tagFilter: data.tagFilter,
enableSubmodules: data.enableSubmodules,
triggerType: data.triggerType,
})
Expand Down Expand Up @@ -548,6 +552,36 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
)}
/>
)}
{triggerType === "tag" && (
<FormField
control={form.control}
name="tagFilter"
render={({ field }) => (
<FormItem className="md:col-span-2">
<div className="flex items-center gap-2">
<FormLabel>Tag Filter</FormLabel>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircle className="size-4 text-muted-foreground hover:text-foreground transition-colors cursor-pointer" />
</TooltipTrigger>
<TooltipContent>
<p>
Only deploy on tags matching this glob (e.g.
web-*). Leave empty to deploy on any tag.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
<FormControl>
<Input placeholder="e.g. web-*" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}
<FormField
control={form.control}
name="enableSubmodules"
Expand Down
2 changes: 2 additions & 0 deletions apps/dokploy/drizzle/0180_shocking_thena.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "application" ADD COLUMN "tagFilter" text;--> statement-breakpoint
ALTER TABLE "compose" ADD COLUMN "tagFilter" text;
Loading
Loading