Fix invalid path error when using OCI artifacts on Windows#13574
Fix invalid path error when using OCI artifacts on Windows#13574mikesir87 wants to merge 1 commit intodocker:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thank you for contributing! It appears your commit message is missing a DCO sign-off, We require all commit messages to have a There is no need to open a new pull request, but to fix this (and make CI pass), Unfortunately, it's not possible to do so through GitHub's web UI, so this needs You can find some instructions in the output of the DCO check (which can be found Steps to do so "roughly" come down to:
Sorry for the hassle (I wish GitHub would make this a bit easier to do), and let me know if you need help or more detailed instructions! |
When using OCI artifacts (e.g., `docker compose -f oci://dockersamples/welcome-to-docker up`) on Windows, users encountered the following error: CreateFile C:\Users\username\oci:\dockersamples\.env: The filename, directory name, or volume label syntax is incorrect. This issue 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 error handling. Root Cause: ----------- The setEnvWithDotEnv function creates ProjectOptions without registering remote loaders. Without remote loaders, the compose-go library doesn't recognize OCI paths as remote resources. It falls through to filepath.Abs() which treats the OCI reference as a relative path. On Windows, filepath.Abs("oci://dockersamples/...") produces an invalid path like: C:\Users\username\oci:\dockersamples Windows rejects this path because colons are only valid after drive letters. Solution: --------- Modified setEnvWithDotEnv to detect remote config paths and skip environment loading for them. Instead of hardcoding string checks, the fix uses the actual remote loaders' Accept() method to determine if a config path is remote. This is more maintainable and consistent with how the compose-go library identifies remote resources. The function now: - Accepts a dockerCli parameter to access remote loaders - Uses opts.remoteLoaders(dockerCli) to get loader instances - Checks if any loader accepts the config path using loader.Accept() - Skips .env loading for remote configs (happens later when loaders are initialized) - Allows normal processing for local compose files Testing: -------- - Added tests for OCI artifacts, Git remotes, and local paths - Verified fix works on Windows ARM64 - All existing tests pass Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Michael Irwin <mikesir87@gmail.com>
9696b02 to
6cbb80d
Compare
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"