lib/spoon.rb in docker-spoon-0.0.1 vs lib/spoon.rb in docker-spoon-0.1.0
- old
+ new
@@ -10,15 +10,15 @@
include Methadone::SH
version(Spoon::VERSION)
main do |instance|
parse_config(options[:config])
- pp options
+ D options.inspect
if options[:list]
instance_list
- elsif options["list-containers"]
- # container_list
+ elsif options["list-images"]
+ image_list
elsif options[:build]
image_build
elsif options[:destroy]
instance_destroy(apply_prefix(options[:destroy]))
elsif instance
@@ -35,14 +35,16 @@
on("-l", "--list", "List available spoon instances")
on("-d", "--destroy NAME", "Destroy spoon instance with NAME")
on("-b", "--build", "Build image from Dockerfile using name passed to --image")
# Configurables
- on("--builddir", "Directory containing Dockerfile")
+ options[:builddir] = '.'
+ on("--builddir DIR", "Directory containing Dockerfile")
on("--pre-build-commands", "List of commands to run locally before building image")
+ options[:url] = Docker.url
on("-u", "--url URL", "Docker url to connect to")
- on("-L", "--list-containers", "List available spoon container images")
+ on("-L", "--list-images", "List available spoon images")
options[:image] = "spoon-pairing"
on("-i", "--image NAME", "Use image for spoon instance")
options[:prefix] = 'spoon-'
on("-p", "--prefix PREFIX", "Prefix for container names")
options[:command] = ''
@@ -75,16 +77,25 @@
options["pre-build-commands"].each do |command|
sh command
end
D "pre-build commands complete, building Docker image"
+ docker_url
build_opts = { 't' => options[:image], 'rm' => true }
- Docker::Image.build_from_dir(options[:build], build_opts) do |chunk|
+ Docker::Image.build_from_dir(options[:builddir], build_opts) do |chunk|
print_docker_response(chunk)
end
end
+ def self.image_list
+ docker_url
+ Docker::Image.all.each do |image|
+ next if image.info["RepoTags"] == ["<none>:<none>"]
+ puts "Image: #{image.info["RepoTags"]}"
+ end
+ end
+
def self.print_parsed_response(response)
case response
when Hash
response.each do |key, value|
case key
@@ -128,10 +139,9 @@
end
end
def self.instance_destroy(name)
docker_url
- puts "destroy: #{name}"
container = get_container(name)
if container
puts "Destroying #{name}"
begin