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:
parent
a1522ec01c
commit
305f735080
6 changed files with 19 additions and 34 deletions
|
@ -10,7 +10,6 @@ func NewBuilder(opts *BuildOpts) *BuildFile {
|
||||||
Dockerfile: nil,
|
Dockerfile: nil,
|
||||||
Config: &runconfig.Config{},
|
Config: &runconfig.Config{},
|
||||||
Options: opts,
|
Options: opts,
|
||||||
TmpContainers: UniqueMap{},
|
TmpContainers: map[string]struct{}{},
|
||||||
TmpImages: UniqueMap{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@ import (
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UniqueMap map[string]struct{}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
ErrDockerfileEmpty = errors.New("Dockerfile cannot be empty")
|
||||||
)
|
)
|
||||||
|
@ -74,8 +72,7 @@ type BuildFile struct {
|
||||||
Options *BuildOpts // see below
|
Options *BuildOpts // see below
|
||||||
|
|
||||||
// both of these are controlled by the Remove and ForceRemove options in BuildOpts
|
// both of these are controlled by the Remove and ForceRemove options in BuildOpts
|
||||||
TmpContainers UniqueMap // a map of containers used for removes
|
TmpContainers map[string]struct{} // a map of containers used for removes
|
||||||
TmpImages UniqueMap // a map of images used for removes
|
|
||||||
|
|
||||||
image string // image name for commit processing
|
image string // image name for commit processing
|
||||||
maintainer string // maintainer name. could probably be removed.
|
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 {
|
for i, n := range b.Dockerfile.Children {
|
||||||
if err := b.dispatch(i, n); err != nil {
|
if err := b.dispatch(i, n); err != nil {
|
||||||
if b.Options.ForceRemove {
|
if b.Options.ForceRemove {
|
||||||
b.clearTmp(b.TmpContainers)
|
b.clearTmp()
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(b.Options.OutStream, " ---> %s\n", utils.TruncateID(b.image))
|
fmt.Fprintf(b.Options.OutStream, " ---> %s\n", utils.TruncateID(b.image))
|
||||||
if b.Options.Remove {
|
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)
|
return f(b, strs, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(b.Options.ErrStream, "# Skipping unknown instruction %s\n", strings.ToUpper(cmd))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,6 @@ func (b *BuildFile) commit(id string, autoCmd []string, comment string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.TmpImages[image.ID] = struct{}{}
|
|
||||||
b.image = image.ID
|
b.image = image.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -304,7 +303,7 @@ func (b *BuildFile) processImageFrom(img *imagepkg.Image) error {
|
||||||
b.Config = img.Config
|
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)
|
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{}) {
|
func (b *BuildFile) clearTmp() {
|
||||||
for c := range containers {
|
for c := range b.TmpContainers {
|
||||||
tmp := b.Options.Daemon.Get(c)
|
tmp := b.Options.Daemon.Get(c)
|
||||||
if err := b.Options.Daemon.Destroy(tmp); err != nil {
|
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())
|
fmt.Fprintf(b.Options.OutStream, "Error removing intermediate container %s: %s\n", utils.TruncateID(c), err.Error())
|
||||||
} else {
|
} else {
|
||||||
delete(containers, c)
|
delete(b.TmpContainers, c)
|
||||||
fmt.Fprintf(b.Options.OutStream, "Removing intermediate container %s\n", utils.TruncateID(c))
|
fmt.Fprintf(b.Options.OutStream, "Removing intermediate container %s\n", utils.TruncateID(c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,18 +116,16 @@ func parseJSON(rest string) (*Node, map[string]bool, error) {
|
||||||
func parseMaybeJSON(rest string) (*Node, map[string]bool, error) {
|
func parseMaybeJSON(rest string) (*Node, map[string]bool, error) {
|
||||||
rest = strings.TrimSpace(rest)
|
rest = strings.TrimSpace(rest)
|
||||||
|
|
||||||
if strings.HasPrefix(rest, "[") {
|
node, attrs, err := parseJSON(rest)
|
||||||
node, attrs, err := parseJSON(rest)
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return node, attrs, nil
|
return node, attrs, nil
|
||||||
}
|
}
|
||||||
if err == errDockerfileJSONNesting {
|
if err == errDockerfileJSONNesting {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node := &Node{}
|
node = &Node{}
|
||||||
node.Value = rest
|
node.Value = rest
|
||||||
return node, nil, nil
|
return node, nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,7 @@ func Parse(rwc io.Reader) (*Node, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if line != "" && child == nil {
|
if line != "" && child == nil {
|
||||||
for {
|
for scanner.Scan() {
|
||||||
scanner.Scan()
|
|
||||||
newline := strings.TrimSpace(scanner.Text())
|
newline := strings.TrimSpace(scanner.Text())
|
||||||
|
|
||||||
if newline == "" {
|
if newline == "" {
|
||||||
|
|
|
@ -19,6 +19,7 @@ func (b *BuildFile) replaceEnv(str string) string {
|
||||||
tmp := strings.SplitN(keyval, "=", 2)
|
tmp := strings.SplitN(keyval, "=", 2)
|
||||||
if tmp[0] == matchKey {
|
if tmp[0] == matchKey {
|
||||||
str = strings.Replace(str, match, tmp[1], -1)
|
str = strings.Replace(str, match, tmp[1], -1)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +27,6 @@ func (b *BuildFile) replaceEnv(str string) string {
|
||||||
return str
|
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 {
|
func handleJsonArgs(args []string, attributes map[string]bool) []string {
|
||||||
if attributes != nil && attributes["json"] {
|
if attributes != nil && attributes["json"] {
|
||||||
return args
|
return args
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue