module ImageTasks
Public Instance Methods
build()
click to toggle source
# File lib/concerns/image_tasks.rb, line 179 def build dir = options['dir'] invoke(:init) if file_not_exist?("#{dir}/#{DOCKER_CONFIG_FILE}") load_config(dir) do |config| Image.build(DOCKER_FILE, *config[:repository_urls].map { |url| "#{url}/#{config[:image_name]}" }.unshift(config[:image_name])) end end
ls(keyword = nil)
click to toggle source
# File lib/concerns/image_tasks.rb, line 18 def ls(keyword = nil) ret = Image.find(keyword: keyword, name: options['name'], tag: options['tag']) Image.print_table(ret) # print_table([ret.unshift(Image.headers)]) end
pull(name)
click to toggle source
# File lib/concerns/image_tasks.rb, line 56 def pull(name) Image.pull(name) if options['local'] options['local'].each do |new_name| Image.tag(name, new_name) end end end
push(keyword = nil)
click to toggle source
# File lib/concerns/image_tasks.rb, line 76 def push(keyword = nil) ret = Image.find(keyword: keyword, name: options['name'], tag: options['tag']) Image.print_table(ret) say('The listed images will be pushed, ARE YOU SURE?'.blue) answer = ask('(y=YES;q=QUIT;i=ASK one by one)', limited_to: %w[y q i]) return if answer == 'q' ret.each do |image| if answer == 'i' say(image.to_s) each_answer = ask('going to push? (y=YES,n=NO,c=YES and change repository name,q=QUIT):') next if each_answer == 'n' break if each_answer == 'q' if each_answer == 'c' new_rep = ask_with_default('New repository?', image.image_name) Image.tag(image.image_name, new_rep) image.repository, image.tag = new_rep.split(':') end end image.push end end
release()
click to toggle source
# File lib/concerns/image_tasks.rb, line 195 def release dir = options['dir'] invoke(:init) if file_not_exist?("#{dir}/#{DOCKER_CONFIG_FILE}") load_config(dir) do |config| config[:repository_urls].map { |url| "#{url}/#{config[:image_name]}" }.each do |image_name| Image.push(image_name) end end end
rmi(keyword = nil)
click to toggle source
# File lib/concerns/image_tasks.rb, line 35 def rmi(keyword = nil) ret = Image.find(keyword: keyword, name: options['name'], tag: options['tag']) Image.print_table(ret) say('The listed images will be deleted, ARE YOU SURE?'.blue) answer = ask('(y=YES;q=QUIT;i=ASK one by one)', limited_to: %w[y q i]) return if answer == 'q' ret.each do |image| if answer == 'i' say(image.to_s) each_answer = ask('going to delete? (y=YES,n=NO,q=QUIT):') next if each_answer == 'n' break if each_answer == 'q' end image.del end end
tag(name)
click to toggle source
# File lib/concerns/image_tasks.rb, line 106 def tag(name) image = search_with_ask(name, Image, 'which image you want to tag?') say(image.to_s) option ||= {} new_image_name = option['as'] || ask('new image name?') Image.tag(image.image_name, new_image_name) end
xrun(keyword = nil)
click to toggle source
# File lib/concerns/image_tasks.rb, line 147 def xrun(keyword = nil) ret = Image.find(keyword: keyword, name: options['name'], tag: options['tag']) if ret.count==0 repository,tag=keyword.split(":") ret=[Image.new(repository:repository,tag:tag)] end if ret.count > 1 Image.print_table(ret) { |item, index| "[#{index + 1}]#{item}" } question = ['please select one image to run:'].unshift(' ').unshift(' ').join("\n") say(question.blue) answer = ask('(q=QUIT;n=)', limited_to: ['q', *('1'..ret.count.to_s).to_a]) return if answer == 'q' end command = options['cmd'] || ask_with_default('Any command you want to run?', '') opts = options['opts'] || ask_with_default('Any option you want to set?', '-d') index=(answer&.to_i||1)-1 xcommand=ret[index].launch(opts, command) run(["dk","alias",options['alias'],xcommand].join(" ")) if options['alias'] run(xcommand.join(" ")) end