diff --git a/builder/builder.go b/builder/builder.go index e655f9da60..685f27b061 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -10,7 +10,6 @@ func NewBuilder(opts *BuildOpts) *BuildFile { Dockerfile: nil, Config: &runconfig.Config{}, Options: opts, - TmpContainers: UniqueMap{}, - TmpImages: UniqueMap{}, + TmpContainers: map[string]struct{}{}, } } diff --git a/builder/evaluator.go b/builder/evaluator.go index 01805f892d..ec8edc98c8 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -38,8 +38,6 @@ import ( "github.com/docker/docker/utils" ) -type UniqueMap map[string]struct{} - var ( ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty") ) @@ -74,8 +72,7 @@ type BuildFile struct { Options *BuildOpts // see below // both of these are controlled by the Remove and ForceRemove options in BuildOpts - TmpContainers UniqueMap // a map of containers used for removes - TmpImages UniqueMap // a map of images used for removes + TmpContainers map[string]struct{} // a map of containers used for removes image string // image name for commit processing maintainer string // maintainer name. could probably be removed. @@ -147,13 +144,13 @@ func (b *BuildFile) Run(context io.Reader) (string, error) { for i, n := range b.Dockerfile.Children { if err := b.dispatch(i, n); err != nil { if b.Options.ForceRemove { - b.clearTmp(b.TmpContainers) + b.clearTmp() } return "", err } fmt.Fprintf(b.Options.OutStream, " ---> %s\n", utils.TruncateID(b.image)) if b.Options.Remove { - b.clearTmp(b.TmpContainers) + b.clearTmp() } } @@ -206,5 +203,7 @@ func (b *BuildFile) dispatch(stepN int, ast *parser.Node) error { return f(b, strs, attrs) } + fmt.Fprintf(b.Options.ErrStream, "# Skipping unknown instruction %s\n", strings.ToUpper(cmd)) + return nil } diff --git a/builder/internals.go b/builder/internals.go index b1d5b21f03..51b2b63ab9 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -97,7 +97,6 @@ func (b *BuildFile) commit(id string, autoCmd []string, comment string) error { if err != nil { return err } - b.TmpImages[image.ID] = struct{}{} b.image = image.ID return nil } @@ -304,7 +303,7 @@ func (b *BuildFile) processImageFrom(img *imagepkg.Image) error { b.Config = img.Config } - if b.Config.Env == nil || len(b.Config.Env) == 0 { + if len(b.Config.Env) == 0 { b.Config.Env = append(b.Config.Env, "PATH="+daemon.DefaultPathEnv) } @@ -549,13 +548,13 @@ func fixPermissions(destination string, uid, gid int) error { }) } -func (b *BuildFile) clearTmp(containers map[string]struct{}) { - for c := range containers { +func (b *BuildFile) clearTmp() { + for c := range b.TmpContainers { tmp := b.Options.Daemon.Get(c) if err := b.Options.Daemon.Destroy(tmp); err != nil { fmt.Fprintf(b.Options.OutStream, "Error removing intermediate container %s: %s\n", utils.TruncateID(c), err.Error()) } else { - delete(containers, c) + delete(b.TmpContainers, c) fmt.Fprintf(b.Options.OutStream, "Removing intermediate container %s\n", utils.TruncateID(c)) } } diff --git a/builder/parser/line_parsers.go b/builder/parser/line_parsers.go index 999d97603d..93fa23ee85 100644 --- a/builder/parser/line_parsers.go +++ b/builder/parser/line_parsers.go @@ -116,18 +116,16 @@ func parseJSON(rest string) (*Node, map[string]bool, error) { func parseMaybeJSON(rest string) (*Node, map[string]bool, error) { rest = strings.TrimSpace(rest) - if strings.HasPrefix(rest, "[") { - node, attrs, err := parseJSON(rest) + node, attrs, err := parseJSON(rest) - if err == nil { - return node, attrs, nil - } - if err == errDockerfileJSONNesting { - return nil, nil, err - } + if err == nil { + return node, attrs, nil + } + if err == errDockerfileJSONNesting { + return nil, nil, err } - node := &Node{} + node = &Node{} node.Value = rest return node, nil, nil } diff --git a/builder/parser/parser.go b/builder/parser/parser.go index 47ffc9a678..8315412bd7 100644 --- a/builder/parser/parser.go +++ b/builder/parser/parser.go @@ -100,8 +100,7 @@ func Parse(rwc io.Reader) (*Node, error) { } if line != "" && child == nil { - for { - scanner.Scan() + for scanner.Scan() { newline := strings.TrimSpace(scanner.Text()) if newline == "" { diff --git a/builder/support.go b/builder/support.go index 08cfa8defa..bae97e370f 100644 --- a/builder/support.go +++ b/builder/support.go @@ -19,6 +19,7 @@ func (b *BuildFile) replaceEnv(str string) string { tmp := strings.SplitN(keyval, "=", 2) if tmp[0] == matchKey { str = strings.Replace(str, match, tmp[1], -1) + break } } } @@ -26,16 +27,6 @@ func (b *BuildFile) replaceEnv(str string) string { return str } -func (b *BuildFile) FindEnvKey(key string) int { - for k, envVar := range b.Config.Env { - envParts := strings.SplitN(envVar, "=", 2) - if key == envParts[0] { - return k - } - } - return -1 -} - func handleJsonArgs(args []string, attributes map[string]bool) []string { if attributes != nil && attributes["json"] { return args