fix(docker): default Dockerfile build context to code root (#5417) - #5444
fliptrigga13 wants to merge 1 commit into
Conversation
… Dockerfile directory (Dokploy#5417)
| buildPath ?? "", | ||
| dockerContextPath || ".", |
There was a problem hiding this comment.
Prepending buildPath also rebases every explicitly configured dockerContextPath, although existing values were resolved from the repository code root. For example, an application with buildPath: "services/api" and a previously working context of "shared" now builds from code/services/api/shared instead of code/shared. If that nested path does not exist, the cd guard aborts the deployment. Apply buildPath only when selecting the default context, without changing the base of persisted explicit paths.
| buildPath ?? "", | |
| dockerContextPath || ".", | |
| dockerContextPath ? "" : buildPath ?? "", | |
| dockerContextPath || ".", |
Knowledge Base Used: Build and Compose workflows
| @@ -0,0 +1,192 @@ | |||
| import path from "node:path"; | |||
| import { describe, expect, it } from "vitest"; | |||
|
|
|||
There was a problem hiding this comment.
This test recreates the three production path resolvers locally, so every assertion exercises the copies rather than the changed exports in directory.ts. The suite can remain green if production behavior regresses or drifts from these copies. Import the production helpers through the existing @dokploy/server test alias and mock only their environmental dependencies.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Fixes #5417
Problem
In Dockerfile-type applications, when the
Docker Context Pathfield was left empty, Dokploy fell back to:When a Dockerfile was placed in a subdirectory (e.g.
docker/api/Dockerfile) in monorepos or multi-service projects,defaultContextPathset the build context todocker/api/rather than the repository/application root (.), causing builds to fail whenever the Dockerfile attempted toCOPYshared files from the repository root (e.g.COPY shared/config.json /app/config.json). This contradicted the UI field's documented placeholder (default: .) and differed from Docker Compose (context: .).PR #5231 attempted to fix this, but in PR #5271 it was reverted because
customGitBuildPath(such as inapplication.real.test.tswherecustomGitBuildPath = "/deno") was not accounted for in the context path calculation.Solution
getApplicationBuildPath(application)inpackages/server/src/utils/filesystem/directory.tsto consistently resolve the build path across all source providers (github,gitlab,bitbucket,gitea,drop,git).getDockerContextPath:buildPathalongsidedockerContextPath..(the application code root orbuildPathsub-root) whendockerContextPathis empty or null, matching the UI placeholder and standard Docker Compose semantics.getDockerCommandinpackages/server/src/utils/builders/docker-file.tsto rely directly ongetDockerContextPath.apps/dokploy/__test__/deploy/docker-context-path.test.tsvalidating:dockerContextPathis null/empty with subdirectory Dockerfiles (docker/api/Dockerfile).dockerContextPathoverrides.buildPath/customGitBuildPathscoping.The PR should not merge until explicit Docker context paths retain backward-compatible resolution and the regression tests exercise the production implementation.
Summary
buildPath, which can break existing deployments.Reviews (1) · Last reviewed commit: "fix(docker): default Dockerfile build co..."