Browse code

Remove chain of engine passing from builder to loadManifest

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/04/22 06:23:48
Showing 7 changed files
... ...
@@ -708,7 +708,7 @@ func (s *Server) postCommit(eng *engine.Engine, version version.Version, w http.
708 708
 		Config:  c,
709 709
 	}
710 710
 
711
-	imgID, err := builder.Commit(s.daemon, eng, cont, containerCommitConfig)
711
+	imgID, err := builder.Commit(s.daemon, cont, containerCommitConfig)
712 712
 	if err != nil {
713 713
 		return err
714 714
 	}
... ...
@@ -764,7 +764,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
764 764
 			imagePullConfig.Json = false
765 765
 		}
766 766
 
767
-		if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig, eng); err != nil {
767
+		if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig); err != nil {
768 768
 			return err
769 769
 		}
770 770
 	} else { //import
... ...
@@ -785,7 +785,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
785 785
 			imageImportConfig.Json = false
786 786
 		}
787 787
 
788
-		newConfig, err := builder.BuildFromConfig(s.daemon, eng, &runconfig.Config{}, imageImportConfig.Changes)
788
+		newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
789 789
 		if err != nil {
790 790
 			return err
791 791
 		}
... ...
@@ -1327,7 +1327,7 @@ func (s *Server) postBuild(eng *engine.Engine, version version.Version, w http.R
1327 1327
 		}()
1328 1328
 	}
1329 1329
 
