diff --git a/cluster/calcium/build_image.go b/cluster/calcium/build_image.go index fd387ea6a..9d3c94322 100644 --- a/cluster/calcium/build_image.go +++ b/cluster/calcium/build_image.go @@ -175,15 +175,6 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t return ch, err } - labels := make(map[string]string) - if specs.Cache != "" { - labels["cached"] = "true" - labels["cached.pod"] = specs.Cache - } else { - labels["cached"] = "false" - labels["cached.pod"] = "" - } - // must be put here because of that `defer os.RemoveAll(buildDir)` buildOptions := enginetypes.ImageBuildOptions{ Tags: []string{tag}, @@ -192,7 +183,6 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t Remove: true, ForceRemove: true, PullParent: true, - Labels: labels, } log.Infof("Building image %v with artifact %v at %v:%v", tag, artifact, buildPodname, node.Name) resp, err := node.Engine.ImageBuild(context.Background(), buildContext, buildOptions) @@ -200,7 +190,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t return ch, err } - go func(cachedPod string) { + go func() { defer resp.Body.Close() decoder := json.NewDecoder(resp.Body) for { @@ -242,11 +232,6 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t ch <- message } - // 如果有需要cache住 - if cachedPod != "" { - go c.cacheImage(cachedPod, tag) - } - // 无论如何都删掉build机器的 // 事实上他不会跟cached pod一样 // 一样就砍死 @@ -257,7 +242,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t ch <- &types.BuildImageMessage{Status: "finished", Progress: tag} close(ch) - }(specs.Cache) + }() return ch, nil } diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 119869669..cd13f6f51 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -66,6 +66,9 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De }(nodename, num, opts) } wg.Wait() + + // 第一次部署的时候就去cache下镜像吧 + go c.cacheImage(opts.Podname, opts.Image) close(ch) }(specs, plan, opts) diff --git a/cluster/calcium/image.go b/cluster/calcium/image.go index 7d06ca107..87ba6a90d 100644 --- a/cluster/calcium/image.go +++ b/cluster/calcium/image.go @@ -89,8 +89,8 @@ func cleanImageOnNode(node *types.Node, image string) error { sort.Sort(toDelete) for index, img := range toDelete { - // 如果是最新的两个(index是0或者1), 并且标记了要cache, 就忽略 - if index <= 1 && img.Labels["cached"] == "true" { + // 如果是最新的两个(index是0或者1), 就忽略 + if index <= 1 { continue } // 其他都无情删掉 diff --git a/types/specs.go b/types/specs.go index a22bcbb1d..fc444c194 100644 --- a/types/specs.go +++ b/types/specs.go @@ -16,7 +16,6 @@ type Specs struct { Binds map[string]Bind `yaml:"binds,omitempty,flow"` Meta map[string]string `yaml:"meta,omitempty,flow"` Base string `yaml:"base"` - Cache string `yaml:"cache"` MountPaths []string `yaml:"mount_paths,omitempty,flow"` DNS []string `yaml:"dns,omitempty,flow"` }