Class: Dockistrano::Cli
- Inherits:
-
Thor
- Object
- Thor
- Dockistrano::Cli
- Defined in:
- lib/dockistrano/cli.rb
Instance Method Summary collapse
- #build ⇒ Object
- #clean ⇒ Object
- #console(*command) ⇒ Object
- #exec(*command) ⇒ Object
- #logs(name = nil) ⇒ Object
- #method_missing(*args) ⇒ Object
- #ps ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #restart ⇒ Object
- #setup ⇒ Object
- #start ⇒ Object
- #start_services ⇒ Object
- #status ⇒ Object
- #stop(id = nil) ⇒ Object
- #stop_all ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'lib/dockistrano/cli.rb', line 199 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 |
Instance Method Details
#build ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dockistrano/cli.rb', line 65 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 ⇒ Object
182 183 184 185 |
# File 'lib/dockistrano/cli.rb', line 182 def clean Docker.clean Dockistrano::ServiceDependency.clear_cache end |
#console(*command) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/dockistrano/cli.rb', line 174 def console(*command) command = ["/bin/bash"] if command.empty? current_service.console(command.join(" "), ) rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e., :red end |
#exec(*command) ⇒ Object
166 167 168 169 170 |
# File 'lib/dockistrano/cli.rb', line 166 def exec(*command) current_service.exec(command.join(" "), ) rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e., :red end |
#logs(name = nil) ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/dockistrano/cli.rb', line 188 def logs(name=nil) service = name ? current_service.backing_services[name] : current_service if service.running? say "Container #{service.image_name} running, attaching to output", :blue service.attach else say "Container #{service.image_name} stopped, printing logs of last run", :blue service.logs end end |
#ps ⇒ Object
20 21 22 |
# File 'lib/dockistrano/cli.rb', line 20 def ps puts Docker.ps end |
#pull ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dockistrano/cli.rb', line 83 def pull current_service.backing_services.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 ⇒ Object
102 103 104 |
# File 'lib/dockistrano/cli.rb', line 102 def push current_service.push end |
#restart ⇒ Object
157 158 159 160 161 162 |
# File 'lib/dockistrano/cli.rb', line 157 def restart current_service.stop say_status("Stopped", current_service.image_name) current_service.start() say_status("Started", current_service.image_name) end |
#setup ⇒ Object
26 27 28 29 |
# File 'lib/dockistrano/cli.rb', line 26 def setup say "Please execute the following command on the host to setup", :green say "\tmkdir -p #{current_service.directories_required_on_host.join(" ")}" end |
#start ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dockistrano/cli.rb', line 133 def start if current_service.running? say_status("Running", current_service.image_name, :white) else current_service.start() say_status("Started", current_service.image_name) end rescue Dockistrano::Service::EnvironmentVariablesMissing => e say e., :red end |
#start_services ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dockistrano/cli.rb', line 108 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 ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dockistrano/cli.rb', line 33 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| say " #{service.full_image_name}" end say "" say "Environment", :blue current_service.environment_variables.each do |key, value| say " #{key}=#{value}" end say "" say "Hipache", :blue Hipache.new(ENV["DOCKER_HOST_IP"]).status.each do |host, ips| say " #{host}: #{ips.join(", ")}" end say "" end |
#stop(id = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/dockistrano/cli.rb', line 145 def stop(id=nil) if id Docker.stop(id) say_status("Stopped", id, :green) else current_service.stop say_status("Stopped", current_service.image_name, :green) end end |
#stop_all ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/dockistrano/cli.rb', line 120 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 |