class Dockistrano::Cli
Public Instance Methods
build()
click to toggle source
# File lib/dockistrano/cli.rb, line 63 def build if current_service.build say_status "built", current_service.image_name if current_service.test say_status "tests passed", current_service.image_name current_service.push say_status "pushed", current_service.image_name else say_status "tests failed", current_service.image_name exit 1 end else say_status "failed", current_service.image_name, :red exit 1 end end
clean()
click to toggle source
# File lib/dockistrano/cli.rb, line 181 def clean Docker.clean Dockistrano::ServiceDependency.clear_cache end
console(*command)
click to toggle source
# File lib/dockistrano/cli.rb, line 173 def console(*command) command = ["/bin/bash"] if command.empty? current_service.console(command.join(" "), options) rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e.message, :red end
exec(*command)
click to toggle source
# File lib/dockistrano/cli.rb, line 165 def exec(*command) current_service.exec(command.join(" "), options) rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e.message, :red end
logs(name=nil)
click to toggle source
# File lib/dockistrano/cli.rb, line 187 def logs(name=nil) if name and current_service.backing_services[name] service = current_service.backing_services[name] command_name = nil else service = current_service command_name = name end if service.running? say "Container #{service.image_name} running, attaching to output", :blue service.attach(command_name) else say "Container #{service.image_name} stopped, printing logs of last run", :blue service.logs(command_name) end end
method_missing(*args)
click to toggle source
Calls superclass method
# File lib/dockistrano/cli.rb, line 210 def method_missing(*args) command = args[0] if command and current_service.config["aliases"] and current_service.config["aliases"][command.to_s] args.shift Kernel.exec("doc #{current_service.config["aliases"][command.to_s]} #{args.join(" ")}") else super end end
ps()
click to toggle source
# File lib/dockistrano/cli.rb, line 13 def ps puts Docker.ps end
pull()
click to toggle source
# File lib/dockistrano/cli.rb, line 81 def pull current_service.backing_services(initialize: false).each do |name, service| if service.newer_version_available? service.pull say_status "Pulled", name else say_status "Uptodate", name, :white end end if current_service.newer_version_available? current_service.pull say_status "Pulled", current_service.image_name else say_status "Uptodate", current_service.image_name, :white end end
push()
click to toggle source
# File lib/dockistrano/cli.rb, line 100 def push current_service.push end
restart()
click to toggle source
# File lib/dockistrano/cli.rb, line 156 def restart current_service.stop say_status("Stopped", current_service.image_name) current_service.start(options) say_status("Started", current_service.image_name) end
setup()
click to toggle source
# File lib/dockistrano/cli.rb, line 19 def setup `mkdir -p #{current_service.directories_required_on_host.join(" ")}` end
start()
click to toggle source
# File lib/dockistrano/cli.rb, line 131 def start if current_service.running? say_status("Running", current_service.image_name, :white) else current_service.start(options) say_status("Started", current_service.image_name) end rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e.message, :red end
start_services()
click to toggle source
# File lib/dockistrano/cli.rb, line 106 def start_services current_service.backing_services.each do |name, service| if service.running? say_status("Running", name, :white) else service.start say_status("Started", name) end end end
status()
click to toggle source
# File lib/dockistrano/cli.rb, line 25 def status say "DOCKISTRANO_ENVIRONMENT: #{options["environment"]}", :green say "DOCKER_HOST_IP: #{ENV['DOCKER_HOST_IP']}", :green say "DOCKER_BINARY: #{ENV['DOCKER_BINARY']}", :green say "" say "Current application", :blue say " registry: #{current_service.registry}" say " image name: #{current_service.image_name}" say " tag: #{current_service.tag}" say " volumes:" current_service.volumes.each do |volume| say " #{volume}" end say "" say "Dependencies", :blue current_service.backing_services.each do |name, service| if service.running? say_status "online", "#{service.full_image_name}", :green else say_status "offline", "#{service.full_image_name}", :red end end say "" say "Environment", :blue current_service.environment_variables.each do |key, value| say " #{key}=#{value}" end if current_service.backing_services["hipache"] and redis_url = current_service.backing_services["hipache"].ip_address say "" say "Hipache", :blue Hipache.new("redis://#{redis_url}:6379").status.each do |host, ips| say " #{host}: #{ips.join(", ")}" end end say "" end
stop(id=nil)
click to toggle source
# File lib/dockistrano/cli.rb, line 143 def stop(id=nil) if id Docker.stop(id) Docker.remove_container(id) say_status("Stopped", id, :green) else current_service.stop say_status("Stopped", current_service.image_name, :green) end end
stop_all()
click to toggle source
# File lib/dockistrano/cli.rb, line 118 def stop_all current_service.stop say_status("Stopped", current_service.image_name) current_service.backing_services.each do |name, service| if service.running? service.stop say_status("Stopped", name) end end end
version()
click to toggle source
# File lib/dockistrano/cli.rb, line 206 def version say "Dockistrano version: #{Dockistrano::VERSION}" end
Private Instance Methods
current_service()
click to toggle source
Returns the current service
# File lib/dockistrano/cli.rb, line 223 def current_service @service ||= Service.factory(Dir.pwd, options["environment"]) rescue Dockistrano::Service::ConfigurationFileMissing say "No configuration file found in current directory. config/dockistrano.yml missing", :red exit 1 end