lib/cide/docker.rb in cide-0.9.1 vs lib/cide/docker.rb in cide-0.9.2

- old
+ new

@@ -3,11 +3,11 @@ module CIDE # Simple docker client helper module Docker # Generates a valid id for docker from any string def self.id(str) - "#{str}".downcase.gsub(/[^a-z0-9\-_.]/, '_') + str.to_s.downcase.gsub(/[^a-z0-9\-_.]/, '_') end # Raised when a docker command exits with a status higher than zero class Error < StandardError attr_reader :exitstatus @@ -17,10 +17,19 @@ end end class VersionError < StandardError; end + def docker_image_ids(filter_by: false) + args = ['--no-trunc'] + args << ['--filter', filter_by] if filter_by + lines = docker('images', *args, capture: true).lines[1..-1] + lines + .map { |line| line.split(/\s+/) } + .map { |line| line[2] } + end + def docker(*args, verbose: false, capture: false) cmd = (['docker'] + args).map(&:to_s) p cmd if verbose if capture @@ -34,32 +43,9 @@ return 0 end ensure Process.wait(pid) exitstatus = $?.exitstatus - fail Error, exitstatus if exitstatus > 0 - end - - protected - - def setup_docker - @setup_docker ||= ( - # Check docker version - docker_version = nil - case `docker version 2>/dev/null` - when /Client version: ([^\s]+)/ - docker_version = $1 - when /\s+Version:\s+([^\s]+)/ - docker_version = $1 - else - fail VersionError, 'Unknown docker version' - end - - if Gem::Version.new(docker_version) < Gem::Version.new('1.5.0') - fail VersionError, "Docker version #{$1} too old" - end - - true - ) + raise Error, exitstatus if exitstatus > 0 end end end