Fix invalid path error when using OCI artifacts on Windows #13574
+92
−2
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.
Resolves #13572
And AI disclaimer - Claude performed the troubleshooting and fix in this PR.
I have built the Compose binary locally and validated the fix does work on my Windows machine.
Problem
When using Docker Compose with an OCI artifact on Windows (e.g.,
docker compose -f oci://dockersamples/welcome-to-docker up), the following error occurred:This error was introduced between v5.0.0 and v5.0.1, specifically by commit 6c04392 which fixed error handling in
setEnvWithDotEnv. The bug existed in v5.0.0 but was silently ignored due to improper errorhandling.
Root Cause
The issue occurred in the
setEnvWithDotEnvfunction incmd/compose/compose.go:setEnvWithDotEnvis called with an OCI artifact path, it creates ProjectOptions without registering any remote loadersGetWorkingDir()method doesn't recognize the path as a remote resourcefilepath.Abs()on itfilepath.Abs("oci://dockersamples/...")produces an invalid path likeC:\Users\username\oci:\dockersamples.envfiles, it appends to this malformed path, resulting in:C:\Users\username\oci:\dockersamples\.envCode Flow
In compose-go's
cli/options.go, theGetWorkingDir()method:Without remote loaders registered, OCI paths fall through to
filepath.Abs(), causing the issue.Solution
Modified
setEnvWithDotEnvto detect remote config paths and skip environment loading for them:This approach:
oci://, Git: URLs with://)Testing
cmd/compose/compose_oci_test.gofor OCI artifacts, Git remotes, and local pathsFiles Changed
cmd/compose/compose.go: ModifiedsetEnvWithDotEnvfunctioncmd/compose/compose_oci_test.go: Added tests for the fix"