fix(up): forward single-file bind mounts to container run#94
Open
csaller wants to merge 3 commits intoMcrich23:mainfrom
Open
fix(up): forward single-file bind mounts to container run#94csaller wants to merge 3 commits intoMcrich23:mainfrom
container run#94csaller wants to merge 3 commits intoMcrich23:mainfrom
Conversation
Apple `container` (0.12.3+) accepts `--volume host/file:container/file[:mode]` for single-file bind mounts, but `configVolume` was branching on `isDirectory` and silently dropping the mount (with only a warning) when the host side resolved to a file. Common compose idioms like `./config.yaml:/app/config.yaml:ro` or `./init.sh:/docker-entrypoint-initdb.d/init.sh` therefore never reached the container. Forward the bind mount for both file and directory sources, and preserve the optional mode component (e.g. `:ro`) when rebuilding the `--volume` argument — previously the mode was stripped even for directory mounts. Closes Mcrich23#93
Owner
|
Hi @csaller. Thank you for your PR. I plan to look at it early next week when I have some time (if I don't send something, please ping me!) For the test, go ahead and add it. Using an |
Extract configVolume's bind-mount logic into a public free function composeVolumeToRunArgs so it can be tested without spinning up a real container runtime. Add 7 static tests covering: single-file mount with :ro mode (the bug case), single-file mount without mode, directory mount, directory mount with mode, relative path resolution, missing host path auto-creation, and invalid format.
Author
|
Hi @Mcrich23, thanks! I just added the unit test and they are passing locally, also a test build worked exactly as expected with no regressions detected. Lmk if you need everything else from me. Other than that, have a great weekend! |
The function only needs to be reachable from the test target via @testable import ContainerComposeCore — there's no reason to expose it as part of the public API surface.
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.
Closes #93.
The bug
configVolumeinComposeUp.swifttreated file vs. directory host sources differently: if the host side of a bind mount resolved to a file, the mount was skipped and only a"The 'container' tool does not support direct file mounts"warning was printed. In practice that warning is often masked by the image-fetch/progress output, so users see a container that silently starts withvolumes:entries missing.But Apple
container(0.12.3+) does support file-to-file bind mounts. This works today, straight from the CLI:So the gate in
container-composeis no longer (and, based on field use, seems to never have been) correct. Common compose idioms like./config.yaml:/app/config.yaml:roor./init.sh:/docker-entrypoint-initdb.d/init.shhave to be worked around by moving the file into a directory that's already mounted.The fix
container --volume.:ro, etc.) when rebuilding the--volumeargument. Previously the mode was stripped even for directory mounts, so:rohad no effect there either.Diff is small and localized to the bind-mount branch of
configVolume. The named-volume branch is untouched.Verification
Minimal reproducer with one directory mount and one file mount:
Before (0.11.0):
container inspectshows only the directory mount; file mount is absent fromconfiguration.mounts;cat /app/hello.txt→No such file or directory.After this patch:
[ { "source": ".../data/", "destination": "/app/data", "options": [], "type": {"virtiofs": {}} }, { "source": ".../hello.txt", "destination": "/app/hello.txt", "options": ["ro"], "type": {"virtiofs": {}} } ]Container logs:
The
:roon the file mount is now propagated (options: ["ro"]), matching compose semantics.Test status
Ran
swift test. The only failures are in the pre-existing dynamic suite ("What goes up must come down - two containers", "Test WordPress with MySQL compose file", "Test compose with complex dependency chain") — all of those use compose YAMLs with only named volumes (wordpress_data,db_data) and hit the known named-volume bootstrap issue tracked in #52. They reproduce onmainwithout this patch; no code path touched by this change is exercised by them.I didn't add a unit test because
configVolumeis a private instance method that pulls from severalComposeUpfields (cwd,fileManager,environmentVariables,projectName). Happy to extract a pure helper and add a static test in a follow-up if you'd prefer that shape.Test plan
docker-compose.ymlwith a single-file bind mount (e.g../config.yaml:/app/config.yaml:ro) brings up a container that can read the file.docker-compose.ymlwith a directory bind mount continues to work.container inspect <name>shows both mounts inconfiguration.mounts, withoptions: ["ro"]preserved for:roentries.