Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
if parsed.Source != "" {
toBind := bind

if parsed.Type == string(mount.TypeBind) {
if parsed.Type == mount.TypeBind {
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
if absHostPart, err := filepath.Abs(hostPart); err == nil {
Expand Down
22 changes: 9 additions & 13 deletions cli/compose/convert/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func Volumes(serviceVolumes []composetypes.ServiceVolumeConfig, stackVolumes vol

func createMountFromVolume(volume composetypes.ServiceVolumeConfig) mount.Mount {
return mount.Mount{
Type: mount.Type(volume.Type),
Type: volume.Type,
Target: volume.Target,
ReadOnly: volume.ReadOnly,
Source: volume.Source,
Consistency: mount.Consistency(volume.Consistency),
Consistency: volume.Consistency,
}
}

Expand Down Expand Up @@ -235,23 +235,19 @@ func handleClusterToMount(
return result, nil
}

func convertVolumeToMount(
volume composetypes.ServiceVolumeConfig,
stackVolumes volumes,
namespace Namespace,
) (mount.Mount, error) {
func convertVolumeToMount(volume composetypes.ServiceVolumeConfig, stackVolumes volumes, namespace Namespace) (mount.Mount, error) {
switch volume.Type {
case "volume", "":
case mount.TypeVolume, "":
return handleVolumeToMount(volume, stackVolumes, namespace)
case "image":
case mount.TypeImage:
return handleImageToMount(volume)
case "bind":
case mount.TypeBind:
return handleBindToMount(volume)
case "tmpfs":
case mount.TypeTmpfs:
return handleTmpfsToMount(volume)
case "npipe":
case mount.TypeNamedPipe:
return handleNpipeToMount(volume)
case "cluster":
case mount.TypeCluster:
return handleClusterToMount(volume, stackVolumes, namespace)
}
return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs, npipe, or cluster")
Expand Down
22 changes: 12 additions & 10 deletions internal/volumespec/types.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package volumespec

import "github.com/moby/moby/api/types/mount"

// VolumeConfig are references to a volume used by a service
type VolumeConfig struct {
Type string `yaml:",omitempty" json:"type,omitempty"`
Source string `yaml:",omitempty" json:"source,omitempty"`
Target string `yaml:",omitempty" json:"target,omitempty"`
ReadOnly bool `mapstructure:"read_only" yaml:"read_only,omitempty" json:"read_only,omitempty"`
Consistency string `yaml:",omitempty" json:"consistency,omitempty"`
Bind *BindOpts `yaml:",omitempty" json:"bind,omitempty"`
Volume *VolumeOpts `yaml:",omitempty" json:"volume,omitempty"`
Image *ImageOpts `yaml:",omitempty" json:"image,omitempty"`
Tmpfs *TmpFsOpts `yaml:",omitempty" json:"tmpfs,omitempty"`
Cluster *ClusterOpts `yaml:",omitempty" json:"cluster,omitempty"`
Type mount.Type `yaml:",omitempty" json:"type,omitempty"`
Source string `yaml:",omitempty" json:"source,omitempty"`
Target string `yaml:",omitempty" json:"target,omitempty"`
ReadOnly bool `mapstructure:"read_only" yaml:"read_only,omitempty" json:"read_only,omitempty"`
Consistency mount.Consistency `yaml:",omitempty" json:"consistency,omitempty"`
Bind *BindOpts `yaml:",omitempty" json:"bind,omitempty"`
Volume *VolumeOpts `yaml:",omitempty" json:"volume,omitempty"`
Image *ImageOpts `yaml:",omitempty" json:"image,omitempty"`
Tmpfs *TmpFsOpts `yaml:",omitempty" json:"tmpfs,omitempty"`
Cluster *ClusterOpts `yaml:",omitempty" json:"cluster,omitempty"`
}

// BindOpts are options for a service volume of type bind
Expand Down
8 changes: 4 additions & 4 deletions internal/volumespec/volumespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Parse(spec string) (VolumeConfig, error) {
return volume, errors.New("invalid empty volume spec")
case 1, 2:
volume.Target = spec
volume.Type = string(mount.TypeVolume)
volume.Type = mount.TypeVolume
return volume, nil
}

Expand Down Expand Up @@ -97,11 +97,11 @@ func populateType(volume *VolumeConfig) {
switch {
// Anonymous volume
case volume.Source == "":
volume.Type = string(mount.TypeVolume)
volume.Type = mount.TypeVolume
case isFilePath(volume.Source):
volume.Type = string(mount.TypeBind)
volume.Type = mount.TypeBind
default:
volume.Type = string(mount.TypeVolume)
volume.Type = mount.TypeVolume
}
}

Expand Down
Loading