Browse code

add some optimizations to build code

guangxuli authored on 2016/10/11 11:27:24
Showing 4 changed files
... ...
@@ -56,7 +56,8 @@ func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterf
56 56
 
57 57
 // Build executes a Docker build
58 58
 func (d *DockerBuilder) Build() error {
59
-	if d.build.Spec.Source.Git == nil && d.build.Spec.Source.Binary == nil && d.build.Spec.Source.Dockerfile == nil && d.build.Spec.Source.Images == nil {
59
+	if d.build.Spec.Source.Git == nil && d.build.Spec.Source.Binary == nil &&
60
+		d.build.Spec.Source.Dockerfile == nil && d.build.Spec.Source.Images == nil {
60 61
 		return fmt.Errorf("must provide a value for at least one of source, binary, images, or dockerfile")
61 62
 	}
62 63
 	var push bool
... ...
@@ -164,7 +164,7 @@ func dockerRun(client DockerClient, createOpts docker.CreateContainerOptions, lo
164 164
 		return fmt.Errorf("create container %q: %v", createOpts.Name, err)
165 165
 	}
166 166
 
167
-	containerName := containerNameOrID(c)
167
+	containerName := getContainerNameOrID(c)
168 168
 
169 169
 	removeContainer := func() {
170 170
 		glog.V(4).Infof("Removing container %q ...", containerName)
... ...
@@ -204,7 +204,7 @@ func dockerRun(client DockerClient, createOpts docker.CreateContainerOptions, lo
204 204
 	return interrupt.New(nil, removeContainer).Run(startWaitContainer)
205 205
 }
206 206
 
207
-func containerNameOrID(c *docker.Container) string {
207
+func getContainerNameOrID(c *docker.Container) string {
208 208
 	if c.Name != "" {
209 209
 		return c.Name
210 210
 	}
... ...
@@ -335,7 +335,7 @@ func extractSourceFromImage(dockerClient DockerClient, image, buildDir string, i
335 335
 	exists := true
336 336
 	if !forcePull {
337 337
 		_, err := dockerClient.InspectImage(image)
338
-		if err != nil && err == docker.ErrNoSuchImage {
338
+		if err == docker.ErrNoSuchImage {
339 339
 			exists = false
340 340
 		} else if err != nil {
341 341
 			return err
... ...
@@ -93,8 +93,6 @@ func (s *S2IBuilder) Build() error {
93 93
 		return errors.New("the source to image builder must be used with the source strategy")
94 94
 	}
95 95
 
96
-	var push bool
97
-
98 96
 	contextDir := filepath.Clean(s.build.Spec.Source.ContextDir)
99 97
 	if contextDir == "." || contextDir == "/" {
100 98
 		contextDir = ""
... ...
@@ -121,6 +119,8 @@ func (s *S2IBuilder) Build() error {
121 121
 		contextDir: contextDir,
122 122
 		tmpDir:     tmpDir,
123 123
 	}
124
+
125
+	var push bool
124 126
 	// if there is no output target, set one up so the docker build logic
125 127
 	// (which requires a tag) will still work, but we won't push it at the end.
126 128
 	if s.build.Spec.Output.To == nil || len(s.build.Spec.Output.To.Name) == 0 {