mirror of https://github.com/docker/cli.git
only check for containerpath
Signed-off-by: Venky Natham <vrnatham@amazon.com>
This commit is contained in:
parent
51dcc574d5
commit
f705c40714
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -434,19 +433,19 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
||||||
deviceMappings := []container.DeviceMapping{}
|
deviceMappings := []container.DeviceMapping{}
|
||||||
for _, device := range copts.devices.GetAll() {
|
for _, device := range copts.devices.GetAll() {
|
||||||
var (
|
var (
|
||||||
validated string
|
validated string
|
||||||
parsedDeviceMappings []container.DeviceMapping
|
deviceMapping container.DeviceMapping
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
validated, err = validateDevice(device, serverOS)
|
validated, err = validateDevice(device, serverOS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
parsedDeviceMappings, err = parseDevice(validated, serverOS)
|
deviceMapping, err = parseDevice(validated, serverOS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
deviceMappings = append(deviceMappings, parsedDeviceMappings...)
|
deviceMappings = append(deviceMappings, deviceMapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect all the environment variables for the container
|
// collect all the environment variables for the container
|
||||||
|
@ -895,21 +894,19 @@ func parseStorageOpts(storageOpts []string) (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseDevice parses a device mapping string to a container.DeviceMapping struct
|
// parseDevice parses a device mapping string to a container.DeviceMapping struct
|
||||||
func parseDevice(device, serverOS string) ([]container.DeviceMapping, error) {
|
func parseDevice(device, serverOS string) (container.DeviceMapping, error) {
|
||||||
var deviceMappings []container.DeviceMapping
|
|
||||||
switch serverOS {
|
switch serverOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
return parseLinuxDevice(device)
|
return parseLinuxDevice(device)
|
||||||
case "windows":
|
case "windows":
|
||||||
return parseWindowsDevice(device)
|
return parseWindowsDevice(device)
|
||||||
}
|
}
|
||||||
return append(deviceMappings, container.DeviceMapping{}), errors.Errorf("unknown server OS: %s", serverOS)
|
return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
|
// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
|
||||||
// knowing that the target is a Linux daemon
|
// knowing that the target is a Linux daemon
|
||||||
func parseLinuxDevice(device string) ([]container.DeviceMapping, error) {
|
func parseLinuxDevice(device string) (container.DeviceMapping, error) {
|
||||||
var deviceMappings []container.DeviceMapping
|
|
||||||
src := ""
|
src := ""
|
||||||
dst := ""
|
dst := ""
|
||||||
permissions := "rwm"
|
permissions := "rwm"
|
||||||
|
@ -929,44 +926,29 @@ func parseLinuxDevice(device string) ([]container.DeviceMapping, error) {
|
||||||
src = arr[0]
|
src = arr[0]
|
||||||
if strings.HasSuffix(src, "*") {
|
if strings.HasSuffix(src, "*") {
|
||||||
if dst != "" {
|
if dst != "" {
|
||||||
return deviceMappings, errors.Errorf("device with * suffix can't have dst: %s", device)
|
return container.DeviceMapping{}, errors.Errorf("device with * suffix can't have dst: %s", device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return deviceMappings, errors.Errorf("invalid device specification: %s", device)
|
return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(src, "*") {
|
if dst == "" {
|
||||||
devicePaths, _ := filepath.Glob(src)
|
dst = src
|
||||||
for _, devicePath := range devicePaths {
|
|
||||||
deviceMapping := container.DeviceMapping{
|
|
||||||
PathOnHost: devicePath,
|
|
||||||
PathInContainer: devicePath,
|
|
||||||
CgroupPermissions: permissions,
|
|
||||||
}
|
|
||||||
deviceMappings = append(deviceMappings, deviceMapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if dst == "" {
|
|
||||||
dst = src
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceMapping := container.DeviceMapping{
|
|
||||||
PathOnHost: src,
|
|
||||||
PathInContainer: dst,
|
|
||||||
CgroupPermissions: permissions,
|
|
||||||
}
|
|
||||||
deviceMappings = append(deviceMappings, deviceMapping)
|
|
||||||
}
|
}
|
||||||
return deviceMappings, nil
|
|
||||||
|
deviceMapping := container.DeviceMapping{
|
||||||
|
PathOnHost: src,
|
||||||
|
PathInContainer: dst,
|
||||||
|
CgroupPermissions: permissions,
|
||||||
|
}
|
||||||
|
return deviceMapping, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseWindowsDevice parses a device mapping string to a container.DeviceMapping struct
|
// parseWindowsDevice parses a device mapping string to a container.DeviceMapping struct
|
||||||
// knowing that the target is a Windows daemon
|
// knowing that the target is a Windows daemon
|
||||||
func parseWindowsDevice(device string) ([]container.DeviceMapping, error) {
|
func parseWindowsDevice(device string) (container.DeviceMapping, error) {
|
||||||
var deviceMappings []container.DeviceMapping
|
return container.DeviceMapping{PathOnHost: device}, nil
|
||||||
return append(deviceMappings, container.DeviceMapping{PathOnHost: device}), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateDeviceCgroupRule validates a device cgroup rule string format
|
// validateDeviceCgroupRule validates a device cgroup rule string format
|
||||||
|
|
Loading…
Reference in New Issue