1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add setSubEnv and getSubEnv

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-01-28 03:26:24 +00:00
parent 55d7aa1b49
commit 7b7f7e4436
4 changed files with 38 additions and 13 deletions

18
api.go
View file

@ -345,11 +345,11 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
return err
}
var (
config = &Config{}
config engine.Env
env engine.Env
job = srv.Eng.Job("commit", r.Form.Get("container"))
)
if err := json.NewDecoder(r.Body).Decode(config); err != nil && err != io.EOF {
if err := config.Import(r.Body); err != nil {
utils.Errorf("%s", err)
}
@ -357,7 +357,7 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
job.Setenv("tag", r.Form.Get("tag"))
job.Setenv("author", r.Form.Get("author"))
job.Setenv("comment", r.Form.Get("comment"))
job.SetenvJson("config", config)
job.SetenvSubEnv("config", &config)
var id string
job.Stdout.AddString(&id)
@ -704,18 +704,14 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
return fmt.Errorf("Missing parameter")
}
// TODO: replace the buffer by job.AddEnv()
var (
job = srv.Eng.Job("inspect", vars["name"], "container")
buffer = bytes.NewBuffer(nil)
c Container
c, err = job.Stdout.AddEnv()
)
job.Stdout.Add(buffer)
if err := job.Run(); err != nil {
if err != nil {
return err
}
if err := json.Unmarshal(buffer.Bytes(), &c); err != nil {
if err = job.Run(); err != nil {
return err
}
@ -742,7 +738,7 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
if !c.Config.Tty && version >= 1.6 {
if c.GetSubEnv("Config") != nil && !c.GetSubEnv("Config").GetBool("Tty") && version >= 1.6 {
errStream = utils.NewStdWriter(outStream, utils.Stderr)
outStream = utils.NewStdWriter(outStream, utils.Stdout)
} else {

View file

@ -86,6 +86,28 @@ func (env *Env) GetList(key string) []string {
return l
}
func (env *Env) GetSubEnv(key string) *Env {
sval := env.Get(key)
if sval == "" {
return nil
}
buf := bytes.NewBufferString(sval)
var sub Env
if err := sub.Decode(buf); err != nil {
return nil
}
return &sub
}
func (env *Env) SetSubEnv(key string, sub *Env) error {
var buf bytes.Buffer
if err := sub.Encode(&buf); err != nil {
return err
}
env.Set(key, string(buf.Bytes()))
return nil
}
func (env *Env) GetJson(key string, iface interface{}) error {
sval := env.Get(key)
if sval == "" {

View file

@ -114,6 +114,14 @@ func (job *Job) SetenvBool(key string, value bool) {
job.env.SetBool(key, value)
}
func (job *Job) GetenvSubEnv(key string) *Env {
return job.env.GetSubEnv(key)
}
func (job *Job) SetenvSubEnv(key string, value *Env) error {
return job.env.SetSubEnv(key, value)
}
func (job *Job) GetenvInt64(key string) int64 {
return job.env.GetInt64(key)
}

View file

@ -1660,8 +1660,7 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status {
}
resolvConf, err := utils.GetResolvConf()
if err != nil {
job.Error(err)
return engine.StatusErr
return job.Error(err)
}
if !config.NetworkDisabled && len(config.Dns) == 0 && len(srv.runtime.config.Dns) == 0 && utils.CheckLocalDns(resolvConf) {
job.Errorf("WARNING: Docker detected local DNS server on resolv.conf. Using default external servers: %v\n", defaultDns)