diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 680a84a8b56c..0e46ad51f42f 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -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 { diff --git a/cli/compose/convert/volume.go b/cli/compose/convert/volume.go index 8eaa934cc097..c810fd1da94e 100644 --- a/cli/compose/convert/volume.go +++ b/cli/compose/convert/volume.go @@ -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, } } @@ -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") diff --git a/internal/volumespec/types.go b/internal/volumespec/types.go index 7eb9a5006ef0..89168ea0217f 100644 --- a/internal/volumespec/types.go +++ b/internal/volumespec/types.go @@ -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 diff --git a/internal/volumespec/volumespec.go b/internal/volumespec/volumespec.go index 8f497714c83e..bba23e843d9b 100644 --- a/internal/volumespec/volumespec.go +++ b/internal/volumespec/volumespec.go @@ -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 } @@ -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 } }