Skip to content

fix(compose)!: honor Docker's project-directory anchoring model#54

Open
jahirvidrio wants to merge 2 commits into
us:mainfrom
jahirvidrio:fix/compose-project-directory-foundation
Open

fix(compose)!: honor Docker's project-directory anchoring model#54
jahirvidrio wants to merge 2 commits into
us:mainfrom
jahirvidrio:fix/compose-project-directory-foundation

Conversation

@jahirvidrio

Copy link
Copy Markdown
Contributor

This PR was originally meant to close #49, but I hit a bunch of related project-directory anchoring issues along the way and got a bit (okay, a lot) sidetracked. I'm glad another contributor already handled #49 upstream while I was down that rabbit hole.

This is the first of a few Docker-parity fixes I'll be submitting. I'll do my best to stay on track for the next ones!

What problem does this solve?

mocker compose -f /projects/app/compose.yaml build resolved build.context: . against the caller's CWD rather than the project root. From outside /projects/app, the build received the wrong source tree with no error. Silent wrong output. .env auto-discovery had the same flaw: it ran relative to each compose file's parent directory, so the active environment varied with the number and location of -f files in play.

Docker Compose defines a canonical project directory: the path given via --project-directory, else the directory of the first non-stdin -f file, else the process CWD. Every project-relative path (build.context, dockerfile, .env, the project name) must anchor there. Without this anchor, mocker's path resolution diverges from Docker Compose's behavior whenever the caller's CWD differs from the project root, making builds non-reproducible across environments.

What changed

  • Added --project-directory <path> to mocker compose, implementing Docker Compose's precedence rule: explicit flag > directory of the first real -f file ("-" stdin entries skipped) > process CWD. When no -f is given, default compose file discovery runs inside projectDir rather than the process CWD.
  • .env discovery and the default project name now anchor to the resolved project directory. Previously .env was sought relative to each compose file's parent; now a single lookup runs against projectDir.
  • build.context and the dockerfile path derived from it now resolve against the project directory instead of the process CWD. Builds invoked from outside the project root now receive consistent absolute paths regardless of caller CWD.
  • ComposeFile.load(from:projectDir:) and ComposeOrchestrator.init(...) each take a required projectDir: URL parameter. ImageManager.resolveContextPath is promoted to public to support cross-module path resolution from the CLI layer.

Breaking change

.env discovery and the default project name now derive from the resolved project directory rather than each compose file's parent. build.context and the dockerfile path now resolve against the project directory instead of the process CWD. For the common case (running mocker compose from the project root), behavior is unchanged. Callers that invoke mocker compose from a directory other than the project root should add --project-directory <path> and verify resolved paths with mocker compose config. MockerKit consumers: ComposeFile.load(from:projectDir:) and ComposeOrchestrator.init(...) each require a new projectDir: URL argument; callers that relied on implicit CWD anchoring must supply the directory explicitly.

BREAKING CHANGE: 'ComposeFile.load(...)' now requires a 'projectDir: URL'
parameter. '.env' discovery and the default compose project name anchor
to the resolved project directory (explicit '--project-directory', else
the first '-f' file's directory, else the current working directory)
instead of each compose file's own directory.
BREAKING CHANGE: 'compose build', 'compose up', 'compose restart', and
'compose create' now resolve 'build.context' and the derived Dockerfile
path against the resolved project directory (explicit '--project-directory',
else the first '-f' file's directory, else the current working directory)
instead of the process's current working directory. Builds run from outside
the project directory now see different absolute context/Dockerfile paths.
MockerKit consumers: 'ComposeOrchestrator.init(...)' now requires a
'projectDir: URL' parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mocker compose up skips bind mounts with relative paths

1 participant