Browse code

Merge pull request #14790 from hqhq/hq_golint_build

Fix golint warnings for builder

Alexander Morozov authored on 2015/07/23 00:17:04
Showing 13 changed files
... ...
@@ -688,7 +688,7 @@ func (s *Server) postCommit(version version.Version, w http.ResponseWriter, r *h
688 688
 		return err
689 689
 	}
690 690
 
691
-	commitCfg := &builder.BuilderCommitConfig{
691
+	commitCfg := &builder.CommitConfig{
692 692
 		Pause:   pause,
693 693
 		Repo:    r.Form.Get("repo"),
694 694
 		Tag:     r.Form.Get("tag"),
... ...
@@ -1276,11 +1276,11 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
1276 1276
 	buildConfig.AuthConfigs = authConfigs
1277 1277
 	buildConfig.MemorySwap = int64ValueOrZero(r, "memswap")
1278 1278
 	buildConfig.Memory = int64ValueOrZero(r, "memory")
1279
-	buildConfig.CpuShares = int64ValueOrZero(r, "cpushares")
1280
-	buildConfig.CpuPeriod = int64ValueOrZero(r, "cpuperiod")
1281
-	buildConfig.CpuQuota = int64ValueOrZero(r, "cpuquota")
1282
-	buildConfig.CpuSetCpus = r.FormValue("cpusetcpus")
1283
-	buildConfig.CpuSetMems = r.FormValue("cpusetmems")
1279
+	buildConfig.CPUShares = int64ValueOrZero(r, "cpushares")
1280
+	buildConfig.CPUPeriod = int64ValueOrZero(r, "cpuperiod")
1281
+	buildConfig.CPUQuota = int64ValueOrZero(r, "cpuquota")
1282
+	buildConfig.CPUSetCpus = r.FormValue("cpusetcpus")
1283
+	buildConfig.CPUSetMems = r.FormValue("cpusetmems")
1284 1284
 	buildConfig.CgroupParent = r.FormValue("cgroupparent")
1285 1285
 
1286 1286
 	// Job cancellation. Note: not all job types support this.
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"strings"
6 6
 )
7 7
 
8
+// FlagType is the type of the build flag
8 9
 type FlagType int
9 10
 
10 11
 const (
... ...
@@ -12,28 +13,32 @@ const (
12 12
 	stringType
13 13
 )
14 14
 
15
-type BuilderFlags struct {
15
+// BFlags contains all flags information for the builder
16
+type BFlags struct {
16 17
 	Args  []string // actual flags/args from cmd line
17 18
 	flags map[string]*Flag
18 19
 	used  map[string]*Flag
19 20
 	Err   error
20 21
 }
21 22
 
23
+// Flag contains all information for a flag
22 24
 type Flag struct {
23
-	bf       *BuilderFlags
25
+	bf       *BFlags
24 26
 	name     string
25 27
 	flagType FlagType
26 28
 	Value    string
27 29
 }
28 30
 
29
-func NewBuilderFlags() *BuilderFlags {
30
-	return &BuilderFlags{
31
+// NewBFlags return the new BFlags struct
32
+func NewBFlags() *BFlags {
33
+	return &BFlags{
31 34
 		flags: make(map[string]*Flag),
32 35
 		used:  make(map[string]*Flag),
33 36
 	}
34 37
 }
35 38
 
36
-func (bf *BuilderFlags) AddBool(name string, def bool) *Flag {
39
+// AddBool adds a bool flag to BFlags
40
+func (bf *BFlags) AddBool(name string, def bool) *Flag {
37 41
 	flag := bf.addFlag(name, boolType)
38 42
 	if flag == nil {
39 43
 		return nil
... ...
@@ -46,7 +51,8 @@ func (bf *BuilderFlags) AddBool(name string, def bool) *Flag {
46 46
 	return flag
47 47
 }
48 48
 
49
-func (bf *BuilderFlags) AddString(name string, def string) *Flag {
49
+// AddString adds a string flag to BFlags
50
+func (bf *BFlags) AddString(name string, def string) *Flag {
50 51
 	flag := bf.addFlag(name, stringType)
51 52
 	if flag == nil {
52 53
 		return nil
... ...
@@ -55,7 +61,7 @@ func (bf *BuilderFlags) AddString(name string, def string) *Flag {
55 55
 	return flag
56 56
 }
57 57
 
58
-func (bf *BuilderFlags) addFlag(name string, flagType FlagType) *Flag {
58
+func (bf *BFlags) addFlag(name string, flagType FlagType) *Flag {
59 59
 	if _, ok := bf.flags[name]; ok {
60 60
 		bf.Err = fmt.Errorf("Duplicate flag defined: %s", name)
61 61
 		return nil
... ...
@@ -71,6 +77,7 @@ func (bf *BuilderFlags) addFlag(name string, flagType FlagType) *Flag {
71 71
 	return newFlag
72 72
 }
73 73
 
74
+// IsUsed checks if the flag is used
74 75
 func (fl *Flag) IsUsed() bool {
75 76
 	if _, ok := fl.bf.used[fl.name]; ok {
76 77
 		return true
... ...
@@ -78,6 +85,7 @@ func (fl *Flag) IsUsed() bool {
78 78
 	return false
79 79
 }
80 80
 
81
+// IsTrue checks if a bool flag is true
81 82
 func (fl *Flag) IsTrue() bool {
82 83
 	if fl.flagType != boolType {
83 84
 		// Should never get here
... ...
@@ -86,7 +94,8 @@ func (fl *Flag) IsTrue() bool {
86 86
 	return fl.Value == "true"
87 87
 }
88 88
 
89
-func (bf *BuilderFlags) Parse() error {
89
+// Parse parses and checks if the BFlags is valid
90
+func (bf *BFlags) Parse() error {
90 91
 	// If there was an error while defining the possible flags
91 92
 	// go ahead and bubble it back up here since we didn't do it
92 93
 	// earlier in the processing
... ...
@@ -10,7 +10,7 @@ func TestBuilderFlags(t *testing.T) {
10 10
 
11 11
 	// ---
12 12
 
13
-	bf := NewBuilderFlags()
13
+	bf := NewBFlags()
14 14
 	bf.Args = []string{}
15 15
 	if err := bf.Parse(); err != nil {
16 16
 		t.Fatalf("Test1 of %q was supposed to work: %s", bf.Args, err)
... ...
@@ -18,7 +18,7 @@ func TestBuilderFlags(t *testing.T) {
18 18
 
19 19
 	// ---
20 20
 
21
-	bf = NewBuilderFlags()
21
+	bf = NewBFlags()
22 22
 	bf.Args = []string{"--"}
23 23
 	if err := bf.Parse(); err != nil {
24 24
 		t.Fatalf("Test2 of %q was supposed to work: %s", bf.Args, err)
... ...
@@ -26,7 +26,7 @@ func TestBuilderFlags(t *testing.T) {
26 26
 
27 27
 	// ---
28 28
 
29
-	bf = NewBuilderFlags()
29
+	bf = NewBFlags()
30 30
 	flStr1 := bf.AddString("str1", "")
31 31
 	flBool1 := bf.AddBool("bool1", false)
32 32
 	bf.Args = []string{}
... ...
@@ -43,7 +43,7 @@ func TestBuilderFlags(t *testing.T) {
43 43
 
44 44
 	// ---
45 45
 
46
-	bf = NewBuilderFlags()
46
+	bf = NewBFlags()
47 47
 	flStr1 = bf.AddString("str1", "HI")
48 48
 	flBool1 = bf.AddBool("bool1", false)
49 49
 	bf.Args = []string{}
... ...
@@ -67,7 +67,7 @@ func TestBuilderFlags(t *testing.T) {
67 67
 
68 68
 	// ---
69 69
 
70
-	bf = NewBuilderFlags()
70
+	bf = NewBFlags()
71 71
 	flStr1 = bf.AddString("str1", "HI")
72 72
 	bf.Args = []string{"--str1"}
73 73
 
... ...
@@ -77,7 +77,7 @@ func TestBuilderFlags(t *testing.T) {
77 77
 
78 78
 	// ---
79 79
 
80
-	bf = NewBuilderFlags()
80
+	bf = NewBFlags()
81 81
 	flStr1 = bf.AddString("str1", "HI")
82 82
 	bf.Args = []string{"--str1="}
83 83
 
... ...
@@ -92,7 +92,7 @@ func TestBuilderFlags(t *testing.T) {
92 92
 
93 93
 	// ---
94 94
 
95
-	bf = NewBuilderFlags()
95
+	bf = NewBFlags()
96 96
 	flStr1 = bf.AddString("str1", "HI")
97 97
 	bf.Args = []string{"--str1=BYE"}
98 98
 
... ...
@@ -107,7 +107,7 @@ func TestBuilderFlags(t *testing.T) {
107 107
 
108 108
 	// ---
109 109
 
110
-	bf = NewBuilderFlags()
110
+	bf = NewBFlags()
111 111
 	flBool1 = bf.AddBool("bool1", false)
112 112
 	bf.Args = []string{"--bool1"}
113 113
 
... ...
@@ -121,7 +121,7 @@ func TestBuilderFlags(t *testing.T) {
121 121
 
122 122
 	// ---
123 123
 
124
-	bf = NewBuilderFlags()
124
+	bf = NewBFlags()
125 125
 	flBool1 = bf.AddBool("bool1", false)
126 126
 	bf.Args = []string{"--bool1=true"}
127 127
 
... ...
@@ -135,7 +135,7 @@ func TestBuilderFlags(t *testing.T) {
135 135
 
136 136
 	// ---
137 137
 
138
-	bf = NewBuilderFlags()
138
+	bf = NewBFlags()
139 139
 	flBool1 = bf.AddBool("bool1", false)
140 140
 	bf.Args = []string{"--bool1=false"}
141 141
 
... ...
@@ -149,7 +149,7 @@ func TestBuilderFlags(t *testing.T) {
149 149
 
150 150
 	// ---
151 151
 
152
-	bf = NewBuilderFlags()
152
+	bf = NewBFlags()
153 153
 	flBool1 = bf.AddBool("bool1", false)
154 154
 	bf.Args = []string{"--bool1=false1"}
155 155
 
... ...
@@ -159,7 +159,7 @@ func TestBuilderFlags(t *testing.T) {
159 159
 
160 160
 	// ---
161 161
 
162
-	bf = NewBuilderFlags()
162
+	bf = NewBFlags()
163 163
 	flBool1 = bf.AddBool("bool1", false)
164 164
 	bf.Args = []string{"--bool2"}
165 165
 
... ...
@@ -169,7 +169,7 @@ func TestBuilderFlags(t *testing.T) {
169 169
 
170 170
 	// ---
171 171
 
172
-	bf = NewBuilderFlags()
172
+	bf = NewBFlags()
173 173
 	flStr1 = bf.AddString("str1", "HI")
174 174
 	flBool1 = bf.AddBool("bool1", false)
175 175
 	bf.Args = []string{"--bool1", "--str1=BYE"}
... ...
@@ -1,6 +1,7 @@
1
-// This package contains the set of Dockerfile commands.
1
+// Package command contains the set of Dockerfile commands.
2 2
 package command
3 3
 
4
+// Define constants for the command strings
4 5
 const (
5 6
 	Env        = "env"
6 7
 	Label      = "label"
... ...
@@ -30,7 +30,7 @@ const (
30 30
 )
31 31
 
32 32
 // dispatch with no layer / parsing. This is effectively not a command.
33
-func nullDispatch(b *Builder, args []string, attributes map[string]bool, original string) error {
33
+func nullDispatch(b *builder, args []string, attributes map[string]bool, original string) error {
34 34
 	return nil
35 35
 }
36 36
 
... ...
@@ -39,7 +39,7 @@ func nullDispatch(b *Builder, args []string, attributes map[string]bool, origina
39 39
 // Sets the environment variable foo to bar, also makes interpolation
40 40
 // in the dockerfile available from the next statement on via ${foo}.
41 41
 //
42
-func env(b *Builder, args []string, attributes map[string]bool, original string) error {
42
+func env(b *builder, args []string, attributes map[string]bool, original string) error {
43 43
 	if len(args) == 0 {
44 44
 		return fmt.Errorf("ENV requires at least one argument")
45 45
 	}
... ...
@@ -98,7 +98,7 @@ func env(b *Builder, args []string, attributes map[string]bool, original string)
98 98
 // MAINTAINER some text <maybe@an.email.address>
99 99
 //
100 100
 // Sets the maintainer metadata.
101
-func maintainer(b *Builder, args []string, attributes map[string]bool, original string) error {
101
+func maintainer(b *builder, args []string, attributes map[string]bool, original string) error {
102 102
 	if len(args) != 1 {
103 103
 		return fmt.Errorf("MAINTAINER requires exactly one argument")
104 104
 	}
... ...
@@ -115,7 +115,7 @@ func maintainer(b *Builder, args []string, attributes map[string]bool, original
115 115
 //
116 116
 // Sets the Label variable foo to bar,
117 117
 //
118
-func label(b *Builder, args []string, attributes map[string]bool, original string) error {
118
+func label(b *builder, args []string, attributes map[string]bool, original string) error {
119 119
 	if len(args) == 0 {
120 120
 		return fmt.Errorf("LABEL requires at least one argument")
121 121
 	}
... ...
@@ -151,7 +151,7 @@ func label(b *Builder, args []string, attributes map[string]bool, original strin
151 151
 // Add the file 'foo' to '/path'. Tarball and Remote URL (git, http) handling
152 152
 // exist here. If you do not wish to have this automatic handling, use COPY.
153 153
 //
154
-func add(b *Builder, args []string, attributes map[string]bool, original string) error {
154
+func add(b *builder, args []string, attributes map[string]bool, original string) error {
155 155
 	if len(args) < 2 {
156 156
 		return fmt.Errorf("ADD requires at least two arguments")
157 157
 	}
... ...
@@ -167,7 +167,7 @@ func add(b *Builder, args []string, attributes map[string]bool, original string)
167 167
 //
168 168
 // Same as 'ADD' but without the tar and remote url handling.
169 169
 //
170
-func dispatchCopy(b *Builder, args []string, attributes map[string]bool, original string) error {
170
+func dispatchCopy(b *builder, args []string, attributes map[string]bool, original string) error {
171 171
 	if len(args) < 2 {
172 172
 		return fmt.Errorf("COPY requires at least two arguments")
173 173
 	}
... ...
@@ -183,7 +183,7 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, origina
183 183
 //
184 184
 // This sets the image the dockerfile will build on top of.
185 185
 //
186
-func from(b *Builder, args []string, attributes map[string]bool, original string) error {
186
+func from(b *builder, args []string, attributes map[string]bool, original string) error {
187 187
 	if len(args) != 1 {
188 188
 		return fmt.Errorf("FROM requires one argument")
189 189
 	}
... ...
@@ -231,7 +231,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
231 231
 // special cases. search for 'OnBuild' in internals.go for additional special
232 232
 // cases.
233 233
 //
234
-func onbuild(b *Builder, args []string, attributes map[string]bool, original string) error {
234
+func onbuild(b *builder, args []string, attributes map[string]bool, original string) error {
235 235
 	if len(args) == 0 {
236 236
 		return fmt.Errorf("ONBUILD requires at least one argument")
237 237
 	}
... ...
@@ -258,7 +258,7 @@ func onbuild(b *Builder, args []string, attributes map[string]bool, original str
258 258
 //
259 259
 // Set the working directory for future RUN/CMD/etc statements.
260 260
 //
261
-func workdir(b *Builder, args []string, attributes map[string]bool, original string) error {
261
+func workdir(b *builder, args []string, attributes map[string]bool, original string) error {
262 262
 	if len(args) != 1 {
263 263
 		return fmt.Errorf("WORKDIR requires exactly one argument")
264 264
 	}
... ...
@@ -315,7 +315,7 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
315 315
 // RUN echo hi          # cmd /S /C echo hi   (Windows)
316 316
 // RUN [ "echo", "hi" ] # echo hi
317 317
 //
318
-func run(b *Builder, args []string, attributes map[string]bool, original string) error {
318
+func run(b *builder, args []string, attributes map[string]bool, original string) error {
319 319
 	if b.image == "" && !b.noBaseImage {
320 320
 		return fmt.Errorf("Please provide a source image with `from` prior to run")
321 321
 	}
... ...
@@ -324,7 +324,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
324 324
 		return err
325 325
 	}
326 326
 
327
-	args = handleJsonArgs(args, attributes)
327
+	args = handleJSONArgs(args, attributes)
328 328
 
329 329
 	if !attributes["json"] {
330 330
 		if runtime.GOOS != "windows" {
... ...
@@ -386,12 +386,12 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
386 386
 // Set the default command to run in the container (which may be empty).
387 387
 // Argument handling is the same as RUN.
388 388
 //
389
-func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
389
+func cmd(b *builder, args []string, attributes map[string]bool, original string) error {
390 390
 	if err := b.BuilderFlags.Parse(); err != nil {
391 391
 		return err
392 392
 	}
393 393
 
394
-	cmdSlice := handleJsonArgs(args, attributes)
394
+	cmdSlice := handleJSONArgs(args, attributes)
395 395
 
396 396
 	if !attributes["json"] {
397 397
 		if runtime.GOOS != "windows" {
... ...
@@ -422,12 +422,12 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
422 422
 // Handles command processing similar to CMD and RUN, only b.Config.Entrypoint
423 423
 // is initialized at NewBuilder time instead of through argument parsing.
424 424
 //
425
-func entrypoint(b *Builder, args []string, attributes map[string]bool, original string) error {
425
+func entrypoint(b *builder, args []string, attributes map[string]bool, original string) error {
426 426
 	if err := b.BuilderFlags.Parse(); err != nil {
427 427
 		return err
428 428
 	}
429 429
 
430
-	parsed := handleJsonArgs(args, attributes)
430
+	parsed := handleJSONArgs(args, attributes)
431 431
 
432 432
 	switch {
433 433
 	case attributes["json"]:
... ...
@@ -463,7 +463,7 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
463 463
 // Expose ports for links and port mappings. This all ends up in
464 464
 // b.Config.ExposedPorts for runconfig.
465 465
 //
466
-func expose(b *Builder, args []string, attributes map[string]bool, original string) error {
466
+func expose(b *builder, args []string, attributes map[string]bool, original string) error {
467 467
 	portsTab := args
468 468
 
469 469
 	if len(args) == 0 {
... ...
@@ -504,9 +504,9 @@ func expose(b *Builder, args []string, attributes map[string]bool, original stri
504 504
 // Set the user to 'foo' for future commands and when running the
505 505
 // ENTRYPOINT/CMD at container run time.
506 506
 //
507
-func user(b *Builder, args []string, attributes map[string]bool, original string) error {
507
+func user(b *builder, args []string, attributes map[string]bool, original string) error {
508 508
 	if runtime.GOOS == "windows" {
509
-		return fmt.Errorf("USER is not supported on Windows.")
509
+		return fmt.Errorf("USER is not supported on Windows")
510 510
 	}
511 511
 
512 512
 	if len(args) != 1 {
... ...
@@ -525,9 +525,9 @@ func user(b *Builder, args []string, attributes map[string]bool, original string
525 525
 //
526 526
 // Expose the volume /foo for use. Will also accept the JSON array form.
527 527
 //
528
-func volume(b *Builder, args []string, attributes map[string]bool, original string) error {
528
+func volume(b *builder, args []string, attributes map[string]bool, original string) error {
529 529
 	if runtime.GOOS == "windows" {
530
-		return fmt.Errorf("VOLUME is not supported on Windows.")
530
+		return fmt.Errorf("VOLUME is not supported on Windows")
531 531
 	}
532 532
 	if len(args) == 0 {
533 533
 		return fmt.Errorf("VOLUME requires at least one argument")
... ...
@@ -53,10 +53,10 @@ var replaceEnvAllowed = map[string]struct{}{
53 53
 	command.User:    {},
54 54
 }
55 55
 
56
-var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error
56
+var evaluateTable map[string]func(*builder, []string, map[string]bool, string) error
57 57
 
58 58
 func init() {
59
-	evaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{
59
+	evaluateTable = map[string]func(*builder, []string, map[string]bool, string) error{
60 60
 		command.Env:        env,
61 61
 		command.Label:      label,
62 62
 		command.Maintainer: maintainer,
... ...
@@ -74,9 +74,9 @@ func init() {
74 74
 	}
75 75
 }
76 76
 
77
-// internal struct, used to maintain configuration of the Dockerfile's
77
+// builder is an internal struct, used to maintain configuration of the Dockerfile's
78 78
 // processing as it evaluates the parsing result.
79
-type Builder struct {
79
+type builder struct {
80 80
 	Daemon *daemon.Daemon
81 81
 
82 82
 	// effectively stdio for the run. Because it is not stdio, I said
... ...
@@ -115,7 +115,7 @@ type Builder struct {
115 115
 	image          string        // image name for commit processing
116 116
 	maintainer     string        // maintainer name. could probably be removed.
117 117
 	cmdSet         bool          // indicates is CMD was set in current Dockerfile
118
-	BuilderFlags   *BuilderFlags // current cmd's BuilderFlags - temporary
118
+	BuilderFlags   *BFlags       // current cmd's BuilderFlags - temporary
119 119
 	context        tarsum.TarSum // the context is a tarball that is uploaded by the client
120 120
 	contextPath    string        // the path of the temporary directory the local context is unpacked to (server side)
121 121
 	noBaseImage    bool          // indicates that this build does not start from any base image, but is being built from an empty file system.
... ...
@@ -148,7 +148,7 @@ type Builder struct {
148 148
 //   processing.
149 149
 // * Print a happy message and return the image ID.
150 150
 //
151
-func (b *Builder) Run(context io.Reader) (string, error) {
151
+func (b *builder) Run(context io.Reader) (string, error) {
152 152
 	if err := b.readContext(context); err != nil {
153 153
 		return "", err
154 154
 	}
... ...
@@ -199,7 +199,7 @@ func (b *Builder) Run(context io.Reader) (string, error) {
199 199
 
200 200
 // Reads a Dockerfile from the current context. It assumes that the
201 201
 // 'filename' is a relative path from the root of the context
202
-func (b *Builder) readDockerfile() error {
202
+func (b *builder) readDockerfile() error {
203 203
 	// If no -f was specified then look for 'Dockerfile'. If we can't find
204 204
 	// that then look for 'dockerfile'.  If neither are found then default
205 205
 	// back to 'Dockerfile' and use that in the error message.
... ...
@@ -277,7 +277,7 @@ func (b *Builder) readDockerfile() error {
277 277
 // such as `RUN` in ONBUILD RUN foo. There is special case logic in here to
278 278
 // deal with that, at least until it becomes more of a general concern with new
279 279
 // features.
280
-func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
280
+func (b *builder) dispatch(stepN int, ast *parser.Node) error {
281 281
 	cmd := ast.Value
282 282
 	attrs := ast.Attributes
283 283
 	original := ast.Original
... ...
@@ -340,7 +340,7 @@ func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
340 340
 	// XXX yes, we skip any cmds that are not valid; the parser should have
341 341
 	// picked these out already.
342 342
 	if f, ok := evaluateTable[cmd]; ok {
343
-		b.BuilderFlags = NewBuilderFlags()
343
+		b.BuilderFlags = NewBFlags()
344 344
 		b.BuilderFlags.Args = flags
345 345
 		return f(b, strList, attrs, original)
346 346
 	}
... ...
@@ -40,7 +40,7 @@ import (
40 40
 	"github.com/docker/docker/runconfig"
41 41
 )
42 42
 
43
-func (b *Builder) readContext(context io.Reader) (err error) {
43
+func (b *builder) readContext(context io.Reader) (err error) {
44 44
 	tmpdirPath, err := ioutil.TempDir("", "docker-build")
45 45
 	if err != nil {
46 46
 		return
... ...
@@ -73,7 +73,7 @@ func (b *Builder) readContext(context io.Reader) (err error) {
73 73
 	return
74 74
 }
75 75
 
76
-func (b *Builder) commit(id string, autoCmd *runconfig.Command, comment string) error {
76
+func (b *builder) commit(id string, autoCmd *runconfig.Command, comment string) error {
77 77
 	if b.disableCommit {
78 78
 		return nil
79 79
 	}
... ...
@@ -143,7 +143,7 @@ type copyInfo struct {
143 143
 	tmpDir     string
144 144
 }
145 145
 
146
-func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecompression bool, cmdName string) error {
146
+func (b *builder) runContextCommand(args []string, allowRemote bool, allowDecompression bool, cmdName string) error {
147 147
 	if b.context == nil {
148 148
 		return fmt.Errorf("No context given. Impossible to use %s", cmdName)
149 149
 	}
... ...
@@ -261,7 +261,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
261 261
 	return nil
262 262
 }
263 263
 
264
-func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool, allowWildcards bool) error {
264
+func calcCopyInfo(b *builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool, allowWildcards bool) error {
265 265
 
266 266
 	// Work in daemon-specific OS filepath semantics. However, we save
267 267
 	// the the origPath passed in here, as it might also be a URL which
... ...
@@ -398,7 +398,7 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri
398 398
 	}
399 399
 
400 400
 	// Deal with wildcards
401
-	if allowWildcards && ContainsWildcards(origPath) {
401
+	if allowWildcards && containsWildcards(origPath) {
402 402
 		for _, fileInfo := range b.context.GetSums() {
403 403
 			if fileInfo.Name() == "" {
404 404
 				continue
... ...
@@ -475,7 +475,7 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri
475 475
 	return nil
476 476
 }
477 477
 
478
-func ContainsWildcards(name string) bool {
478
+func containsWildcards(name string) bool {
479 479
 	for i := 0; i < len(name); i++ {
480 480
 		ch := name[i]
481 481
 		if ch == '\\' {
... ...
@@ -487,7 +487,7 @@ func ContainsWildcards(name string) bool {
487 487
 	return false
488 488
 }
489 489
 
490
-func (b *Builder) pullImage(name string) (*image.Image, error) {
490
+func (b *builder) pullImage(name string) (*image.Image, error) {
491 491
 	remote, tag := parsers.ParseRepositoryTag(name)
492 492
 	if tag == "" {
493 493
 		tag = "latest"
... ...
@@ -525,7 +525,7 @@ func (b *Builder) pullImage(name string) (*image.Image, error) {
525 525
 	return image, nil
526 526
 }
527 527
 
528
-func (b *Builder) processImageFrom(img *image.Image) error {
528
+func (b *builder) processImageFrom(img *image.Image) error {
529 529
 	b.image = img.ID
530 530
 
531 531
 	if img.Config != nil {
... ...
@@ -577,7 +577,7 @@ func (b *Builder) processImageFrom(img *image.Image) error {
577 577
 // in the current server `b.Daemon`. If an image is found, probeCache returns
578 578
 // `(true, nil)`. If no image is found, it returns `(false, nil)`. If there
579 579
 // is any error, it returns `(false, err)`.
580
-func (b *Builder) probeCache() (bool, error) {
580
+func (b *builder) probeCache() (bool, error) {
581 581
 	if !b.UtilizeCache || b.cacheBusted {
582 582
 		return false, nil
583 583
 	}
... ...
@@ -600,7 +600,7 @@ func (b *Builder) probeCache() (bool, error) {
600 600
 	return true, nil
601 601
 }
602 602
 
603
-func (b *Builder) create() (*daemon.Container, error) {
603
+func (b *builder) create() (*daemon.Container, error) {
604 604
 	if b.image == "" && !b.noBaseImage {
605 605
 		return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
606 606
 	}
... ...
@@ -643,7 +643,7 @@ func (b *Builder) create() (*daemon.Container, error) {
643 643
 	return c, nil
644 644
 }
645 645
 
646
-func (b *Builder) run(c *daemon.Container) error {
646
+func (b *builder) run(c *daemon.Container) error {
647 647
 	var errCh chan error
648 648
 	if b.Verbose {
649 649
 		errCh = c.Attach(nil, b.OutStream, b.ErrStream)
... ...
@@ -683,7 +683,7 @@ func (b *Builder) run(c *daemon.Container) error {
683 683
 	return nil
684 684
 }
685 685
 
686
-func (b *Builder) checkPathForAddition(orig string) error {
686
+func (b *builder) checkPathForAddition(orig string) error {
687 687
 	origPath := filepath.Join(b.contextPath, orig)
688 688
 	origPath, err := filepath.EvalSymlinks(origPath)
689 689
 	if err != nil {
... ...
@@ -708,7 +708,7 @@ func (b *Builder) checkPathForAddition(orig string) error {
708 708
 	return nil
709 709
 }
710 710
 
711
-func (b *Builder) addContext(container *daemon.Container, orig, dest string, decompress bool) error {
711
+func (b *builder) addContext(container *daemon.Container, orig, dest string, decompress bool) error {
712 712
 	var (
713 713
 		err        error
714 714
 		destExists = true
... ...
@@ -791,7 +791,7 @@ func copyAsDirectory(source, destination string, destExisted bool) error {
791 791
 	return fixPermissions(source, destination, 0, 0, destExisted)
792 792
 }
793 793
 
794
-func (b *Builder) clearTmp() {
794
+func (b *builder) clearTmp() {
795 795
 	for c := range b.TmpContainers {
796 796
 		rmConfig := &daemon.ContainerRmConfig{
797 797
 			ForceRemove:  true,
... ...
@@ -44,6 +44,7 @@ var validCommitCommands = map[string]bool{
44 44
 	"workdir":    true,
45 45
 }
46 46
 
47
+// Config contains all configs for a build job
47 48
 type Config struct {
48 49
 	DockerfileName string
49 50
 	RemoteURL      string
... ...
@@ -55,11 +56,11 @@ type Config struct {
55 55
 	Pull           bool
56 56
 	Memory         int64
57 57
 	MemorySwap     int64
58
-	CpuShares      int64
59
-	CpuPeriod      int64
60
-	CpuQuota       int64
61
-	CpuSetCpus     string
62
-	CpuSetMems     string
58
+	CPUShares      int64
59
+	CPUPeriod      int64
60
+	CPUQuota       int64
61
+	CPUSetCpus     string
62
+	CPUSetMems     string
63 63
 	CgroupParent   string
64 64
 	AuthConfigs    map[string]cliconfig.AuthConfig
65 65
 
... ...
@@ -72,18 +73,20 @@ type Config struct {
72 72
 	cancelOnce sync.Once
73 73
 }
74 74
 
75
-// When called, causes the Job.WaitCancelled channel to unblock.
75
+// Cancel signals the build job to cancel
76 76
 func (b *Config) Cancel() {
77 77
 	b.cancelOnce.Do(func() {
78 78
 		close(b.cancelled)
79 79
 	})
80 80
 }
81 81
 
82
-// Returns a channel which is closed ("never blocks") when the job is cancelled.
82
+// WaitCancelled returns a channel which is closed ("never blocks") when
83
+// the job is cancelled.
83 84
 func (b *Config) WaitCancelled() <-chan struct{} {
84 85
 	return b.cancelled
85 86
 }
86 87
 
88
+// NewBuildConfig returns a new Config struct
87 89
 func NewBuildConfig() *Config {
88 90
 	return &Config{
89 91
 		AuthConfigs: map[string]cliconfig.AuthConfig{},
... ...
@@ -91,6 +94,8 @@ func NewBuildConfig() *Config {
91 91
 	}
92 92
 }
93 93
 
94
+// Build is the main interface of the package, it gathers the Builder
95
+// struct and calls builder.Run() to do all the real build job.
94 96
 func Build(d *daemon.Daemon, buildConfig *Config) error {
95 97
 	var (
96 98
 		repoName string
... ...
@@ -173,7 +178,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
173 173
 
174 174
 	defer context.Close()
175 175
 
176
-	builder := &Builder{
176
+	builder := &builder{
177 177
 		Daemon: d,
178 178
 		OutStream: &streamformatter.StdoutFormater{
179 179
 			Writer:          buildConfig.Stdout,
... ...
@@ -192,11 +197,11 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
192 192
 		StreamFormatter: sf,
193 193
 		AuthConfigs:     buildConfig.AuthConfigs,
194 194
 		dockerfileName:  buildConfig.DockerfileName,
195
-		cpuShares:       buildConfig.CpuShares,
196
-		cpuPeriod:       buildConfig.CpuPeriod,
197
-		cpuQuota:        buildConfig.CpuQuota,
198
-		cpuSetCpus:      buildConfig.CpuSetCpus,
199
-		cpuSetMems:      buildConfig.CpuSetMems,
195
+		cpuShares:       buildConfig.CPUShares,
196
+		cpuPeriod:       buildConfig.CPUPeriod,
197
+		cpuQuota:        buildConfig.CPUQuota,
198
+		cpuSetCpus:      buildConfig.CPUSetCpus,
199
+		cpuSetMems:      buildConfig.CPUSetMems,
200 200
 		cgroupParent:    buildConfig.CgroupParent,
201 201
 		memory:          buildConfig.Memory,
202 202
 		memorySwap:      buildConfig.MemorySwap,
... ...
@@ -218,6 +223,11 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
218 218
 	return nil
219 219
 }
220 220
 
221
+// BuildFromConfig will do build directly from parameter 'changes', which comes
222
+// from Dockerfile entries, it will:
223
+//
224
+// - call parse.Parse() to get AST root from Dockerfile entries
225
+// - do build by calling builder.dispatch() to call all entries' handling routines
221 226
 func BuildFromConfig(d *daemon.Daemon, c *runconfig.Config, changes []string) (*runconfig.Config, error) {
222 227
 	ast, err := parser.Parse(bytes.NewBufferString(strings.Join(changes, "\n")))
223 228
 	if err != nil {
... ...
@@ -231,7 +241,7 @@ func BuildFromConfig(d *daemon.Daemon, c *runconfig.Config, changes []string) (*
231 231
 		}
232 232
 	}
233 233
 
234
-	builder := &Builder{
234
+	builder := &builder{
235 235
 		Daemon:        d,
236 236
 		Config:        c,
237 237
 		OutStream:     ioutil.Discard,
... ...
@@ -248,7 +258,8 @@ func BuildFromConfig(d *daemon.Daemon, c *runconfig.Config, changes []string) (*
248 248
 	return builder.Config, nil
249 249
 }
250 250
 
251
-type BuilderCommitConfig struct {
251
+// CommitConfig contains build configs for commit operation
252
+type CommitConfig struct {
252 253
 	Pause   bool
253 254
 	Repo    string
254 255
 	Tag     string
... ...
@@ -258,7 +269,8 @@ type BuilderCommitConfig struct {
258 258
 	Config  *runconfig.Config
259 259
 }
260 260
 
261
-func Commit(name string, d *daemon.Daemon, c *BuilderCommitConfig) (string, error) {
261
+// Commit will create a new image from a container's changes
262
+func Commit(name string, d *daemon.Daemon, c *CommitConfig) (string, error) {
262 263
 	container, err := d.Get(name)
263 264
 	if err != nil {
264 265
 		return "", err
... ...
@@ -151,7 +151,7 @@ func parseNameVal(rest string, key string) (*Node, map[string]bool, error) {
151 151
 	if !strings.Contains(words[0], "=") {
152 152
 		node := &Node{}
153 153
 		rootnode = node
154
-		strs := TOKEN_WHITESPACE.Split(rest, 2)
154
+		strs := tokenWhitespace.Split(rest, 2)
155 155
 
156 156
 		if len(strs) < 2 {
157 157
 			return nil, nil, fmt.Errorf(key + " must have two arguments")
... ...
@@ -205,7 +205,7 @@ func parseStringsWhitespaceDelimited(rest string) (*Node, map[string]bool, error
205 205
 	node := &Node{}
206 206
 	rootnode := node
207 207
 	prevnode := node
208
-	for _, str := range TOKEN_WHITESPACE.Split(rest, -1) { // use regexp
208
+	for _, str := range tokenWhitespace.Split(rest, -1) { // use regexp
209 209
 		prevnode = node
210 210
 		node.Value = str
211 211
 		node.Next = &Node{}
... ...
@@ -232,13 +232,13 @@ func parseString(rest string) (*Node, map[string]bool, error) {
232 232
 
233 233
 // parseJSON converts JSON arrays to an AST.
234 234
 func parseJSON(rest string) (*Node, map[string]bool, error) {
235
-	var myJson []interface{}
236
-	if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJson); err != nil {
235
+	var myJSON []interface{}
236
+	if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil {
237 237
 		return nil, nil, err
238 238
 	}
239 239
 
240 240
 	var top, prev *Node
241
-	for _, str := range myJson {
241
+	for _, str := range myJSON {
242 242
 		s, ok := str.(string)
243 243
 		if !ok {
244 244
 			return nil, nil, errDockerfileNotStringArray
... ...
@@ -1,4 +1,4 @@
1
-// This package implements a parser and parse tree dumper for Dockerfiles.
1
+// Package parser implements a parser and parse tree dumper for Dockerfiles.
2 2
 package parser
3 3
 
4 4
 import (
... ...
@@ -33,10 +33,10 @@ type Node struct {
33 33
 }
34 34
 
35 35
 var (
36
-	dispatch                map[string]func(string) (*Node, map[string]bool, error)
37
-	TOKEN_WHITESPACE        = regexp.MustCompile(`[\t\v\f\r ]+`)
38
-	TOKEN_LINE_CONTINUATION = regexp.MustCompile(`\\[ \t]*$`)
39
-	TOKEN_COMMENT           = regexp.MustCompile(`^#.*$`)
36
+	dispatch              map[string]func(string) (*Node, map[string]bool, error)
37
+	tokenWhitespace       = regexp.MustCompile(`[\t\v\f\r ]+`)
38
+	tokenLineContinuation = regexp.MustCompile(`\\[ \t]*$`)
39
+	tokenComment          = regexp.MustCompile(`^#.*$`)
40 40
 )
41 41
 
42 42
 func init() {
... ...
@@ -70,8 +70,8 @@ func parseLine(line string) (string, *Node, error) {
70 70
 		return "", nil, nil
71 71
 	}
72 72
 
73
-	if TOKEN_LINE_CONTINUATION.MatchString(line) {
74
-		line = TOKEN_LINE_CONTINUATION.ReplaceAllString(line, "")
73
+	if tokenLineContinuation.MatchString(line) {
74
+		line = tokenLineContinuation.ReplaceAllString(line, "")
75 75
 		return line, nil, nil
76 76
 	}
77 77
 
... ...
@@ -96,8 +96,8 @@ func parseLine(line string) (string, *Node, error) {
96 96
 	return "", node, nil
97 97
 }
98 98
 
99
-// The main parse routine. Handles an io.ReadWriteCloser and returns the root
100
-// of the AST.
99
+// Parse is the main parse routine.
100
+// It handles an io.ReadWriteCloser and returns the root of the AST.
101 101
 func Parse(rwc io.Reader) (*Node, error) {
102 102
 	root := &Node{}
103 103
 	scanner := bufio.NewScanner(rwc)
... ...
@@ -7,8 +7,8 @@ import (
7 7
 	"unicode"
8 8
 )
9 9
 
10
-// dumps the AST defined by `node` as a list of sexps. Returns a string
11
-// suitable for printing.
10
+// Dump dumps the AST defined by `node` as a list of sexps.
11
+// Returns a string suitable for printing.
12 12
 func (node *Node) Dump() string {
13 13
 	str := ""
14 14
 	str += node.Value
... ...
@@ -59,7 +59,7 @@ func splitCommand(line string) (string, []string, string, error) {
59 59
 	var flags []string
60 60
 
61 61
 	// Make sure we get the same results irrespective of leading/trailing spaces
62
-	cmdline := TOKEN_WHITESPACE.Split(strings.TrimSpace(line), 2)
62
+	cmdline := tokenWhitespace.Split(strings.TrimSpace(line), 2)
63 63
 	cmd := strings.ToLower(cmdline[0])
64 64
 
65 65
 	if len(cmdline) == 2 {
... ...
@@ -77,8 +77,8 @@ func splitCommand(line string) (string, []string, string, error) {
77 77
 // this function.
78 78
 func stripComments(line string) string {
79 79
 	// string is already trimmed at this point
80
-	if TOKEN_COMMENT.MatchString(line) {
81
-		return TOKEN_COMMENT.ReplaceAllString(line, "")
80
+	if tokenComment.MatchString(line) {
81
+		return tokenComment.ReplaceAllString(line, "")
82 82
 	}
83 83
 
84 84
 	return line
... ...
@@ -18,6 +18,8 @@ type shellWord struct {
18 18
 	pos  int
19 19
 }
20 20
 
21
+// ProcessWord will use the 'env' list of environment variables,
22
+// and replace any env var references in 'word'.
21 23
 func ProcessWord(word string, env []string) (string, error) {
22 24
 	sw := &shellWord{
23 25
 		word: word,
... ...
@@ -13,7 +13,7 @@ func selectAcceptableMIME(ct string) string {
13 13
 	return mimeRe.FindString(ct)
14 14
 }
15 15
 
16
-func handleJsonArgs(args []string, attributes map[string]bool) []string {
16
+func handleJSONArgs(args []string, attributes map[string]bool) []string {
17 17
 	if len(args) == 0 {
18 18
 		return []string{}
19 19
 	}