From ec2fdcee5df9e81020046edd073dab69aca60a60 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 6 May 2013 18:39:56 -0700 Subject: [PATCH 1/2] Implement ENV within docker builder Upstream-commit: e45aef0c82044be6a427502d4bbb0979074c2ba1 Component: engine --- components/engine/builder.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/components/engine/builder.go b/components/engine/builder.go index 61ea03311c..e835c6d390 100644 --- a/components/engine/builder.go +++ b/components/engine/builder.go @@ -200,6 +200,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e image, base *Image config *Config maintainer string + env map[string]string = make(map[string]string) tmpContainers map[string]struct{} = make(map[string]struct{}) tmpImages map[string]struct{} = make(map[string]struct{}) ) @@ -270,6 +271,10 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e return nil, err } + for key, value := range env { + config.Env = append(config.Env, fmt.Sprintf("%s=%s", key, value)) + } + if cache, err := builder.getCachedImage(image, config); err != nil { return nil, err } else if cache != nil { @@ -278,11 +283,21 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e break } + Debugf("Env -----> %v ------ %v\n", config.Env, env) + // Create the container and start it c, err := builder.Create(config) if err != nil { return nil, err } + + if os.Getenv("DEBUG") != "" { + out, _ := c.StdoutPipe() + err2, _ := c.StderrPipe() + go io.Copy(os.Stdout, out) + go io.Copy(os.Stdout, err2) + } + if err := c.Start(); err != nil { return nil, err } @@ -305,6 +320,21 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e // use the base as the new image image = base + break + case "env": + tmp := strings.SplitN(arguments, " ", 2) + if len(tmp) != 2 { + return nil, fmt.Errorf("Invalid ENV format") + } + key := strings.Trim(tmp[0], " ") + value := strings.Trim(tmp[1], " ") + fmt.Fprintf(stdout, "ENV %s %s\n", key, value) + env[key] = value + if image != nil { + fmt.Fprintf(stdout, "===> %s\n", image.ShortId()) + } else { + fmt.Fprintf(stdout, "===> \n") + } break case "cmd": fmt.Fprintf(stdout, "CMD %s\n", arguments) From 0d4addc80f402e552e71e6d7d1f56cde13915726 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 6 May 2013 18:54:27 -0700 Subject: [PATCH 2/2] Add the ENV instruciton to the docker builder documentation Upstream-commit: 4c7c177e4ea4a166e656306e1d845cdb9e2f37ce Component: engine --- components/engine/docs/sources/builder/basics.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/engine/docs/sources/builder/basics.rst b/components/engine/docs/sources/builder/basics.rst index 2282cccf29..0d726e93c1 100644 --- a/components/engine/docs/sources/builder/basics.rst +++ b/components/engine/docs/sources/builder/basics.rst @@ -66,7 +66,16 @@ It is equivalent to do `docker commit -run '{"Cmd": }'` outside the bui The `EXPOSE` instruction sets ports to be publicly exposed when running the image. This is equivalent to do `docker commit -run '{"PortSpecs": ["", ""]}'` outside the builder. -2.6 INSERT +2.6 ENV +------- + ``ENV `` + +The `ENV` instruction set as environment variable `` with the value ``. This value will be passed to all future ``RUN`` instructions. + +.. note:: + The environment variables are local to the Dockerfile, they will not be set as autorun. + +2.7 INSERT ---------- ``INSERT ``