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

builder: several fixups from comments

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
Erik Hollensbe 2014-08-19 11:14:21 +00:00
parent a1522ec01c
commit 305f735080
6 changed files with 19 additions and 34 deletions

View file

@ -10,7 +10,6 @@ func NewBuilder(opts *BuildOpts) *BuildFile {
Dockerfile: nil,
Config: &runconfig.Config{},
Options: opts,
TmpContainers: UniqueMap{},
TmpImages: UniqueMap{},
TmpContainers: map[string]struct{}{},
}
}

View file

@ -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
}

View file

@ -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))
}
}

View file

@ -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
}

View file

@ -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 == "" {

View file

@ -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