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
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 @@ -48,6 +48,7 @@ const baseApp: ApplicationNested = {
enableSubmodules: false,
applicationStatus: "done",
triggerType: "push",
tagPatterns: [],
appName: "",
autoDeploy: true,
endpointSpecSwarm: null,
Expand Down
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 @@ -39,6 +39,7 @@ const baseApp: ApplicationNested = {
previewBuildArgs: null,
previewBuildSecrets: null,
triggerType: "push",
tagPatterns: [],
previewCertificateType: "none",
previewEnv: null,
previewHttps: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
import { TagPatternsField } from "@/components/dashboard/shared/tag-patterns-field";
import { GithubIcon } from "@/components/icons/data-tools-icons";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -59,6 +60,7 @@ const GithubProviderSchema = z.object({
githubId: z.string().min(1, "Github Provider is required"),
watchPaths: z.array(z.string()).optional(),
triggerType: z.enum(["push", "tag"]).default("push"),
tagPatterns: z.array(z.string()).optional().default([]),
enableSubmodules: z.boolean().default(false),
});

Expand All @@ -85,6 +87,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
githubId: "",
branch: "",
triggerType: "push",
tagPatterns: [],
enableSubmodules: false,
},
resolver: zodResolver(GithubProviderSchema),
Expand Down Expand Up @@ -119,6 +122,22 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
},
);

const { data: tags, isLoading: isLoadingTags } =
api.github.getGithubTags.useQuery(
{
owner: repository?.owner || "",
repo: repository?.repo || "",
githubId: githubId || "",
},
{
enabled:
!!repository?.owner &&
!!repository?.repo &&
!!githubId &&
triggerType === "tag",
},
);

useEffect(() => {
if (data) {
form.reset({
Expand All @@ -131,6 +150,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
githubId: data.githubId || "",
watchPaths: data.watchPaths || [],
triggerType: data.triggerType || "push",
tagPatterns: data.tagPatterns || [],
enableSubmodules: data.enableSubmodules ?? false,
});
}
Expand All @@ -146,6 +166,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
githubId: data.githubId,
watchPaths: data.watchPaths || [],
triggerType: data.triggerType,
tagPatterns: data.tagPatterns || [],
enableSubmodules: data.enableSubmodules,
})
.then(async () => {
Expand Down Expand Up @@ -429,6 +450,20 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
</FormItem>
)}
/>
{triggerType === "tag" && (
<FormField
control={form.control}
name="tagPatterns"
render={({ field }) => (
<TagPatternsField
value={field.value}
onChange={field.onChange}
tags={tags}
isLoadingTags={isLoadingTags}
/>
)}
/>
)}
{triggerType === "push" && (
<FormField
control={form.control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
import { TagPatternsField } from "@/components/dashboard/shared/tag-patterns-field";
import { GithubIcon } from "@/components/icons/data-tools-icons";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -59,6 +60,7 @@ const GithubProviderSchema = z.object({
githubId: z.string().min(1, "Github Provider is required"),
watchPaths: z.array(z.string()).optional(),
triggerType: z.enum(["push", "tag"]).default("push"),
tagPatterns: z.array(z.string()).optional().default([]),
enableSubmodules: z.boolean().default(false),
});

Expand Down Expand Up @@ -86,6 +88,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
branch: "",
watchPaths: [],
triggerType: "push",
tagPatterns: [],
enableSubmodules: false,
},
resolver: zodResolver(GithubProviderSchema),
Expand Down Expand Up @@ -119,6 +122,22 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
},
);

const { data: tags, isLoading: isLoadingTags } =
api.github.getGithubTags.useQuery(
{
owner: repository?.owner || "",
repo: repository?.repo || "",
githubId: githubId || "",
},
{
enabled:
!!repository?.owner &&
!!repository?.repo &&
!!githubId &&
triggerType === "tag",
},
);

