Skip to content

Commit

Permalink
在发现跨区域没办法pull之后只好在第一次部署的时候来cache了
Browse files Browse the repository at this point in the history
  • Loading branch information
tonicmuroq committed Mar 8, 2017
1 parent d6ff185 commit b96c738
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
19 changes: 2 additions & 17 deletions cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -192,15 +183,14 @@ 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)
if err != nil {
return ch, err
}

go func(cachedPod string) {
go func() {
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)
for {
Expand Down Expand Up @@ -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一样
// 一样就砍死
Expand All @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
// 其他都无情删掉
Expand Down
1 change: 0 additions & 1 deletion types/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down

0 comments on commit b96c738

Please sign in to comment.