Browse code

refactor function parameters

run gofmt

guangxuli authored on 2016/08/09 12:15:01
Showing 2 changed files
... ...
@@ -296,7 +296,27 @@ func (d *DockerBuilder) dockerBuild(dir string, tag string, secrets []api.Secret
296 296
 	if err := d.copySecrets(secrets, dir); err != nil {
297 297
 		return err
298 298
 	}
299
-	return buildImage(d.dockerClient, dir, dockerfilePath, noCache, tag, d.tar, auth, forcePull, d.cgLimits)
299
+
300
+	opts := docker.BuildImageOptions{
301
+		Name:           tag,
302
+		RmTmpContainer: true,
303
+		OutputStream:   os.Stdout,
304
+		Dockerfile:     dockerfilePath,
305
+		NoCache:        noCache,
306
+		Pull:           forcePull,
307
+	}
308
+	if d.cgLimits != nil {
309
+		opts.Memory = d.cgLimits.MemoryLimitBytes
310
+		opts.Memswap = d.cgLimits.MemorySwap
311
+		opts.CPUShares = d.cgLimits.CPUShares
312
+		opts.CPUPeriod = d.cgLimits.CPUPeriod
313
+		opts.CPUQuota = d.cgLimits.CPUQuota
314
+	}
315
+	if auth != nil {
316
+		opts.AuthConfigs = *auth
317
+	}
318
+
319
+	return buildImage(d.dockerClient, dir, d.tar, &opts)
300 320
 }
301 321
 
302 322
 // replaceLastFrom changes the last FROM instruction of node to point to the
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"k8s.io/kubernetes/pkg/util/interrupt"
13 13
 	utilruntime "k8s.io/kubernetes/pkg/util/runtime"
14 14
 
15
-	s2iapi "github.com/openshift/source-to-image/pkg/api"
16 15
 	"github.com/openshift/source-to-image/pkg/tar"
17 16
 
18 17
 	"github.com/openshift/imagebuilder/imageprogress"
... ...
@@ -101,8 +100,11 @@ func removeImage(client DockerClient, name string) error {
101 101
 }
102 102
 
103 103
 // buildImage invokes a docker build on a particular directory
104
-func buildImage(client DockerClient, dir string, dockerfilePath string, noCache bool, tag string, tar tar.Tar, pullAuth *docker.AuthConfigurations, forcePull bool, cgLimits *s2iapi.CGroupLimits) error {
104
+func buildImage(client DockerClient, dir string, tar tar.Tar, opts *docker.BuildImageOptions) error {
105 105
 	// TODO: be able to pass a stream directly to the Docker build to avoid the double temp hit
106
+	if opts == nil {
107
+		return fmt.Errorf("%s", "build image options nil")
108
+	}
106 109
 	r, w := io.Pipe()
107 110
 	go func() {
108 111
 		defer utilruntime.HandleCrash()
... ...
@@ -112,27 +114,9 @@ func buildImage(client DockerClient, dir string, dockerfilePath string, noCache
112 112
 		}
113 113
 	}()
114 114
 	defer w.Close()
115
-	glog.V(5).Infof("Invoking Docker build to create %q", tag)
116
-	opts := docker.BuildImageOptions{
117
-		Name:           tag,
118
-		RmTmpContainer: true,
119
-		OutputStream:   os.Stdout,
120
-		InputStream:    r,
121
-		Dockerfile:     dockerfilePath,
122
-		NoCache:        noCache,
123
-		Pull:           forcePull,
124
-	}
125
-	if cgLimits != nil {
126
-		opts.Memory = cgLimits.MemoryLimitBytes
127
-		opts.Memswap = cgLimits.MemorySwap
128
-		opts.CPUShares = cgLimits.CPUShares
129
-		opts.CPUPeriod = cgLimits.CPUPeriod
130
-		opts.CPUQuota = cgLimits.CPUQuota
131
-	}
132
-	if pullAuth != nil {
133
-		opts.AuthConfigs = *pullAuth
134
-	}
135
-	return client.BuildImage(opts)
115
+	opts.InputStream = r
116
+	glog.V(5).Infof("Invoking Docker build to create %q", opts.Name)
117
+	return client.BuildImage(*opts)
136 118
 }
137 119
 
138 120
 // tagImage uses the dockerClient to tag a Docker image with name. It is a