useEffect(() => {
if (data) {
form.reset({
Expand All @@ -131,6 +150,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
githubId: data.githubId || "",
watchPaths: data.watchPaths || [],
triggerType: data.triggerType || "push",
tagPatterns: data.tagPatterns || [],
enableSubmodules: data.enableSubmodules ?? false,
});
}
Expand All @@ -149,6 +169,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
watchPaths: data.watchPaths,
enableSubmodules: data.enableSubmodules,
triggerType: data.triggerType,
tagPatterns: data.tagPatterns,
})
.then(async () => {
toast.success("Service Provider Saved");
Expand Down Expand Up @@ -431,6 +452,20 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => {
</FormItem>
)}
/>
{triggerType === "tag" && (
<FormField
control={form.control}
name="tagPatterns"
render={({ field }) => (
<TagPatternsField
value={field.value}
onChange={field.onChange}
tags={tags}
isLoadingTags={isLoadingTags}
/>
)}
/>
)}
{triggerType === "push" && (
<FormField
control={form.control}
Expand Down
165 changes: 165 additions & 0 deletions apps/dokploy/components/dashboard/shared/tag-patterns-field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { HelpCircle, X } from "lucide-react";
import { useState } from "react";
import { Badge } from "@/components/ui/badge";
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
} from "@/components/ui/command";
import {
FormControl,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";

interface TagPatternsFieldProps {
value: string[] | undefined;
onChange: (value: string[]) => void;
tags: { name: string }[] | undefined;
isLoadingTags: boolean;
}

export const TagPatternsField = ({
value,
onChange,
tags,
isLoadingTags,
}: TagPatternsFieldProps) => {
const [open, setOpen] = useState(false);
const [inputValue, setInputValue] = useState("");

const selectedValues = value || [];
const availableTags = tags?.map((t) => t.name) || [];

const handleSelect = (tagValue: string) => {
if (!selectedValues.includes(tagValue)) {
onChange([...selectedValues, tagValue]);
}
setInputValue("");
};

const handleRemove = (tagValue: string) => {
onChange(selectedValues.filter((v) => v !== tagValue));
};

const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter" && inputValue.trim()) {
e.preventDefault();
handleSelect(inputValue.trim());
}
};

return (
<FormItem className="md:col-span-2">
<div className="flex items-center gap-2">
<FormLabel>Tag Patterns</FormLabel>
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger type="button">
<HelpCircle className="size-4 text-muted-foreground hover:text-foreground transition-colors cursor-pointer" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p>
Select existing tags or type glob patterns (e.g., v*, release-*,
v[0-9].*). Leave empty to deploy on any tag.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>

<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<FormControl>
<div className="flex min-h-10 w-full flex-wrap gap-1 rounded-md border border-input bg-input px-3 py-2 text-sm ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 cursor-pointer">
{selectedValues.length > 0 ? (
selectedValues.map((tagValue) => (
<Badge
key={tagValue}
variant="secondary"
className="flex items-center gap-1"
>
{tagValue}
<X
className="size-3 cursor-pointer hover:text-destructive"
onClick={(e) => {
e.stopPropagation();
handleRemove(tagValue);
}}
/>
</Badge>
))
) : (
<span className="text-muted-foreground">
{isLoadingTags
? "Loading tags..."
: "Select tags or type patterns (empty = any tag)"}
</span>
)}
</div>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[400px] p-0" align="start">
<Command>
<CommandInput
placeholder="Search tags or type a pattern..."
value={inputValue}
onValueChange={setInputValue}
onKeyDown={handleKeyDown}
/>
<CommandEmpty>
{inputValue ? (
<button
type="button"
className="w-full px-2 py-1.5 text-left text-sm hover:bg-accent"
onClick={() => handleSelect(inputValue)}
>
Add pattern: "{inputValue}"
</button>
) : (
"No tags found. Type a pattern and press Enter."
)}
</CommandEmpty>
<ScrollArea className="h-64">
<CommandGroup>
{availableTags
.filter((tag) => !selectedValues.includes(tag))
.map((tag) => (
<CommandItem
key={tag}
value={tag}
onSelect={() => handleSelect(tag)}
>
{tag}
</CommandItem>
))}
</CommandGroup>
</ScrollArea>
</Command>
</PopoverContent>
</Popover>

{selectedValues.length === 0 && (
<p className="text-xs text-muted-foreground">
No patterns configured - will deploy on any tag
</p>
)}
<FormMessage />
</FormItem>
);
};
2 changes: 2 additions & 0 deletions apps/dokploy/drizzle/0134_volatile_doomsday.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "application" ADD COLUMN "tagPatterns" text[] DEFAULT '{}';--> statement-breakpoint
ALTER TABLE "compose" ADD COLUMN "tagPatterns" text[] DEFAULT '{}';
Loading