Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.2k
Handle relative source mounts#3469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,7 @@ import ( | ||
| "encoding/csv" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| @@ -92,6 +93,11 @@ func (m *MountOpt) Set(value string) error { | ||
| mount.Type = mounttypes.Type(strings.ToLower(value)) | ||
| case "source", "src": | ||
| mount.Source = value | ||
| if strings.HasPrefix(value, "."+string(filepath.Separator)) || value == "." { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess as a follow-up, we should consider;
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the second point, Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry I should've been clearer; so I was thinking of the "non-relative path" case, so in a case where we don't hit this (but definitely for a follow-up) | ||
| if abs, err := filepath.Abs(value); err == nil { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to return the error if this fails? (Not entirely sure if needed; it seems like the only case this would fail is if it's failing to resolve | ||
| mount.Source = abs | ||
| } | ||
| } | ||
| case "target", "dst", "destination": | ||
| mount.Target = value | ||
| case "readonly", "ro": | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is a bit hairy (not your fault), and could use some cleaning up at least (we're parsing the
bindinto a structured type, but effectively only to do some mild "validation" (however, we're throwing away any error caused byloader.ParseVolume().One thing we can do already (if I see it correctly), is to use the
parsed.Typefield to only run this code if it's a bind-mount.Ideally (but that bit might be ok to be done separate), we should
loader.ParseVolume()already do the resolving (I guess that won't work for the compose case, as it would have to resolve relative to the compose-file)parsed.Source, and;types.ServiceVolumeConfig(which is returned byloader.ParseVolume()) to have a.String()(or a separate utility for that), which returnsparsedin its canonicalstringrepresentation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the check for the
parsed.Type, I didn't really want to touch the loader code since it touches the compose/swarm things and figured it would surely break something else. I do agree we could have something somewhere that can return a canonical string representation, we should also try and think about how we can make volume and mounts options parsing be in the same place.