lib/spoon.rb in docker-spoon-0.3.0 vs lib/spoon.rb in docker-spoon-0.4.0

- old
+ new

@@ -9,11 +9,11 @@ include Methadone::CLILogging include Methadone::SH version(Spoon::VERSION) main do |instance| - parse_config(options[:config]) + D options.inspect if options[:list] instance_list elsif options["list-images"] image_list @@ -53,28 +53,23 @@ options[:command] = '' options[:config] = "#{ENV['HOME']}/.spoonrc" on("-c", "--config FILE", "Config file to use for spoon options") on("--debug", "Enable debug") + # Read config file & set options + eval(File.open(options[:config]).read) + arg(:instance, :optional, "Spoon instance to connect to") use_log_level_option - def self.parse_config(config_file) - eval(File.open(config_file).read) - end - def self.apply_prefix(name) - "spoon-#{name}" + "#{options[:prefix]}#{name}" end def self.remove_prefix(name) - if name.start_with? "/" - name[7..-1] - else - name[6..-1] - end + name.gsub(/\/?#{options[:prefix]}/, '') end def self.image_build # Run pre-build commands options["pre-build-commands"].each do |command| @@ -82,11 +77,13 @@ end unless options["pre-build-commands"].nil? D "pre-build commands complete, building Docker image" docker_url build_opts = { 't' => options[:image], 'rm' => true } - Docker::Image.build_from_dir(options[:builddir], build_opts) do |chunk| + docker_connection = ::Docker::Connection.new(options[:url], :read_timeout => 3000) + + Docker::Image.build_from_dir(options[:builddir], build_opts, docker_connection) do |chunk| print_docker_response(chunk) end end def self.image_list @@ -136,17 +133,22 @@ end def self.instance_list docker_url puts "List of available spoon containers:" - container_list = get_all_containers + container_list = get_all_containers.sort { |c1, c2| c1.info["Names"].first.to_s <=> c2.info["Names"].first.to_s } container_list.each do |container| name = container.info["Names"].first.to_s if name.start_with? "/#{options[:prefix]}" running = is_running?(container) ? Rainbow("Running").green : Rainbow("Stopped").red - puts "#{remove_prefix(name)} [ #{running} ]".rjust(40) + puts "#{remove_prefix(name)} [ #{running} ]".rjust(40) + " " + Rainbow(image_name(container)).yellow end end + end + + def self.image_name(container) + env = Hash[container.json['Config']['Env'].collect { |v| v.split('=') }] + return env['IMAGE_NAME'] || container.json['Config']['Image'].split(':').first end def self.strip_slash(name) if name.start_with? "/" name[1..-1]