diff --git a/.github/workflows/dokploy.yml b/.github/workflows/dokploy.yml index 529cd8f7fa..5429446114 100644 --- a/.github/workflows/dokploy.yml +++ b/.github/workflows/dokploy.yml @@ -138,6 +138,8 @@ jobs: needs: [combine-manifests] if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} steps: - name: Checkout uses: actions/checkout@v4 @@ -160,3 +162,80 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + sync-version: + needs: [generate-release] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Sync version to MCP repository + run: | + git clone https://x-access-token:${{ secrets.DOCS_SYNC_TOKEN }}@github.com/dokploy/mcp.git /tmp/mcp-repo + cd /tmp/mcp-repo + + jq --arg v "${{ needs.generate-release.outputs.version }}" '.version = $v' package.json > package.json.tmp + mv package.json.tmp package.json + + npm install -g pnpm + pnpm install + pnpm run fetch-openapi + pnpm run generate + + git config user.name "Dokploy Bot" + git config user.email "bot@dokploy.com" + git add -A + git commit -m "chore: bump version to ${{ needs.generate-release.outputs.version }}" \ + -m "Source: ${{ github.repository }}@${{ github.sha }}" \ + --allow-empty + git push + + echo "✅ MCP repo synced to version ${{ needs.generate-release.outputs.version }}" + + - name: Sync version to CLI repository + run: | + git clone https://x-access-token:${{ secrets.DOCS_SYNC_TOKEN }}@github.com/dokploy/cli.git /tmp/cli-repo + cd /tmp/cli-repo + + jq --arg v "${{ needs.generate-release.outputs.version }}" '.version = $v' package.json > package.json.tmp + mv package.json.tmp package.json + + cp ${{ github.workspace }}/openapi.json ./openapi.json + npm install -g pnpm + pnpm install + pnpm run generate + + git config user.name "Dokploy Bot" + git config user.email "bot@dokploy.com" + git add -A + git commit -m "chore: bump version to ${{ needs.generate-release.outputs.version }}" \ + -m "Source: ${{ github.repository }}@${{ github.sha }}" \ + --allow-empty + git push + + echo "✅ CLI repo synced to version ${{ needs.generate-release.outputs.version }}" + + - name: Sync version to SDK repository + run: | + git clone https://x-access-token:${{ secrets.DOCS_SYNC_TOKEN }}@github.com/dokploy/sdk.git /tmp/sdk-repo + cd /tmp/sdk-repo + + jq --arg v "${{ needs.generate-release.outputs.version }}" '.version = $v' package.json > package.json.tmp + mv package.json.tmp package.json + + cp ${{ github.workspace }}/openapi.json ./openapi.json + npm install -g pnpm + pnpm install + pnpm run generate + + git config user.name "Dokploy Bot" + git config user.email "bot@dokploy.com" + git add -A + git commit -m "chore: bump version to ${{ needs.generate-release.outputs.version }}" \ + -m "Source: ${{ github.repository }}@${{ github.sha }}" \ + --allow-empty + git push + + echo "✅ SDK repo synced to version ${{ needs.generate-release.outputs.version }}" diff --git a/.github/workflows/sync-version.yml b/.github/workflows/sync-version.yml deleted file mode 100644 index 5e8ccb7067..0000000000 --- a/.github/workflows/sync-version.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Sync version to MCP and CLI repos - -on: - release: - types: [published] - push: - tags: - - 'v*' - workflow_dispatch: - -jobs: - sync-version: - name: Sync version to external repos - runs-on: ubuntu-latest - steps: - - name: Checkout Dokploy repository - uses: actions/checkout@v4 - - - name: Get version - id: get_version - run: | - VERSION=$(jq -r .version apps/dokploy/package.json | sed 's/^v//') - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "Version: $VERSION" - - - name: Sync version to MCP repository - run: | - git clone https://x-access-token:${{ secrets.DOCS_SYNC_TOKEN }}@github.com/dokploy/mcp.git /tmp/mcp-repo - cd /tmp/mcp-repo - - # Regenerate tools from latest OpenAPI spec - npm install -g pnpm - pnpm install - pnpm run fetch-openapi - pnpm run generate - - # Bump version after install so pnpm install doesn't overwrite it - jq --arg v "${{ steps.get_version.outputs.version }}" '.version = $v' package.json > package.json.tmp - mv package.json.tmp package.json - - git config user.name "Dokploy Bot" - git config user.email "bot@dokploy.com" - - git add -A - git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" \ - -m "Source: ${{ github.repository }}@${{ github.sha }}" \ - -m "Release: ${{ github.event.release.html_url }}" \ - --allow-empty - - git push - - - - name: Sync version to CLI repository - run: | - git clone https://x-access-token:${{ secrets.DOCS_SYNC_TOKEN }}@github.com/dokploy/cli.git /tmp/cli-repo - - cd /tmp/cli-repo - - # Copy latest openapi spec and regenerate commands - cp ${{ github.workspace }}/openapi.json ./openapi.json - npm install -g pnpm - pnpm install - pnpm run generate - - # Bump version after install so pnpm install doesn't overwrite it - if [ -f package.json ]; then - jq --arg v "${{ steps.get_version.outputs.version }}" '.version = $v' package.json > package.json.tmp - mv package.json.tmp package.json - fi - - git config user.name "Dokploy Bot" - git config user.email "bot@dokploy.com" - - git add -A - git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" \ - -m "Source: ${{ github.repository }}@${{ github.sha }}" \ - -m "Release: ${{ github.event.release.html_url }}" \ - --allow-empty - - git push - - echo "CLI repo synced to version ${{ steps.get_version.outputs.version }}" - diff --git a/apps/dokploy/__test__/compose/domain/labels.test.ts b/apps/dokploy/__test__/compose/domain/labels.test.ts index ec8e9edc70..dce69cfe4f 100644 --- a/apps/dokploy/__test__/compose/domain/labels.test.ts +++ b/apps/dokploy/__test__/compose/domain/labels.test.ts @@ -103,6 +103,51 @@ describe("createDomainLabels", () => { ); }); + it("should add tls=true for certificateType none on websecure entrypoint", async () => { + const noneDomain = { + ...baseDomain, + https: true, + certificateType: "none" as const, + }; + const labels = await createDomainLabels(appName, noneDomain, "websecure"); + expect(labels).toContain( + "traefik.http.routers.test-app-1-websecure.tls=true", + ); + // no cert resolver should be set when relying on a default/custom cert + expect(labels).not.toContain( + "traefik.http.routers.test-app-1-websecure.tls.certresolver=letsencrypt", + ); + }); + + it("should not add tls=true for certificateType none on web entrypoint", async () => { + const noneDomain = { + ...baseDomain, + https: true, + certificateType: "none" as const, + }; + const labels = await createDomainLabels(appName, noneDomain, "web"); + expect(labels).not.toContain( + "traefik.http.routers.test-app-1-web.tls=true", + ); + }); + + it("should add tls=true for certificateType none on a custom https entrypoint", async () => { + const noneDomain = { + ...baseDomain, + https: true, + customEntrypoint: "websecure-custom", + certificateType: "none" as const, + }; + const labels = await createDomainLabels( + appName, + noneDomain, + "websecure-custom", + ); + expect(labels).toContain( + "traefik.http.routers.test-app-1-websecure-custom.tls=true", + ); + }); + it("should handle different ports correctly", async () => { const customPortDomain = { ...baseDomain, port: 3000 }; const labels = await createDomainLabels(appName, customPortDomain, "web"); diff --git a/apps/dokploy/__test__/deploy/should-deploy.test.ts b/apps/dokploy/__test__/deploy/should-deploy.test.ts new file mode 100644 index 0000000000..d9a1c02446 --- /dev/null +++ b/apps/dokploy/__test__/deploy/should-deploy.test.ts @@ -0,0 +1,41 @@ +import { shouldDeploy } from "@dokploy/server"; +import { describe, expect, it } from "vitest"; + +describe("shouldDeploy", () => { + it("should deploy when no watch paths are configured", () => { + expect(shouldDeploy(null, ["src/index.ts"])).toBe(true); + expect(shouldDeploy([], ["src/index.ts"])).toBe(true); + }); + + it("should deploy when watch paths match modified files", () => { + expect(shouldDeploy(["src/**"], ["src/index.ts"])).toBe(true); + expect(shouldDeploy(["apps/web/**"], ["apps/web/page.tsx"])).toBe(true); + }); + + it("should not deploy when watch paths do not match", () => { + expect(shouldDeploy(["src/**"], ["docs/readme.md"])).toBe(false); + }); + + it("should not throw when modified files contain non-string values", () => { + expect(() => + shouldDeploy(["src/**"], ["src/index.ts", undefined, null] as any), + ).not.toThrow(); + expect( + shouldDeploy(["src/**"], ["src/index.ts", undefined, null] as any), + ).toBe(true); + }); + + it("should not throw when modified files are undefined or null", () => { + expect(() => shouldDeploy(["src/**"], undefined)).not.toThrow(); + expect(() => shouldDeploy(["src/**"], null)).not.toThrow(); + expect(shouldDeploy(["src/**"], undefined)).toBe(false); + expect(shouldDeploy(["src/**"], null)).toBe(false); + }); + + it("should not throw when every modified file is non-string", () => { + expect(() => + shouldDeploy(["src/**"], [undefined, undefined] as any), + ).not.toThrow(); + expect(shouldDeploy(["src/**"], [undefined, undefined] as any)).toBe(false); + }); +}); diff --git a/apps/dokploy/__test__/utils/backups.test.ts b/apps/dokploy/__test__/utils/backups.test.ts index 2c1e5decc9..8016a2c88b 100644 --- a/apps/dokploy/__test__/utils/backups.test.ts +++ b/apps/dokploy/__test__/utils/backups.test.ts @@ -1,4 +1,9 @@ -import { normalizeS3Path } from "@dokploy/server/utils/backups/utils"; +import { + buildRcloneDestination, + getDestinationRoot, + getS3Credentials, + normalizeS3Path, +} from "@dokploy/server/utils/backups/utils"; import { describe, expect, test } from "vitest"; describe("normalizeS3Path", () => { @@ -59,3 +64,46 @@ describe("normalizeS3Path", () => { expect(normalizeS3Path("instance-backups")).toBe("instance-backups/"); }); }); + +describe("buildRcloneDestination", () => { + test("should append relative paths to remote roots", () => { + expect(buildRcloneDestination(":s3:bucket", "app/file.tar.gz")).toBe( + ":s3:bucket/app/file.tar.gz", + ); + expect( + buildRcloneDestination(":sftp,host=example.com:backups", "app"), + ).toBe(":sftp,host=example.com:backups/app"); + expect(buildRcloneDestination("remote/root/", "app")).toBe( + "remote/root/app", + ); + }); + + test("should preserve bare roots when no path is provided", () => { + expect(buildRcloneDestination(":s3:bucket", "")).toBe(":s3:bucket"); + expect(buildRcloneDestination("remote/root", "")).toBe("remote/root"); + }); +}); + +describe("custom destination helpers", () => { + const customDestination = { + provider: "Custom", + bucket: "backups", + endpoint: ":sftp,host=example.com:backups", + additionalFlags: ["--ssh-no-check-known-hosts"], + accessKey: "", + secretAccessKey: "", + region: "", + }; + + test("should use the endpoint as the destination root for custom remotes", () => { + expect(getDestinationRoot(customDestination)).toBe( + ":sftp,host=example.com:backups", + ); + }); + + test("should only return additional flags for custom destinations", () => { + expect(getS3Credentials(customDestination)).toEqual([ + "--ssh-no-check-known-hosts", + ]); + }); +}); diff --git a/apps/dokploy/__test__/wss/readValidDirectory.test.ts b/apps/dokploy/__test__/wss/readValidDirectory.test.ts index 8107bb591b..29d3152eb0 100644 --- a/apps/dokploy/__test__/wss/readValidDirectory.test.ts +++ b/apps/dokploy/__test__/wss/readValidDirectory.test.ts @@ -78,4 +78,20 @@ describe("readValidDirectory (path traversal)", () => { it("returns false for empty string (resolves to cwd)", () => { expect(readValidDirectory("")).toBe(false); }); + + it("returns true for Next.js dynamic route paths with square brackets", () => { + expect( + readValidDirectory( + `${BASE}/applications/myapp/code/app/api/[id]/route.ts`, + ), + ).toBe(true); + expect( + readValidDirectory(`${BASE}/applications/myapp/code/pages/[slug].tsx`), + ).toBe(true); + expect( + readValidDirectory( + `${BASE}/applications/myapp/code/app/[...catch]/page.tsx`, + ), + ).toBe(true); + }); }); diff --git a/apps/dokploy/components/dashboard/application/advanced/show-resources.tsx b/apps/dokploy/components/dashboard/application/advanced/show-resources.tsx index fa2bda6293..f2a48bae70 100644 --- a/apps/dokploy/components/dashboard/application/advanced/show-resources.tsx +++ b/apps/dokploy/components/dashboard/application/advanced/show-resources.tsx @@ -224,7 +224,7 @@ export const ShowResources = ({ id, type }: Props) => { Memory Limit - + @@ -263,7 +263,7 @@ export const ShowResources = ({ id, type }: Props) => { Memory Reservation - + @@ -303,7 +303,7 @@ export const ShowResources = ({ id, type }: Props) => { CPU Limit - + @@ -343,7 +343,7 @@ export const ShowResources = ({ id, type }: Props) => { CPU Reservation - + @@ -379,7 +379,7 @@ export const ShowResources = ({ id, type }: Props) => { Ulimits - + diff --git a/apps/dokploy/components/dashboard/application/domains/handle-domain.tsx b/apps/dokploy/components/dashboard/application/domains/handle-domain.tsx index 4edd6597f4..b232591e4b 100644 --- a/apps/dokploy/components/dashboard/application/domains/handle-domain.tsx +++ b/apps/dokploy/components/dashboard/application/domains/handle-domain.tsx @@ -806,7 +806,7 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => { Middlewares - +
?
diff --git a/apps/dokploy/components/dashboard/compose/general/generic/save-bitbucket-provider-compose.tsx b/apps/dokploy/components/dashboard/compose/general/generic/save-bitbucket-provider-compose.tsx index 745f72d3bd..330243ae21 100644 --- a/apps/dokploy/components/dashboard/compose/general/generic/save-bitbucket-provider-compose.tsx +++ b/apps/dokploy/components/dashboard/compose/general/generic/save-bitbucket-provider-compose.tsx @@ -422,7 +422,7 @@ export const SaveBitbucketProviderCompose = ({ composeId }: Props) => { Watch Paths - +
?
diff --git a/apps/dokploy/components/dashboard/compose/general/generic/save-github-provider-compose.tsx b/apps/dokploy/components/dashboard/compose/general/generic/save-github-provider-compose.tsx index 10075fb5c6..0c07e688a4 100644 --- a/apps/dokploy/components/dashboard/compose/general/generic/save-github-provider-compose.tsx +++ b/apps/dokploy/components/dashboard/compose/general/generic/save-github-provider-compose.tsx @@ -449,7 +449,7 @@ export const SaveGithubProviderCompose = ({ composeId }: Props) => { Watch Paths - +
?
diff --git a/apps/dokploy/components/dashboard/compose/general/generic/save-gitlab-provider-compose.tsx b/apps/dokploy/components/dashboard/compose/general/generic/save-gitlab-provider-compose.tsx index a81774fec9..cad08f6bf0 100644 --- a/apps/dokploy/components/dashboard/compose/general/generic/save-gitlab-provider-compose.tsx +++ b/apps/dokploy/components/dashboard/compose/general/generic/save-gitlab-provider-compose.tsx @@ -440,7 +440,7 @@ export const SaveGitlabProviderCompose = ({ composeId }: Props) => { Watch Paths - +
?
diff --git a/apps/dokploy/components/dashboard/docker/logs/analyze-logs.tsx b/apps/dokploy/components/dashboard/docker/logs/analyze-logs.tsx index d40697437c..1b8ec736a6 100644 --- a/apps/dokploy/components/dashboard/docker/logs/analyze-logs.tsx +++ b/apps/dokploy/components/dashboard/docker/logs/analyze-logs.tsx @@ -90,7 +90,7 @@ export function AnalyzeLogs({ logs, context }: Props) { disabled={logs.length === 0} title="Analyze logs with AI" > - + AI diff --git a/apps/dokploy/components/dashboard/docker/logs/docker-logs-id.tsx b/apps/dokploy/components/dashboard/docker/logs/docker-logs-id.tsx index 8d8842ac09..3a5f460e91 100644 --- a/apps/dokploy/components/dashboard/docker/logs/docker-logs-id.tsx +++ b/apps/dokploy/components/dashboard/docker/logs/docker-logs-id.tsx @@ -347,11 +347,13 @@ export const DockerLogsId: React.FC = ({ title={isPaused ? "Resume logs" : "Pause logs"} > {isPaused ? ( - + ) : ( - + )} - {isPaused ? "Resume" : "Pause"} + + {isPaused ? "Resume" : "Pause"} + {isPaused && ( - +
- + Logs paused {messageBuffer.length > 0 && ( diff --git a/apps/dokploy/components/dashboard/project/add-import.tsx b/apps/dokploy/components/dashboard/project/add-import.tsx new file mode 100644 index 0000000000..034710e9cf --- /dev/null +++ b/apps/dokploy/components/dashboard/project/add-import.tsx @@ -0,0 +1,494 @@ +import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema"; +import { Code2, FileInput, Globe2, HardDrive, HelpCircle } from "lucide-react"; +import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { toast } from "sonner"; +import { z } from "zod"; +import { AlertBlock } from "@/components/shared/alert-block"; +import { CodeEditor } from "@/components/shared/code-editor"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Separator } from "@/components/ui/separator"; +import { Textarea } from "@/components/ui/textarea"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { slugify } from "@/lib/slug"; +import { api } from "@/utils/api"; +import { APP_NAME_MESSAGE, APP_NAME_REGEX } from "@/utils/schema"; + +const AddImportSchema = z.object({ + name: z.string().min(1, { message: "Name is required" }), + appName: z + .string() + .min(1, { message: "App name is required" }) + .regex(APP_NAME_REGEX, { message: APP_NAME_MESSAGE }), + base64: z.string().min(1, { message: "Base64 content is required" }), + serverId: z.string().optional(), +}); + +type AddImport = z.infer; + +type TemplateInfo = { + compose: string; + template: { + domains: Array<{ + serviceName: string; + port: number; + path?: string; + host?: string; + }>; + envs: string[]; + mounts: Array<{ filePath: string; content: string }>; + }; +}; + +interface Props { + environmentId: string; + projectName?: string; +} + +export const AddImport = ({ environmentId, projectName }: Props) => { + const utils = api.useUtils(); + const [visible, setVisible] = useState(false); + const [previewOpen, setPreviewOpen] = useState(false); + const [mountOpen, setMountOpen] = useState(false); + const [selectedMount, setSelectedMount] = useState<{ + filePath: string; + content: string; + } | null>(null); + const [templateInfo, setTemplateInfo] = useState(null); + + const slug = slugify(projectName); + const { data: isCloud } = api.settings.isCloud.useQuery(); + const { data: servers } = api.server.withSSHKey.useQuery(); + const shouldShowServerDropdown = !!(servers && servers.length > 0); + + const { mutateAsync: previewTemplate, isPending: isProcessing } = + api.compose.previewTemplate.useMutation(); + const { mutateAsync: createCompose, isPending: isCreating } = + api.compose.create.useMutation(); + const { mutateAsync: importCompose, isPending: isImporting } = + api.compose.import.useMutation(); + + const form = useForm({ + defaultValues: { name: "", appName: `${slug}-`, base64: "" }, + resolver: zodResolver(AddImportSchema), + }); + + const resetAll = () => { + form.reset({ name: "", appName: `${slug}-`, base64: "" }); + setTemplateInfo(null); + setPreviewOpen(false); + setMountOpen(false); + setSelectedMount(null); + }; + + const handleOpenChange = (open: boolean) => { + if (!open) resetAll(); + setVisible(open); + }; + + const handleLoad = async (data: AddImport) => { + try { + const result = await previewTemplate({ + appName: data.appName, + base64: data.base64.trim(), + serverId: data.serverId === "dokploy" ? undefined : data.serverId, + }); + setTemplateInfo(result); + setPreviewOpen(true); + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Error processing template", + ); + } + }; + + const handleImport = async () => { + const data = form.getValues(); + try { + const compose = await createCompose({ + name: data.name, + appName: data.appName, + environmentId, + composeType: "docker-compose", + serverId: data.serverId === "dokploy" ? undefined : data.serverId, + }); + await importCompose({ + composeId: compose.composeId, + base64: data.base64.trim(), + }); + toast.success("Compose imported successfully"); + await utils.environment.one.invalidate({ environmentId }); + resetAll(); + setVisible(false); + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Error importing compose", + ); + } + }; + + const handleCancelPreview = () => { + setPreviewOpen(false); + setTemplateInfo(null); + }; + + return ( + <> + + + e.preventDefault()} + > + + Import + + + + + Import Compose + + Paste a base64-encoded compose export to preview and import it + + + +
+ + ( + + Name + + { + const val = e.target.value || ""; + form.setValue( + "appName", + `${slug}-${slugify(val.trim())}`, + ); + field.onChange(val); + }} + /> + + + + )} + /> + + {shouldShowServerDropdown && ( + ( + + + + + + Select a Server {!isCloud ? "(Optional)" : ""} + + + + + + If no server is selected, the compose will be + deployed on the server where the user is logged + in. + + + + + + + + )} + /> + )} + + ( + + App Name + + + + + + )} + /> + + ( + + Configuration (Base64) + +