Class: Jarl::Application::Instance
- Inherits:
-
Object
- Object
- Jarl::Application::Instance
- Defined in:
- lib/jarl/application.rb
Overview
Application::Instance represents a single running instance of the application
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(application, container) ⇒ Instance
constructor
A new instance of Instance.
- #n ⇒ Object
- #name ⇒ Object
- #ssh(command = nil) ⇒ Object
- #stop! ⇒ Object
- #tail_log(*_args) ⇒ Object
Constructor Details
#initialize(application, container) ⇒ Instance
Returns a new instance of Instance.
133 134 135 136 |
# File 'lib/jarl/application.rb', line 133 def initialize(application, container) @application = application @container = container end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
132 133 134 |
# File 'lib/jarl/application.rb', line 132 def application @application end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
132 133 134 |
# File 'lib/jarl/application.rb', line 132 def container @container end |
Class Method Details
.start(application, n = nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/jarl/application.rb', line 173 def self.start(application, n = nil) Docker.start( name: (n ? "#{application.full_name}.#{n}" : application.full_name), hostname: (n ? "#{application.hostname}-#{n}" : application.hostname), image: application.image_name, volumes: application.volumes, ports: application.ports, environment: application.environment, command: application.command ) end |
Instance Method Details
#n ⇒ Object
146 147 148 149 |
# File 'lib/jarl/application.rb', line 146 def n suffix = @container.name.split('.').last suffix =~ /^\d+$/ ? suffix : nil end |
#name ⇒ Object
142 143 144 |
# File 'lib/jarl/application.rb', line 142 def name @container.name end |
#ssh(command = nil) ⇒ Object
169 170 171 |
# File 'lib/jarl/application.rb', line 169 def ssh(command = nil) container.open_ssh_session!(Jarl.config.params, command) end |
#stop! ⇒ Object
138 139 140 |
# File 'lib/jarl/application.rb', line 138 def stop! @container.stop! end |
#tail_log(*_args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/jarl/application.rb', line 151 def tail_log(*_args) color_code = Console::Colors::SEQUENCE[application.serial % Console::Colors::SEQUENCE.size] begin instance_no = n ? ".#{n}" : '' IO.popen "docker logs -f #{container.id}", 'r' do |p| str = '<<< STARTED >>>' while str str = p.gets str.split("\n").each do |s| puts "#{esc_color color_code, application.full_name}#{instance_no}: #{s}" end end end rescue Interrupt # end end |