1330
-	if err := builder.Build(s.daemon, eng, buildConfig); err != nil {
1330
+	if err := builder.Build(s.daemon, buildConfig); err != nil {
1331 1331
 		// Do not write the error in the http output if it's still empty.
1332 1332
 		// This prevents from writing a 200(OK) when there is an interal error.
1333 1333
 		if !output.Flushed() {
... ...
@@ -31,7 +31,6 @@ import (
31 31
 	"github.com/docker/docker/builder/command"
32 32
 	"github.com/docker/docker/builder/parser"
33 33
 	"github.com/docker/docker/daemon"
34
-	"github.com/docker/docker/engine"
35 34
 	"github.com/docker/docker/pkg/fileutils"
36 35
 	"github.com/docker/docker/pkg/streamformatter"
37 36
 	"github.com/docker/docker/pkg/stringid"
... ...
@@ -80,7 +79,6 @@ func init() {
80 80
 // processing as it evaluates the parsing result.
81 81
 type Builder struct {
82 82
 	Daemon *daemon.Daemon
83
-	Engine *engine.Engine
84 83
 
85 84
 	// effectively stdio for the run. Because it is not stdio, I said
86 85
 	// "Effectively". Do not use stdio anywhere in this package for any reason.
... ...
@@ -454,7 +454,7 @@ func (b *Builder) pullImage(name string) (*imagepkg.Image, error) {
454 454
 		Json:       b.StreamFormatter.Json(),
455 455
 	}
456 456
 
457
-	if err := b.Daemon.Repositories().Pull(remote, tag, imagePullConfig, b.Engine); err != nil {
457
+	if err := b.Daemon.Repositories().Pull(remote, tag, imagePullConfig); err != nil {
458 458
 		return nil, err
459 459
 	}
460 460
 
... ...
@@ -13,7 +13,6 @@ import (
13 13
 	"github.com/docker/docker/api"
14 14
 	"github.com/docker/docker/builder/parser"
15 15
 	"github.com/docker/docker/daemon"
16
-	"github.com/docker/docker/engine"
17 16
 	"github.com/docker/docker/graph"
18 17
 	"github.com/docker/docker/pkg/archive"
19 18
 	"github.com/docker/docker/pkg/httputils"
... ...
@@ -83,7 +82,7 @@ func NewBuildConfig() *Config {
83 83
 	}
84 84
 }
85 85
 
86
-func Build(d *daemon.Daemon, e *engine.Engine, buildConfig *Config) error {
86
+func Build(d *daemon.Daemon, buildConfig *Config) error {
87 87
 	var (
88 88
 		repoName string
89 89
 		tag      string
... ...
@@ -150,7 +149,6 @@ func Build(d *daemon.Daemon, e *engine.Engine, buildConfig *Config) error {
150 150
 
151 151
 	builder := &Builder{
152 152
 		Daemon: d,
153
-		Engine: e,
154 153
 		OutStream: &streamformatter.StdoutFormater{
155 154
 			Writer:          buildConfig.Stdout,
156 155
 			StreamFormatter: sf,
... ...
@@ -188,7 +186,7 @@ func Build(d *daemon.Daemon, e *engine.Engine, buildConfig *Config) error {
188 188
 	return nil
189 189
 }
190 190
 
191
-func BuildFromConfig(d *daemon.Daemon, e *engine.Engine, c *runconfig.Config, changes []string) (*runconfig.Config, error) {
191
+func BuildFromConfig(d *daemon.Daemon, c *runconfig.Config, changes []string) (*runconfig.Config, error) {
192 192
 	ast, err := parser.Parse(bytes.NewBufferString(strings.Join(changes, "\n")))
193 193
 	if err != nil {
194 194
 		return nil, err
... ...
@@ -203,7 +201,6 @@ func BuildFromConfig(d *daemon.Daemon, e *engine.Engine, c *runconfig.Config, ch
203 203
 
204 204
 	builder := &Builder{
205 205
 		Daemon:        d,
206
-		Engine:        e,
207 206
 		Config:        c,
208 207
 		OutStream:     ioutil.Discard,
209 208
 		ErrStream:     ioutil.Discard,
... ...
@@ -219,13 +216,13 @@ func BuildFromConfig(d *daemon.Daemon, e *engine.Engine, c *runconfig.Config, ch
219 219
 	return builder.Config, nil
220 220
 }
221 221
 
222
-func Commit(d *daemon.Daemon, eng *engine.Engine, name string, c *daemon.ContainerCommitConfig) (string, error) {
222
+func Commit(d *daemon.Daemon, name string, c *daemon.ContainerCommitConfig) (string, error) {
223 223
 	container, err := d.Get(name)
224 224
 	if err != nil {
225 225
 		return "", err
226 226
 	}
227 227
 
228
-	newConfig, err := BuildFromConfig(d, eng, c.Config, c.Changes)
228
+	newConfig, err := BuildFromConfig(d, c.Config, c.Changes)
229 229
 	if err != nil {
230 230
 		return "", err
231 231
 	}
... ...
@@ -6,7 +6,6 @@ import (
6 6
 
7 7
 	"github.com/Sirupsen/logrus"
8 8
 	"github.com/docker/distribution/digest"
9
-	"github.com/docker/docker/engine"
10 9
 	"github.com/docker/docker/registry"
11 10
 	"github.com/docker/docker/trust"
12 11
 	"github.com/docker/docker/utils"
... ...
@@ -18,7 +17,7 @@ import (
18 18
 // contains no signatures by a trusted key for the name in the manifest, the
19 19
 // image is not considered verified. The parsed manifest object and a boolean
20 20
 // for whether the manifest is verified is returned.
21
-func (s *TagStore) loadManifest(eng *engine.Engine, manifestBytes []byte, dgst, ref string) (*registry.ManifestData, bool, error) {
21
+func (s *TagStore) loadManifest(manifestBytes []byte, dgst, ref string) (*registry.ManifestData, bool, error) {
22 22
 	sig, err := libtrust.ParsePrettySignature(manifestBytes, "signatures")
23 23
 	if err != nil {
24 24
 		return nil, false, fmt.Errorf("error parsing payload: %s", err)
... ...
@@ -12,7 +12,6 @@ import (
12 12
 
13 13
 	"github.com/Sirupsen/logrus"
14 14
 	"github.com/docker/distribution/digest"
15
-	"github.com/docker/docker/engine"
16 15
 	"github.com/docker/docker/image"
17 16
 	"github.com/docker/docker/pkg/progressreader"
18 17
 	"github.com/docker/docker/pkg/streamformatter"
... ...
@@ -29,7 +28,7 @@ type ImagePullConfig struct {
29 29
 	OutStream   io.Writer
30 30
 }
31 31
 
32
-func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConfig, eng *engine.Engine) error {
32
+func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConfig) error {
33 33
 	var (
34 34
 		sf = streamformatter.NewStreamFormatter(imagePullConfig.Json)
35 35
 	)
... ...
@@ -74,7 +73,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
74 74
 		}
75 75
 
76 76
 		logrus.Debugf("pulling v2 repository with local name %q", repoInfo.LocalName)
77
-		if err := s.pullV2Repository(eng, r, imagePullConfig.OutStream, repoInfo, tag, sf, imagePullConfig.Parallel); err == nil {
77
+		if err := s.pullV2Repository(r, imagePullConfig.OutStream, repoInfo, tag, sf, imagePullConfig.Parallel); err == nil {
78 78
 			s.eventsService.Log("pull", logName, "")
79 79
 			return nil
80 80
 		} else if err != registry.ErrDoesNotExist && err != ErrV2RegistryUnavailable {
... ...
@@ -369,7 +368,7 @@ type downloadInfo struct {
369 369
 	err        chan error
370 370
 }
371 371
 
372
-func (s *TagStore) pullV2Repository(eng *engine.Engine, r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool) error {
372
+func (s *TagStore) pullV2Repository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool) error {
373 373
 	endpoint, err := r.V2RegistryEndpoint(repoInfo.Index)
374 374
 	if err != nil {
375 375
 		if repoInfo.Index.Official {
... ...
@@ -393,14 +392,14 @@ func (s *TagStore) pullV2Repository(eng *engine.Engine, r *registry.Session, out
393 393
 			return registry.ErrDoesNotExist
394 394
 		}
395 395
 		for _, t := range tags {
396
-			if downloaded, err := s.pullV2Tag(eng, r, out, endpoint, repoInfo, t, sf, parallel, auth); err != nil {
396
+			if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, t, sf, parallel, auth); err != nil {
397 397
 				return err
398 398
 			} else if downloaded {
399 399
 				layersDownloaded = true
400 400
 			}
401 401
 		}
402 402
 	} else {
403
-		if downloaded, err := s.pullV2Tag(eng, r, out, endpoint, repoInfo, tag, sf, parallel, auth); err != nil {
403
+		if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, tag, sf, parallel, auth); err != nil {
404 404
 			return err
405 405
 		} else if downloaded {
406 406
 			layersDownloaded = true
... ...
@@ -415,7 +414,7 @@ func (s *TagStore) pullV2Repository(eng *engine.Engine, r *registry.Session, out
415 415
 	return nil
416 416
 }
417 417
 
418
-func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Writer, endpoint *registry.Endpoint, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool, auth *registry.RequestAuthorization) (bool, error) {
418
+func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *registry.Endpoint, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool, auth *registry.RequestAuthorization) (bool, error) {
419 419
 	logrus.Debugf("Pulling tag from V2 registry: %q", tag)
420 420
 
421 421
 	manifestBytes, manifestDigest, err := r.GetV2ImageManifest(endpoint, repoInfo.RemoteName, tag, auth)
... ...
@@ -425,7 +424,7 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
425 425
 
426 426
 	// loadManifest ensures that the manifest payload has the expected digest
427 427
 	// if the tag is a digest reference.
428
-	manifest, verified, err := s.loadManifest(eng, manifestBytes, manifestDigest, tag)
428
+	manifest, verified, err := s.loadManifest(manifestBytes, manifestDigest, tag)
429 429
 	if err != nil {
430 430
 		return false, fmt.Errorf("error verifying manifest: %s", err)
431 431
 	}
... ...
@@ -138,7 +138,7 @@ func setupBaseImage() {
138 138
 			AuthConfig: &registry.AuthConfig{},
139 139
 		}
140 140
 		d := getDaemon(eng)
141
-		if err := d.Repositories().Pull(unitTestImageName, "", imagePullConfig, eng); err != nil {
141
+		if err := d.Repositories().Pull(unitTestImageName, "", imagePullConfig); err != nil {
142 142
 			logrus.Fatalf("Unable to pull the test image: %s", err)
143 143
 		}
144 144
 	}