1
0
mirror of https://github.com/rancher/os.git synced 2025-09-16 15:09:27 +00:00

Use a map to configure Docker arguments

This commit is contained in:
Josh Curl
2016-09-25 17:55:19 -07:00
parent 605a8bf618
commit 065fe4a16e
8 changed files with 137 additions and 29 deletions

View File

@@ -1,17 +1,52 @@
package config
import "os"
import (
"fmt"
"os"
"github.com/fatih/structs"
)
func (d *DockerConfig) FullArgs() []string {
args := append(d.Args, d.ExtraArgs...)
args := []string{"daemon"}
args = append(args, generateEngineOptsSlice(d.EngineOpts)...)
args = append(args, d.ExtraArgs...)
if d.TLS {
args = append(args, d.TLSArgs...)
}
return args
}
func (d *DockerConfig) AppendEnv() []string {
return append(os.Environ(), d.Environment...)
}
func generateEngineOptsSlice(opts EngineOpts) []string {
optsStruct := structs.New(opts)
var optsSlice []string
for k, v := range optsStruct.Map() {
optTag := optsStruct.Field(k).Tag("opt")
switch value := v.(type) {
case string:
if value != "" {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), value)
}
case *bool:
if value != nil {
if *value {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag))
} else {
optsSlice = append(optsSlice, fmt.Sprintf("--%s=false", optTag))
}
}
case map[string]string:
for k, v := range value {
optsSlice = append(optsSlice, fmt.Sprintf("--%s", optTag), fmt.Sprintf("%s=%s", k, v))
}
}
}
return optsSlice
}