Skip to content

Commit d7a1256

Browse files
committed
add namespace for image
1 parent be555ce commit d7a1256

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ docker:
9090
network_mode: "bridge" # 默认网络模式, 用 bridge
9191
cert_path: "[cert_file_dir]" # docker tls 证书目录
9292
hub: "hub.ricebook.net" # docker hub 地址
93+
hub_prefix: "namespace/test" # 存放镜像的命名空间, 两边的/会被去掉, 中间的会保留. 镜像名字会是$hub/$hub_prefix/appname:version
9394

9495
scheduler:
9596
lock_key: "_scheduler_lock" # scheduler 用的锁的 key, 会在 etcd_lock_prefix 里面
@@ -110,8 +111,3 @@ $ export ERU_CONFIG_PATH=/path/to/core.yaml
110111
$ export ERU_LOG_LEVEL=DEBUG
111112
$ core
112113
```
113-
114-
## TODO
115-
116-
- [x] more complicated scheduler
117-
- [x] networks, either use eru-agent or use docker plugin, the latter one is preferred

cluster/calcium/build_image.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"os"
99
"path/filepath"
10+
"strings"
1011
"text/template"
1112

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

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

155156
// create tar stream for Build API
156157
buildContext, err := createTarStream(buildDir)
@@ -295,3 +296,13 @@ func createDockerfile(buildDir, uid, reponame string, specs types.Specs) error {
295296
}
296297
return nil
297298
}
299+
300+
// Image tag
301+
// 格式严格按照 Hub/HubPrefix/appname:version 来
302+
func createImageTag(config types.Config, appname, version string) string {
303+
prefix := strings.Trim(config.Docker.HubPrefix, "/")
304+
if prefix == "" {
305+
return fmt.Sprintf("%s/%s:%s", config.Docker.Hub, appname, version)
306+
}
307+
return fmt.Sprintf("%s/%s/%s:%s", config.Docker.Hub, prefix, appname, version)
308+
}

core.yaml.sample

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ docker:
1717
network_mode: "bridge"
1818
cert_path: ""
1919
hub: "hub.ricebook.net"
20+
hub_prefix: ""
2021

2122
scheduler:
2223
lock_key: "_scheduler_lock"

types/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type DockerConfig struct {
2525
NetworkMode string `yaml:"network_mode"` // docker network mode
2626
CertPath string `yaml:"cert_path"` // docker cert files path
2727
Hub string `yaml:"hub"` // docker hub address
28+
HubPrefix string `yaml:"hub_prefix"` // docker hub prefix, will be set to $Hub/$HubPrefix/$appname
2829
}
2930

3031
type SchedConfig struct {

0 commit comments

Comments
 (0)