lib/jarl/application.rb in jarl-0.2.0 vs lib/jarl/application.rb in jarl-0.3.0

- old
+ new

@@ -1,8 +1,9 @@ module Jarl class Application - attr_reader :group, :name, :image, :volumes, :ports, :environment, :entrypoint, :command + attr_reader :group, :name, :hostname + attr_reader :image, :volumes, :ports, :environment, :entrypoint, :command # Create Application object from application definition: # # app_name: # image: blabla @@ -37,10 +38,12 @@ end @command = params['command'] if @command && !@command.is_a?(String) fail "Application '#{self}' has invalid 'command' definition, String is expected" end + @serial = self.class.next_serial + @hostname = @name end def full_name "#{group}.#{name}" end @@ -59,18 +62,36 @@ def start running_container.stop! if running? Docker.start( name: full_name, + hostname: hostname, image: image_name, volumes: volumes, ports: ports, environment: environment, command: command ) end + def execute(execute_command, args) + Docker.execute( + name: full_name, + hostname: hostname, + image: image_name, + volumes: volumes, + ports: ports, + environment: environment, + command: (execute_command || command || '') + ' ' + args.join(' ') + ) + end + + def ssh + fail 'Not a running application' unless running? + running_container.open_ssh_session!(Jarl.config.params) + end + def build fail 'Not a file based image' unless image_is_a_path? Docker::Image.new(image_name, image_path).build! end @@ -81,21 +102,33 @@ def image_path image_is_a_path? ? image : nil end def show_log(*_args) + color_code = Console::Colors::SEQUENCE[@serial % Console::Colors::SEQUENCE.size] return unless running? begin IO.popen "docker logs -f #{running_container.id}", 'r' do |p| str = '<<< STARTED >>>' - puts "#{esc_yellow full_name}: #{str}" while str = p.gets + while str + str = p.gets + str.split("\n").each do |s| + puts "#{esc_color color_code, full_name}: #{s}" + end + end end rescue Interrupt # end end def to_s full_name + end + + def self.next_serial + @current_serial ||= 0 + @current_serial += 1 + @current_serial - 1 end end # class Application end # module Jarl