Repository navigation
feat: Caddy as an optional web server, chosen per server - #5567
masonjames wants to merge 10 commits into
Conversation
Which proxy serves a server's domains becomes a column, traefik by default: on the web server settings for the Dokploy host, and on each remote server. getWebServerProvider reads it, and always answers traefik on Dokploy Cloud. Nothing sets the column until the last commit of this series, so every server stays on Traefik. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| return true; | ||
| return application.serverId; | ||
| }); | ||
| await syncCaddy(serverId); |
There was a problem hiding this comment.
Saved password rule stays inactive
When an existing route gets its first password rule, createSecurity saves the rule before syncCaddy reloads Caddy. If Caddy rejects the reload, the rule stays saved but the old route still accepts requests without a password. Roll back the saved rule or keep the route closed until the reload succeeds.
How this was verified: The security row commits before the reload, and a rejected reload leaves Caddy serving its previous configuration.
There was a problem hiding this comment.
Right. With Traefik a rule is saved only if its middleware was written, because both happen in one transaction. The Caddy sync has to run after the commit to see the row, so a refused reload left the rule saved and the route open.
createSecurity now deletes the rule again when that sync fails, and the admin gets Caddy's message as before (305d4dc). There is a test for it in hooks.test.ts. On a real instance with a broken file in sites/, creating a first rule is refused, the rule is not listed afterwards, and the route answers as the list says.
Updating or deleting a rule is left as it was: the change is saved, the error says it is not live, and until a sync succeeds the route keeps asking for the previous credentials.
| ), | ||
| }); | ||
| } | ||
| if (!serverId && settings?.host) { |
There was a problem hiding this comment.
Default dashboard address disappears
On a fresh self-hosted setup, settings.host can be empty while Traefik serves the dashboard at dokploy.docker.localhost. loadCaddyState then omits that route. After a switch to Caddy, the default dashboard address returns 404. Keep the default dashboard route when no host has been assigned.
There was a problem hiding this comment.
Right, and the dry run did not mention it either, because it counts that default router as Dokploy's own.
On the Dokploy host loadCaddyState now always adds the dashboard's route: at the assigned host, or at dokploy.docker.localhost over HTTP while none is assigned, which is what createDefaultServerTraefikConfig gives Traefik (305d4dc). There is a test for it in sync.test.ts. On a real instance without an assigned host, http://dokploy.docker.localhost/api/health answers 200 under Traefik, under Caddy after the switch, and under Traefik after switching back.
b98f51d to
8f096dc
Compare
renderCaddyfile is a pure function from a server's routes and uploaded certificates to the text of one Caddyfile. A route does what Traefik does for the same domain: path prefixes that match by case, strip and add prefix, redirectRegex, basic auth, HTTP to HTTPS, and a 404 for an unknown host or path. Every value from the database is quoted, escaped or matched against a strict pattern. A route that cannot be written safely answers 503 in its own place instead of falling through to a less specific one. One test file reads the output. The other runs it in the stock image, when Docker is available. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every write to a domain, redirect, basic-auth user or uploaded certificate, and every deploy, ends in a sync of its server's Caddy: the Caddyfile is rendered again and Caddy reloads it. Caddy validates before it swaps, so a configuration it refuses leaves the previous one serving. Traefik's own writers run as before, and a server on Traefik returns before anything is done. A change a person makes is waited for, so Caddy's refusal reaches them and stays on record until a sync succeeds. The change itself stays saved, with one exception: a basic-auth user Caddy did not load is deleted again, because it would be listed while its routes still answer without a password. Deploys, deletions and bulk operations sync in the background. Syncs for one server run one at a time, and callers that arrive together share one. On a Caddy server, what Caddy cannot honour is refused instead of saved without effect: forward auth, custom middlewares, entrypoints and certificate resolvers, a redirect Caddy cannot compile, and edits to Traefik's own configuration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a Caddy server the file browser shows the generated Caddyfile, read-only, and the admin's own files in global/ and sites/, which the Caddyfile imports. Nothing else under Caddy's folder can be listed, read or written, however the path is spelled: data/ and config/ hold private keys. A file Caddy rejects is put back, so a mistake cannot block every later change on the server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Caddy serves what is in the database. What an admin added to Traefik by hand, an IP allow-list for example, would stop applying after a switch without anyone noticing. findHandWrittenTraefikConfig lists it: the files and labels on a server are compared with what Dokploy's own writers produce for the same rows, so a change made under a name Dokploy uses is found too. The tests build the server's files with those writers, so they fail when a writer and this comparison drift apart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A dry run shows the Caddyfile Caddy would start with, what blocks the switch, and what Traefik does today that would stop. Certificates Traefik holds are carried over, so Let's Encrypt is not asked for every domain again. The switch is one script per direction. Everything slow happens while the current proxy still serves, and a step that fails, or a script that is interrupted, puts the previous proxy back. The provider column then follows what Docker reports. The tests run both scripts, failure paths included, against a stand-in for Docker. Traefik's files were written all along, so the way back needs no migration. The server's menu, the health check and the update dialog name the proxy that runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8f096dc to
27056ea
Compare
|
Refreshed this contribution against current official canary, preserving the six original feature commits with a normal merge (no history rewrite).
Local Node 24.22.1 / pnpm 10.22.0 validation: 1,644 tests passed, four skipped, excluding only the deployment test file requiring a Swarm-manager host. Workspace type checks, server compilation/bundle, Next production build and changed-file Biome check passed. The clean 200-migration chain was also applied to disposable PostgreSQL 16.10 with default/provider and upstream-field assertions. The PR description now separates these checks from the original October 2 Swarm/UI/Pebble rehearsal, which was not rerun. Independent review record: Claude Opus 5.5 ( The fixes cover migration ordering, new upstream security/telemetry behavior, proxy-switch serialization, certificate validation/removal ordering, domain re-enabling, provider-specific settings, retired-proxy restart policy, and setup error propagation. Remaining limitations are explicit in the PR body: no refreshed full Swarm/UI rehearsal, experimental database migration history, audit-on-reload-failure gaps, nontransactional certificate-file updates, hung-operation recovery, Caddy setup-maintenance restrictions, and the trust required for custom proxy configuration. This is ready for maintainer review, not a production qualification claim. |
|
Weekly source refresh, November 2:
Local verification on Node24.22.1/pnpm10.22.0: 1,721 tests passed, four skipped, with only the known Swarm-host deployment test file excluded. Workspace types, server compilation/bundle, Next build and migration metadata passed. No migration files changed. Biome passed with two warnings reproduced on unchanged upstream and six informational suggestions. The initial upstream vault-test type failure was reproduced independently on untouched canary and corrected with the same optional-call syntax used by neighboring tests. The four skips are all in
These remain CI-gated; I did not enable Swarm or force those cleanup tests to run. The real-Caddy suite was not skipped: all eight cases passed, including bcrypt-backed basic authentication, plus all 15 Caddy sync cases. A separate focused receipt records107passed/four skipped, including mocked SSH keepalive coverage. No real SSH was used. Independent review: actual model Decision/fallback: the main merge risk was silently losing Caddy lifecycle hooks amid upstream concurrency and network changes; merged-source review and local regression tests cover those interactions. The previous head |
|
Weekly source refresh, November 23:
Normal merges preserve the existing branch history and canary PR base. No force-push. Upstream's new server-access restrictions and boot recovery are preserved; Caddy refuses preview SSO before saving it, and restored Traefik gets its restart policy only after a successful start. Caddy's migration is now0206, after seven new upstream migrations. Fresh local validation on Node24.22.1/pnpm10.34.9: 2,082 tests passed, four skipped, including all eight real Caddy-container cases. Only the Swarm-manager-dependent application deployment file was excluded; the four skips are existing CI-gated monitoring-container cases. Workspace types, server compilation/bundle, Next build, contribution-file Biome and Drizzle checks passed. All207 SQL migrations applied to fresh isolated PostgreSQL16.10. The two lint warnings reproduce on unchanged upstream. Removing the new boot/access guard made each targeted regression test fail; restoring them passed. Post-review fixes passed38 focused tests before the full rerun. The final two-string upstream UI correction also received fresh suite/type/Next-build checks. Server and migration files were unchanged by that final merge. Independent review used actual claude-opus-5-5, tools and MCP disabled, explicit sanitized packets:
Remaining limitations are explicit in the updated PR body: old experimental migration histories need reconciliation; hung shared-queue work can stall same-server changes; Caddy boot-start recovery, full Swarm/UI/Pebble and real SSH remain unqualified. Preview SSO configured before switching with no current preview domains can lead to later preview creation being refused. Existing certificate/audit/cleanup and shared-host/trusted-file semantics remain. This is source evidence, not production qualification or approval to merge the feature. Decision/fallback: the main risks were losing new authorization/boot safeguards and migration ordering while retaining Caddy behavior. Local regression tests and independent review cover those changes. Previous head6241f71a remains in history. Both required precommit quality/minimality checks passed. No production access, deployment, image publication, workflow dispatch, production-branch changes or upstream PR merge occurred. Prior dated validation remains historical. |
|
Hi, for now we are not moving with this feature for now. thank you |
What is this PR about?
Caddy as an optional web server for self-hosted Dokploy, chosen per server. Traefik stays the default, and a server that does not switch behaves as it does today.
This is the shape proposed in #1246 (comment); it replaces #4534. This contribution remains separate from my instance-specific production fork.
Current source sync — November 23, 2026
Merged official
Dokploy/dokploy:canaryat5ccc51a9ccbc66a93a3fdd7c523e9cbd03c6fb16into this contribution with normal merges. Updated head:fc652a3d505171886b43cc71814e006b22592766. The PR still targetscanary, as CONTRIBUTING.md requires. The second merge includes a two-string resolver-example correction that landed while the main sync was being validated.Latest stable is v0.31.4, published November 17. Its tag commit
37b34768a00b6fb7b19a0db4dcae64c8fff9dfc8is not a literal ancestor of canary. Its source tree is identical to its second parent,60964dfe79ca5be17e411e840cdb9df8746ccce0, which is an ancestor. This sync includes that stable source and subsequent canary fixes; it does not create a release.The merge preserves upstream server-access and domain restrictions, credential and preview-auth safeguards, server-setup disconnect handling, Compose command fixes and Traefik recovery changes. Caddy endpoints now use upstream's stronger server-access check before provider reads or effects. Caddy also refuses preview SSO before saving the enabled flag. Automatic Traefik restoration and boot recovery leave Caddy servers alone; deliberate rollback re-enables the retired Traefik's restart policy only after a successful start. A policy-update failure is reported without stopping the restored proxy. Cleanup protection retains Caddy and all three upstream Traefik container names.
Caddy's migration moves from 0199 to 0206, after upstream's seven new migrations. All upstream SQL, snapshots and existing journal entries are unchanged. The new snapshot adds only the provider enum and two non-null columns with Traefik defaults. Do not apply this as an automatic upgrade to a database that has already applied an earlier experimental Caddy migration. Its migration history needs explicit reconciliation: the old journal timestamp can skip intervening upstream migrations, and 0206 can then collide with the existing enum/columns. No live database was touched.
Fresh local verification on Node 24.22.1 / pnpm 10.34.9:
deploy/application.real.test.tsfile was excluded. The four skips are the existing CI-gated monitoring-container cases. All eight real Caddy cases ran on local OrbStack. The post-review focused regression run passed 38 tests. Removing the boot guard or server-access check made its regression test fail; restoring the code made both pass.claude-opus-5-5, explicit sanitized packets, cumulative coverage through tree3294b41a74916d0726a4666fd2110dff2341f7ab. Full contribution review, corrective delta review and the final two-string upstream delta are recorded in the weekly comment.No fresh full Swarm cutover, browser, Pebble or real-SSH rehearsal was run. The local Docker daemon remained outside Swarm. Earlier evidence below is historical, not rerun. Existing audit, certificate-write, reload-failure and provider-health-query limitations remain. Specific remaining limitations:
Source-only: no production access, deployment, image publication, workflow dispatch or production-branch changes. The November 2 validation remains in its dated comment; the current contribution is 66 files, including a 9,624-line generated snapshot.
Source refresh — October 26, 2026
Synced to official
Dokploy/dokploy:canaryateaffeba4a60aa6a7e0318b95a3e9aa3bb90e9bcd, retaining this PR'scanarybase per CONTRIBUTING.md. Latest stable is v0.30.10; its non-version fixes are already on canary. The stable release commit is not a literal ancestor because upstream cherry-picks releases onto main. This contribution keeps canary's package version.The refresh preserves upstream file-path and organization protections, telemetry cleanup, certificate-path validation, and Traefik version/recovery handling. Caddy's migration is now
0199_caddy_provider, after upstream 0197/0198; those upstream migrations and snapshots are unchanged.Compatibility fixes serialize proxy recreates and switching, reject Traefik settings during a switch or on Caddy, validate uploaded certificate/key pairs before persistence on Caddy, retain certificate files until Caddy accepts their removal, prevent a retired Traefik from restarting beside Caddy, use separate dry-run candidate files, and refuse server setup while the provider is Caddy. Regression coverage includes domain re-enabling, tenant-scoped file access, certificate failures and proxy recovery.
Current contribution: 61 files, including 9,344 generated snapshot lines, 2,891 added test lines, and 3,057 added non-test/non-snapshot lines. No instance manifests, deployment workflows or production release metadata are added to this contribution.
Local validation on Node 24.22.1, pnpm 10.22.0, without GitHub Actions dispatch:
__test__/deploy/application.real.test.ts: 1,644 passed, four skipped, including real Caddy-container requests. Four workers avoided import-timeout flakes seen with heavier parallel build/test load. Local Docker's Swarm configuration was not changed.Remaining limits for review/testing:
traefikFiles:writepermits custom proxy configuration with the Caddy container's network/filesystem reach, including its local admin endpoint and mounted certificate storage. Restricting editable paths is not a sandbox for custom Caddy configuration.How it works
webServerProvider(traefikorcaddy, defaulttraefik) on the web server settings and on each remote server. UnderIS_CLOUDit is alwaystraefik.renderCaddyfileis a pure function from a server's routes and uploaded certificates to one Caddyfile: domains, path prefixes, strip and add prefix, redirects, basic auth, preview deployments and compose domains. Every value from the database is quoted, escaped or matched against a strict pattern. A route that cannot be written safely is rendered as a 503 in its place.caddy reload. Caddy validates before it swaps, so a configuration it refuses leaves the previous one serving, and whoever made the change sees Caddy's own message. The change itself stays saved, except a new basic-auth user, which is deleted again so that no route is listed as protected while it still answers without a password.acme.json.caddy:2.11.4, no plugins and no Docker socket. An admin's own configuration goes in/etc/dokploy/caddy/global/*.caddyandsites/*.caddy, edited in the existing file browser. A file Caddy rejects is put back as it was.What it does not do
^, as the presets are, the result is the same; the dry run lists any that are not.How to read it
The six original feature commits below are retained, followed by the canary-sync merge. Their individual validation and sizes refer to the original submission. The refreshed head has the separate validation above; see the current sync section for migration ordering.
Commit 5 can be dropped if you would rather not carry it: the dry run would then show one fixed warning to acknowledge instead of listing what was added by hand. I kept it because an IP allow-list that silently stops applying after a switch is how this feature could hurt someone.
If you would rather take this as three PRs (provider, switch, file browser), as offered in #1246, say so and I will split it.
Original implementation validation (October 2, before this refresh)
pnpm typecheckand Biome pass, and so doespnpm test, apart from four existing tests that need Docker in Swarm mode and do not run on my machine.caddyfile.real.test.tsloads the rendered file into the real image and sends requests through it; skipped without Docker, which the CI test job has.cutover.test.tsruns both switch scripts, with their failure paths, against a stand-in for Docker. The Caddy tests also pass on Linux: in anode:24.4.0-slimcontainer, and, as backported to my fork, on a GitHub-hosted Ubuntu runner with real Caddy.docker container prunehas removed the stopped Traefik container.dash. A successful switch leaves the proxy's ports unanswered for about 0.3 s. A broken configuration, a SIGTERM midway, and a Traefik that will not start each end with the previous proxy serving.shon the other end.Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
Addresses #1246. Supersedes the closed #4534.
Screenshots (if applicable)
The dry run before a switch: something that blocks it, something to accept, a warning, and the Caddyfile Caddy would start with.
The way back, in progress.
A save Caddy rejected in the file browser. The file is back as it was.
The menu on a Caddy server while its last sync has failed.