Skip to content

Commit

Permalink
compose: Support "bind volumes" specified via DriverOpts
Browse files Browse the repository at this point in the history
This adds support for manual bind mounts as named volumes specified as described
in docker/compose#2957.
  • Loading branch information
cg505 committed Jul 29, 2020
1 parent ea6c54e commit 1fad5a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ func (cmd *up) makeSyncthingClient(dcCfg composeTypes.Config) syncthing.Client {
allVolumes = append(allVolumes, volume)
}
}

for _, namedVol := range dcCfg.Volumes {
source, ok := dockercompose.ParseNamedBindVolume(namedVol)

if ok {
allVolumes = append(allVolumes, syncthing.BindVolume{LocalPath: source})
}
}

return syncthing.NewClient(allVolumes)
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/dockercompose/dockercompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,22 @@ func load(det types.ConfigDetails, opts ...func(opts *loader.Options)) (cfg *typ
cfg, err = loader.Load(det, opts...)
return
}

func ParseNamedBindVolume(vol types.VolumeConfig) (source string, ok bool) {
if vol.Driver != "" && vol.Driver != "local" {
return "", false
}

// Look for -o bind.
mountOpts, ok := vol.DriverOpts["o"]
if !ok {
mountOpts = vol.DriverOpts["options"]
}
for _, opt := range strings.Split(mountOpts, ",") {
if opt == "bind" {
return vol.DriverOpts["device"], true
}
}

return "", false
}

0 comments on commit 1fad5a1

Please sign in to comment.