Repository navigation
Rework mount command string generation - #537
Conversation
- Move command generation logic to separate function; - Add check if `src` argument is undefined;
Samruddhi Khandale (samruddhikhandale)
left a comment
There was a problem hiding this comment.
Thanks, can you help add a unit test to validate this fix?
…lyakov/add_proper_handling_for_src_arg_in_mount_command
Added test in 7fc4270 |
joshspicer
left a comment
There was a problem hiding this comment.
Looks good to me - thanks Alexander Smolyakov (@alexander-smolyakov) !
|
Here's the spec article on anonymous volumes https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag. Not sure why this is particularly useful, I guess so as to not clutter up a container's filesystem between starts/stops? |
Christof Marti (chrmarti)
left a comment
There was a problem hiding this comment.
Thanks for looking into this!
- Could you make
sourceoptional in the interface: - Handle the two references to source for Docker Compose:
cli/src/spec-node/dockerCompose.ts
Line 546 in 9064c70
We will also need to update the schemas to make source optional: https://github.com/devcontainers/spec/tree/main/schemas
- Make `source` property optional in `Mount` interface; - Move logic for converting mount to volume to separate function; - Add test to cover docker compose case;
Samruddhi Khandale (samruddhikhandale)
left a comment
There was a problem hiding this comment.
Looks great, thank you!
Christof Marti (chrmarti)
left a comment
There was a problem hiding this comment.
Looks good. A few polishing suggestions. Thanks.
…lyakov/add_proper_handling_for_src_arg_in_mount_command
Description:
This PR addresses the issue when the Docker volume is named as
undefinedif thesrcargument is not specified in themountcommand.The issue related to the following code:
cli/src/spec-node/singleContainer.ts
Lines 359 to 364 in 7de4011
When the
mountcommand string is generated, there is no check for thesrcargument. This results in thesrcattribute being set toundefinedwhen cast to a string.To fix this behavior, we need to apply null-check for the
srcargument and don't pass it to Docker. When thesrcarg is not passed, Docker generates a random name for the volume.Repro sample:
{ "image": "mcr.microsoft.com/devcontainers/base:latest", "mounts": [ { "target": "/home/vscode/.vscode-server", "type": "volume", } ] }Examples:
Without fix:
node ➜ /workspaces/devcontainers-cli (main) $ docker inspect -f '{{json .Mounts }}' a85f6e52d478[ { "Type": "bind", "Source": "/workspaces/devcontainers-cli", "Destination": "/workspaces/devcontainers-cli", "Mode": "", "RW": true, "Propagation": "rprivate" }, { "Type": "volume", "Name": "undefined", "Source": "/var/lib/docker/volumes/undefined/_data", "Destination": "/home/vscode/.vscode-server", "Driver": "local", "Mode": "z", "RW": true, "Propagation": "" } ]With fix:
node ➜ /workspaces/devcontainers-cli (users/alexander-smolyakov/add_proper_handling_for_src_arg_in_mount_command) $ docker inspect -f '{{json .Mounts }}' 2e77ff5392dc[ { "Type": "bind", "Source": "/workspaces/devcontainers-cli", "Destination": "/workspaces/devcontainers-cli", "Mode": "", "RW": true, "Propagation": "rprivate" }, { "Type": "volume", "Name": "628f29020e5d6a9514614ce0ad90411d2400161b67e07bb8744f39a83a397922", "Source": "/var/lib/docker/volumes/628f29020e5d6a9514614ce0ad90411d2400161b67e07bb8744f39a83a397922/_data", "Destination": "/home/vscode/.vscode-server", "Driver": "local", "Mode": "z", "RW": true, "Propagation": "" } ]Attached related issue:
Changelog:
mountcommand generation logic to a separate function;srcargument is undefined;