소스 검색

Change flag to -o and --opt
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 년 전
부모
커밋
c9d7f858fd
5개의 변경된 파일38개의 추가작업 그리고 10개의 파일을 삭제
  1. 2 2
      runconfig/hostconfig.go
  2. 13 7
      runconfig/parse.go
  3. 1 1
      runtime/container.go
  4. 19 0
      runtime/execdriver/native/configuration/fs.go
  5. 3 0
      runtime/execdriver/native/configuration/parse.go

+ 2 - 2
runconfig/hostconfig.go

@@ -13,7 +13,7 @@ type HostConfig struct {
 	PortBindings    nat.PortMap
 	Links           []string
 	PublishAllPorts bool
-	PluginOptions   map[string][]string
+	DriverOptions   map[string][]string
 }
 
 type KeyValuePair struct {
@@ -29,7 +29,7 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
 	}
 	job.GetenvJson("LxcConf", &hostConfig.LxcConf)
 	job.GetenvJson("PortBindings", &hostConfig.PortBindings)
-	job.GetenvJson("PluginOptions", &hostConfig.PluginOptions)
+	job.GetenvJson("DriverOptions", &hostConfig.DriverOptions)
 	if Binds := job.GetenvList("Binds"); Binds != nil {
 		hostConfig.Binds = Binds
 	}

+ 13 - 7
runconfig/parse.go

@@ -45,7 +45,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		flDnsSearch   = opts.NewListOpts(opts.ValidateDomain)
 		flVolumesFrom opts.ListOpts
 		flLxcOpts     opts.ListOpts
-		flPluginOpts  opts.ListOpts
+		flDriverOpts  opts.ListOpts
 
 		flAutoRemove      = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
 		flDetach          = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
@@ -77,8 +77,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 	cmd.Var(&flDns, []string{"#dns", "-dns"}, "Set custom dns servers")
 	cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom dns search domains")
 	cmd.Var(&flVolumesFrom, []string{"#volumes-from", "-volumes-from"}, "Mount volumes from the specified container(s)")
-	cmd.Var(&flLxcOpts, []string{"#lxc-conf", "-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
-	cmd.Var(&flPluginOpts, []string{"-plugin"}, "Add custom plugin options")
+	cmd.Var(&flLxcOpts, []string{"#lxc-conf", "#-lxc-conf"}, "Add custom lxc options --lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
+	cmd.Var(&flDriverOpts, []string{"o", "-opt"}, "Add custom driver options")
 
 	if err := cmd.Parse(args); err != nil {
 		return nil, nil, cmd, err
@@ -208,7 +208,10 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		WorkingDir:      *flWorkingDir,
 	}
 
-	pluginOptions := parsePluginOpts(flPluginOpts)
+	pluginOptions, err := parseDriverOpts(flDriverOpts)
+	if err != nil {
+		return nil, nil, cmd, err
+	}
 
 	hostConfig := &HostConfig{
 		Binds:           binds,
@@ -218,7 +221,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		PortBindings:    portBindings,
 		Links:           flLinks.GetAll(),
 		PublishAllPorts: *flPublishAll,
-		PluginOptions:   pluginOptions,
+		DriverOptions:   pluginOptions,
 	}
 
 	if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {
@@ -253,15 +256,18 @@ func parseLxcOpt(opt string) (string, string, error) {
 	return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
 }
 
-func parsePluginOpts(opts opts.ListOpts) map[string][]string {
+func parseDriverOpts(opts opts.ListOpts) (map[string][]string, error) {
 	out := make(map[string][]string, len(opts.GetAll()))
 	for _, o := range opts.GetAll() {
 		parts := strings.SplitN(o, " ", 2)
+		if len(parts) < 2 {
+			return nil, fmt.Errorf("invalid opt format %s", o)
+		}
 		values, exists := out[parts[0]]
 		if !exists {
 			values = []string{}
 		}
 		out[parts[0]] = append(values, parts[1])
 	}
-	return out
+	return out, nil
 }

+ 1 - 1
runtime/container.go

@@ -361,7 +361,7 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
 func populateCommand(c *Container) {
 	var (
 		en           *execdriver.Network
-		driverConfig = c.hostConfig.PluginOptions
+		driverConfig = c.hostConfig.DriverOptions
 	)
 
 	if driverConfig == nil {

+ 19 - 0
runtime/execdriver/native/configuration/fs.go

@@ -0,0 +1,19 @@
+package configuration
+
+import (
+	"fmt"
+	"github.com/dotcloud/docker/pkg/libcontainer"
+	"strings"
+)
+
+func parseFsOpts(container *libcontainer.Container, opts []string) error {
+	opt := strings.TrimSpace(opts[0])
+
+	switch opt {
+	case "readonly":
+		container.ReadonlyFs = true
+	default:
+		return fmt.Errorf("%s is not a valid filesystem option", opt)
+	}
+	return nil
+}

+ 3 - 0
runtime/execdriver/native/configuration/parse.go

@@ -18,6 +18,9 @@ func ParseConfiguration(container *libcontainer.Container, running map[string]*e
 			err   error
 			parts = strings.Split(strings.TrimSpace(opt), " ")
 		)
+		if len(parts) < 2 {
+			return fmt.Errorf("invalid native driver opt %s", opt)
+		}
 
 		switch parts[0] {
 		case "cap":