fix(preview): re-clone source on rebuild so PR pushes propagate#4319
Open
budivoogt wants to merge 1 commit intoDokploy:canaryfrom
Open
fix(preview): re-clone source on rebuild so PR pushes propagate#4319budivoogt wants to merge 1 commit intoDokploy:canaryfrom
budivoogt wants to merge 1 commit intoDokploy:canaryfrom
Conversation
`rebuildPreviewApplication` (the path that runs for every `synchronize` webhook on an existing preview deployment) skipped the git clone step that `deployPreviewApplication` runs on first deploy. As a result, every push to a PR after the first triggered a `docker build` against the original snapshot taken at PR open. BuildKit content-hashed the unchanged source, cache-hit every layer including `COPY . .`, and the deploy finished in seconds while still serving the original commit. The GitHub Deployments API was posted `success`, but the running container was never replaced. Symptom (verified on a real preview): - PR opened at SHA A → real ~4 min build, image hash A1, container OK. - PR pushed SHA B, C, D → three `synchronize` events, three Dokploy "deploys" each finishing in 9-10 s, GitHub Deployments reports `success`, but the container kept image hash A1. Working tree on disk and BuildKit cache both stuck at SHA A. - After a manual `git fetch + git reset --hard origin/<branch>` on the server's `/etc/dokploy/applications/<preview>/code/`, the next webhook-triggered build cache-missed `COPY . .` and produced a real rebuild — confirming the only thing missing was the fetch. Fix: mirror `deployPreviewApplication`'s pre-build clone in `rebuildPreviewApplication`. `cloneGithubRepository` already does `rm -rf code && git clone --depth 1 --branch <branch>` with a fresh installation token, so each rebuild gets the latest tip of the preview branch. Scope: github source type only, matching the existing scope of `deployPreviewApplication`'s clone. GitLab / Gitea / Bitbucket preview rebuilds remain on the previous behavior; extending parity to those providers belongs in a follow-up.
budivoogt
added a commit
to budivoogt/dokploy
that referenced
this pull request
Apr 28, 2026
Two additions to CTD-FORK.md: - New row in the "Active fork customizations" table for the preview-rebuild fetch fix, with link to upstream PR Dokploy#4319 and a note to remove this row when upstream merges. - A "Fresh-install / disaster-recovery" section flagging that Dokploy's official installer pulls `dokploy/dokploy:latest` from Docker Hub (unpatched upstream), so any host rebuild needs to be followed immediately by `bin/deploy-ctd.sh <tag>` to swap to the patched image. Same applies to upstream version upgrades — rebase the CTD branch first, don't update directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rebuildPreviewApplicationskips the clone step thatdeployPreviewApplicationruns on first deploy. As a result, every PRsynchronizewebhook (i.e., every push to an existing preview branch after the first) only re-runsdocker buildagainst the original snapshot taken at PR open.BuildKit content-hashes the unchanged source, cache-hits every layer including
COPY . ., and the deploy finishes in seconds while still serving the original commit. The GitHub Deployments API gets posted `success`, but the running container is never replaced.Reproduction
Verified empirically on a self-hosted v0.28.8 install:
A— real ~4 min build, image hashA1, container running new code. ✅B, thenC, thenDto the same PR. Threesynchronizeevents, three Dokploy "deploys" each finishing in 9–10 s, GitHub Deployments reports each as `success`. The Docker image and running container keep hash `A1`. Working tree on disk and BuildKit cache both stuck at SHA `A`.The only thing missing for the rebuild path was the fetch.
Fix
Mirror
deployPreviewApplication's pre-build clone inrebuildPreviewApplication.cloneGithubRepositoryalready does `rm -rf code && git clone --depth 1 --branch ` with a fresh installation token issued via the GitHub App — so each rebuild gets the latest tip of the preview branch.The diff is symmetric with the existing block at line ~427 inside
deployPreviewApplication.Scope
GitHub source type only, matching the existing scope of
deployPreviewApplication's clone. GitLab / Gitea / Bitbucket preview rebuilds remain on the previous behavior; extending parity to those providers belongs in a follow-up. Happy to do that in this PR if maintainers prefer — just let me know.Test plan
Related
Verified on
v0.28.8; same bug is inv0.29.2(latest as of this PR — same line, same comment). No prior issue or PR found in tracker for this specific behavior. Closest existing reports are about preview deployment lifecycle (#3248 Destroy & Re-Deploy button, #4203 orphan Swarm services) but not the stale-source-on-rebuild path.Greptile Summary
This PR fixes a real bug where
rebuildPreviewApplicationskipped the repository clone step, causing every PR push after the first to rebuild against the original source snapshot. The fix mirrorsdeployPreviewApplication's clone block exactly, scoped tosourceType === "github"as acknowledged in the description.Confidence Score: 5/5
This PR is safe to merge — it's a targeted, well-scoped fix with no regressions.
The change is a minimal, symmetric addition that directly mirrors the already-working pattern in
deployPreviewApplication. Error handling flows through the existing catch block, the GitHub App token is freshly issued on each call, and non-GitHub source types are explicitly left unchanged (as stated in the description). No new execution paths, no security concerns.No files require special attention.
Reviews (1): Last reviewed commit: "fix(preview): re-clone source on rebuild..." | Re-trigger Greptile