add DOCKER_REGISTRY_HOST, DOCKER_REGISTRY_PORT field into /etc/compass-ci/defaults/*.yaml, or $HOME/.config/compass-ci/defaults/*.yaml
also, if failed from local registry, will pull from docker hub
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com --- providers/docker/docker.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/providers/docker/docker.rb b/providers/docker/docker.rb index c75fc2c..eea0336 100755 --- a/providers/docker/docker.rb +++ b/providers/docker/docker.rb @@ -11,14 +11,17 @@ require_relative '../../container/defconfig'
BASE_DIR = '/srv/dc'
+names = Set.new %w[ + SCHED_HOST + SCHED_PORT + DOCKER_REGISTRY_HOST + DOCKER_REGISTRY_PORT +] +DEFAULTS = relevant_defaults(names) + def get_url(hostname) - names = Set.new %w[ - SCHED_HOST - SCHED_PORT - ] - defaults = relevant_defaults(names) - host = defaults['SCHED_HOST'] || '172.17.0.1' - port = defaults['SCHED_PORT'] || 3000 + host = DEFAULTS['SCHED_HOST'] || '172.17.0.1' + port = DEFAULTS['SCHED_PORT'] || 3000 "http://#%7Bhost%7D:#%7Bport%7D/boot.container/hostname/#%7Bhostname%7D" end
@@ -59,7 +62,7 @@ def clean_dir(path) end
def load_initrds(load_path, hash) - clean_dir(load_path) if Dir.exist?(load_path) + clean_dir(load_path) unless Dir.empty?(load_path) arch = RUBY_PLATFORM.split('-')[0] job_url = hash['job'] lkp_url = hash['lkp'] @@ -67,9 +70,18 @@ def load_initrds(load_path, hash) wget_cmd(load_path, lkp_url, "lkp-#{arch}.cgz") end
+def pull(image_name) + host = DEFAULTS['DOCKER_REGISTRY_HOST'] || '172.17.0.1' + port = DEFAULTS['DOCKER_REGISTRY_PORT'] || '5001' + flag = system "docker pull #{host}:#{port}/#{image_name}" + unless flag + system "docker pull #{image_name}" + end +end + def run(hostname, load_path, hash) docker_image = hash['docker_image'] - system "docker pull #{docker_image}" + pull docker_image system( { 'hostname' => hostname, 'docker_image' => docker_image, 'load_path' => load_path }, ENV['CCI_SRC'] + '/providers/docker/run.sh'