feat: support Docker image source for preview deployments#3782
feat: support Docker image source for preview deployments#3782kopandante wants to merge 1 commit intoDokploy:canaryfrom
Conversation
Adds the ability to deploy preview environments from pre-built Docker images, enabling external CI/CD pipelines (e.g., GitHub Actions) to build images and trigger preview deployments via API. Schema: - Add `dockerImage` column to `preview_deployments` table - Add `apiCreatePreviewDeploymentFromImage` Zod schema Deploy logic: - `deployPreviewApplication`: add `sourceType === "docker"` branch alongside existing GitHub branch. Uses `buildRemoteDocker()` (docker pull) + `mechanizeDockerContainer()`. Also includes buildServerId fix. - `rebuildPreviewApplication`: same docker branch + buildServerId fix Service: - New `createPreviewDeploymentFromImage()` function that creates a preview deployment from a Docker image without requiring GitHub PR context. Optionally posts a PR comment if GitHub provider and PR number are provided. Router: - New `deployFromImage` tRPC procedure that validates permissions, creates the preview deployment, and queues the deployment job. Returns `previewDeploymentId` and `previewDomain`. Workflow: GitHub Actions builds image -> pushes to GHCR -> calls Dokploy API `previewDeployment.deployFromImage` -> Dokploy pulls image and creates preview container with domain Closes Dokploy#2386
Additional Comments (6)
when
wrap this in a check for
all GitHub comment operations need to check if
|
|
Superseded by #3784 |
Problem
Preview deployments currently only work with
sourceType: "github". Applications using Docker images (sourceType: "docker") have their preview builds silently skipped. Additionally, there is no way for external CI/CD pipelines (GitHub Actions, GitLab CI, etc.) to trigger preview deployments with pre-built Docker images.This means users who want to offload builds to CI/CD runners -- or who use Docker image registries as their deployment source -- cannot use preview deployments at all.
Related issues: #2386, #1365
Solution
1. Docker source type support in preview deploy/rebuild
deployPreviewApplication()now handlessourceType === "docker"alongside the existing"github"branch:Same pattern added to
rebuildPreviewApplication().Both functions also include the
buildServerIdfix from #3781.2. Per-preview Docker image override
New
dockerImagecolumn onpreview_deploymentstable allows each preview to use a different Docker image tag (e.g.,ghcr.io/org/app:pr-42), independent of the parent application'sdockerImage.3. New API endpoint:
previewDeployment.deployFromImageNew tRPC procedure that enables external CI/CD to trigger preview deployments:
The function:
Example GitHub Actions workflow
Changes
packages/server/src/db/schema/preview-deployments.tsdockerImagecolumn, newapiCreatePreviewDeploymentFromImageZod schemapackages/server/src/services/application.tsdeployPreviewApplicationandrebuildPreviewApplication, include buildServerId fixpackages/server/src/services/preview-deployment.tscreatePreviewDeploymentFromImage()functionapps/dokploy/server/api/routers/preview-deployment.tsdeployFromImagetRPC procedureBehavior
deployFromImageAPITesting
Tested on a Dokploy v0.27.0 instance with Docker source type applications and GitHub Actions triggered previews.
Greptile Summary
Added Docker image source support for preview deployments, enabling external CI/CD pipelines to trigger previews with pre-built images. Also includes
buildServerIdfix for remote builds.Critical Issue Found:
deployPreviewApplication()andrebuildPreviewApplication()unconditionally call GitHub comment APIs (issueCommentExists(),updateIssueComment()), which throw errors whengithubIdis emptyChanges:
dockerImagecolumn topreview_deploymentstable for per-preview Docker image overridesdeployPreviewApplication()andrebuildPreviewApplication()to handlesourceType === "docker"viabuildRemoteDocker()createPreviewDeploymentFromImage()service function with optional GitHub comment supportdeployFromImagetRPC endpoint for API-triggered preview deploymentsbuildServerIdfix from fix: use buildServerId for preview deployments #3781Missing:
dockerImagecolumn (need to runpnpm migration:generate)deployPreviewApplication()andrebuildPreviewApplication()must be wrapped inif (application?.githubId)checks to prevent crashes for Docker-only applicationsConfidence Score: 1/5
findGithubById("")to throw NOT_FOUND errors and crash the deployment. This affects bothdeployPreviewApplication()andrebuildPreviewApplication()functions in 6+ locations.packages/server/src/services/application.ts- all GitHub comment operations need conditional checks before the PR can be safely mergedLast reviewed commit: d37ab6c
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!