fix(compose)!: honor Docker's project-directory anchoring model#54
Open
jahirvidrio wants to merge 2 commits into
Open
fix(compose)!: honor Docker's project-directory anchoring model#54jahirvidrio wants to merge 2 commits into
jahirvidrio wants to merge 2 commits into
Conversation
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.
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.
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 buildresolvedbuild.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..envauto-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-ffiles in play.Docker Compose defines a canonical project directory: the path given via
--project-directory, else the directory of the first non-stdin-ffile, 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
--project-directory <path>tomocker compose, implementing Docker Compose's precedence rule: explicit flag > directory of the first real-ffile ("-"stdin entries skipped) > process CWD. When no-fis given, default compose file discovery runs insideprojectDirrather than the process CWD..envdiscovery and the default project name now anchor to the resolved project directory. Previously.envwas sought relative to each compose file's parent; now a single lookup runs againstprojectDir.build.contextand thedockerfilepath 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:)andComposeOrchestrator.init(...)each take a requiredprojectDir: URLparameter.ImageManager.resolveContextPathis promoted topublicto support cross-module path resolution from the CLI layer.Breaking change
.envdiscovery and the default project name now derive from the resolved project directory rather than each compose file's parent.build.contextand thedockerfilepath now resolve against the project directory instead of the process CWD. For the common case (runningmocker composefrom the project root), behavior is unchanged. Callers that invokemocker composefrom a directory other than the project root should add--project-directory <path>and verify resolved paths withmocker compose config. MockerKit consumers:ComposeFile.load(from:projectDir:)andComposeOrchestrator.init(...)each require a newprojectDir: URLargument; callers that relied on implicit CWD anchoring must supply the directory explicitly.