Skip to content

Commit

Permalink
add namespace for image
Browse files Browse the repository at this point in the history
  • Loading branch information
tonicmuroq committed Sep 20, 2016
1 parent be555ce commit d7a1256
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ docker:
network_mode: "bridge" # 默认网络模式, 用 bridge
cert_path: "[cert_file_dir]" # docker tls 证书目录
hub: "hub.ricebook.net" # docker hub 地址
hub_prefix: "namespace/test" # 存放镜像的命名空间, 两边的/会被去掉, 中间的会保留. 镜像名字会是$hub/$hub_prefix/appname:version

scheduler:
lock_key: "_scheduler_lock" # scheduler 用的锁的 key, 会在 etcd_lock_prefix 里面
Expand All @@ -110,8 +111,3 @@ $ export ERU_CONFIG_PATH=/path/to/core.yaml
$ export ERU_LOG_LEVEL=DEBUG
$ core
```

## TODO

- [x] more complicated scheduler
- [x] networks, either use eru-agent or use docker plugin, the latter one is preferred
13 changes: 12 additions & 1 deletion cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
}

// tag of image, later this will be used to push image to hub
tag := fmt.Sprintf("%s/%s:%s", c.config.Docker.Hub, specs.Appname, utils.TruncateID(version))
tag := createImageTag(c.config, specs.Appname, utils.TruncateID(version))

// create tar stream for Build API
buildContext, err := createTarStream(buildDir)
Expand Down Expand Up @@ -295,3 +296,13 @@ func createDockerfile(buildDir, uid, reponame string, specs types.Specs) error {
}
return nil
}

// Image tag
// 格式严格按照 Hub/HubPrefix/appname:version 来
func createImageTag(config types.Config, appname, version string) string {
prefix := strings.Trim(config.Docker.HubPrefix, "/")
if prefix == "" {
return fmt.Sprintf("%s/%s:%s", config.Docker.Hub, appname, version)
}
return fmt.Sprintf("%s/%s/%s:%s", config.Docker.Hub, prefix, appname, version)
}
1 change: 1 addition & 0 deletions core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ docker:
network_mode: "bridge"
cert_path: ""
hub: "hub.ricebook.net"
hub_prefix: ""

scheduler:
lock_key: "_scheduler_lock"
Expand Down
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DockerConfig struct {
NetworkMode string `yaml:"network_mode"` // docker network mode
CertPath string `yaml:"cert_path"` // docker cert files path
Hub string `yaml:"hub"` // docker hub address
HubPrefix string `yaml:"hub_prefix"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
}

type SchedConfig struct {
Expand Down

0 comments on commit d7a1256

Please sign in to comment.