jarl 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1b82e05cd7a3e5e5e87a20e58f2975c7283bcd2
4
- data.tar.gz: 9939dc2ec0e4b50c443f4e901687338d8183e603
3
+ metadata.gz: e076c0b533e66716c968624611648d1a04994765
4
+ data.tar.gz: efadec1a212ef32fc557c67573a5b3e36f43ee9d
5
5
  SHA512:
6
- metadata.gz: abd454b5de4b9dbeb19d9775722d714f1e3d06bad19046602120027567e8918b02787307283324ecada358dd9fca32562ea2684c00bee0be880c49ca851b5f4e
7
- data.tar.gz: 76e066025fb79123135cbddce7dd52b5c84900ed50d53b3381a49ea1dd4b13932a53e94e942800678a4faa2914f9e26bc8a406d7665c6e025fb38965c72d9ede
6
+ metadata.gz: d69a18c739d116b3cb92948a331d399363eb963d2ef2d0e75dd76681d186d5f8c8c9907b0036217c7277e09aaf19b898551405def83dbbe9d88b0b8071121925
7
+ data.tar.gz: 7ce1a86f9a063d968320b9586db3671b7b26835e02265169a3072c3f1afae3e1782e38967e6fda0be99df7fc30b474f4dd08a220d5968b071fccb3e464a77ad9
@@ -2,6 +2,7 @@ module Jarl
2
2
  class Application
3
3
  attr_reader :group, :name, :hostname
4
4
  attr_reader :image, :volumes, :ports, :environment, :entrypoint, :command
5
+ attr_reader :serial
5
6
 
6
7
  # Create Application object from application definition:
7
8
  #
@@ -53,24 +54,24 @@ module Jarl
53
54
  end
54
55
 
55
56
  def running?
56
- running_container
57
+ instances.size > 0
57
58
  end
58
59
 
59
- def running_container
60
- Docker.containers_running.find { |c| c.name == full_name }
60
+ def instances
61
+ Docker.containers_running.select { |c| c.name =~ /^#{full_name}(\.\d+)?$/ }.map do |c|
62
+ Instance.new(self, c)
63
+ end
61
64
  end
62
65
 
63
- def start
64
- running_container.stop! if running?
65
- Docker.start(
66
- name: full_name,
67
- hostname: hostname,
68
- image: image_name,
69
- volumes: volumes,
70
- ports: ports,
71
- environment: environment,
72
- command: command
73
- )
66
+ # Start +scale+ instances of the application
67
+ #
68
+ def start(scale = 1)
69
+ instances.map(&:stop!) if running?
70
+ if scale > 1
71
+ scale.times { |n| Instance.start(self, n + 1) }
72
+ else
73
+ Instance.start(self)
74
+ end
74
75
  end
75
76
 
76
77
  def execute(execute_command, args)
@@ -87,7 +88,7 @@ module Jarl
87
88
 
88
89
  def ssh
89
90
  fail 'Not a running application' unless running?
90
- running_container.open_ssh_session!(Jarl.config.params)
91
+ instances.first.ssh
91
92
  end
92
93
 
93
94
  def build
@@ -103,24 +104,6 @@ module Jarl
103
104
  image_is_a_path? ? image : nil
104
105
  end
105
106
 
106
- def show_log(*_args)
107
- color_code = Console::Colors::SEQUENCE[@serial % Console::Colors::SEQUENCE.size]
108
- return unless running?
109
- begin
110
- IO.popen "docker logs -f #{running_container.id}", 'r' do |p|
111
- str = '<<< STARTED >>>'
112
- while str
113
- str = p.gets
114
- str.split("\n").each do |s|
115
- puts "#{esc_color color_code, full_name}: #{s}"
116
- end
117
- end
118
- end
119
- rescue Interrupt
120
- #
121
- end
122
- end
123
-
124
107
  def to_s
125
108
  full_name
126
109
  end
@@ -130,5 +113,62 @@ module Jarl
130
113
  @current_serial += 1
131
114
  @current_serial - 1
132
115
  end
116
+
117
+ # Application::Instance represents a single running instance of the application
118
+ #
119
+ class Instance
120
+ attr_reader :application, :container
121
+ def initialize(application, container)
122
+ @application = application
123
+ @container = container
124
+ end
125
+
126
+ def stop!
127
+ @container.stop!
128
+ end
129
+
130
+ def name
131
+ @container.name
132
+ end
133
+
134
+ def n
135
+ suffix = @container.name.split('.').last
136
+ suffix =~ /^\d+$/ ? suffix : nil
137
+ end
138
+
139
+ def tail_log(*_args)
140
+ color_code = Console::Colors::SEQUENCE[application.serial % Console::Colors::SEQUENCE.size]
141
+ begin
142
+ instance_no = n ? ".#{n}" : ''
143
+ IO.popen "docker logs -f #{container.id}", 'r' do |p|
144
+ str = '<<< STARTED >>>'
145
+ while str
146
+ str = p.gets
147
+ str.split("\n").each do |s|
148
+ puts "#{esc_color color_code, application.full_name}#{instance_no}: #{s}"
149
+ end
150
+ end
151
+ end
152
+ rescue Interrupt
153
+ #
154
+ end
155
+ end
156
+
157
+ def ssh
158
+ container.open_ssh_session!(Jarl.config.params)
159
+ end
160
+
161
+ def self.start(application, n = nil)
162
+ Docker.start(
163
+ name: (n ? "#{application.full_name}.#{n}" : application.full_name),
164
+ hostname: (n ? "#{application.hostname}-#{n}" : application.hostname),
165
+ image: application.image_name,
166
+ volumes: application.volumes,
167
+ ports: application.ports,
168
+ environment: application.environment,
169
+ command: application.command
170
+ )
171
+ end
172
+ end # class Instance
133
173
  end # class Application
134
174
  end # module Jarl
data/lib/jarl/cli.rb CHANGED
@@ -38,13 +38,17 @@ module Jarl
38
38
  default_task :status
39
39
 
40
40
  #
41
+ option :scale,
42
+ type: :numeric,
43
+ default: 1,
44
+ desc: 'Start several instances'
41
45
  desc 'up [NAME]', 'Start or restart applications'
42
46
  def up(name = nil)
43
47
  Jarl.load(options)
44
48
  apps = name ? Jarl.find_applications_by(name) : Jarl.applications
45
49
  apps.each do |app|
46
50
  puts esc_green(app.running? ? "Restarting '#{app}'..." : "Starting '#{app}'...")
47
- app.start
51
+ app.start(options[:scale])
48
52
  end
49
53
  # show_jarl_applications_status(apps)
50
54
  end
@@ -56,8 +60,10 @@ module Jarl
56
60
  apps = name ? Jarl.find_applications_by(name) : Jarl.applications
57
61
  apps.each do |app|
58
62
  next unless app.running?
59
- puts esc_yellow "Stopping '#{app}'..."
60
- app.running_container.stop!
63
+ app.instances.each do |i|
64
+ puts esc_yellow "Stopping '#{i.name}'..."
65
+ i.stop!
66
+ end
61
67
  end
62
68
  end
63
69
 
@@ -87,7 +93,7 @@ module Jarl
87
93
  apps = name ? Jarl.find_applications_by(name) : Jarl.applications
88
94
  apps.each do |app|
89
95
  if options[:ip]
90
- puts app.running_container.ip if app.running?
96
+ puts app.instances.map(&:container).map(&:ip) if app.running?
91
97
  else
92
98
  show_jarl_application_inspect(app)
93
99
  end
@@ -109,11 +115,12 @@ module Jarl
109
115
  Jarl.load(options)
110
116
  apps = name ? Jarl.find_applications_by(name) : Jarl.applications
111
117
  threads = []
112
- apps.select(&:running?).each do |app|
113
- threads << Thread.new { app.show_log }
118
+ apps.select(&:running?).map(&:instances).flatten.each do |instance|
119
+ threads << Thread.new { instance.tail_log }
114
120
  end
121
+
115
122
  begin
116
- threads.each(&:join)
123
+ threads.flatten.each(&:join)
117
124
  rescue Interrupt
118
125
  #
119
126
  end
@@ -136,7 +143,10 @@ module Jarl
136
143
  puts esc_yellow 'No applications found'
137
144
  return
138
145
  end
139
- max_full_name_len = [apps.map(&:full_name).map(&:size).max, 12].max
146
+ full_names = apps.map do |app|
147
+ app.running? ? app.instances.map { |i| i.container.name } : app.full_name
148
+ end.flatten
149
+ max_full_name_len = [full_names.map(&:size).max, 12].max
140
150
  puts esc_format(
141
151
  ['APPLICATION', max_full_name_len],
142
152
  ['RUNNING', 12],
@@ -145,14 +155,25 @@ module Jarl
145
155
  ['PORTS']
146
156
  )
147
157
  apps.each do |app|
148
- container = app.running_container
149
- puts esc_format(
150
- [app.full_name, max_full_name_len, :yellow],
151
- (app.running? ? [container.id, 12, :green] : ['no', 12]),
152
- (app.running? ? [seconds_to_human(container.uptime), 12, :yellow] : ['', 12]),
153
- (app.running? ? [container.ip, 12, :yellow] : ['', 12]),
154
- (app.running? ? [container.ports.map { |p| "#{p[:from]}"}.join(', ')] : [''])
155
- )
158
+ if app.running?
159
+ app.instances.each do |i|
160
+ puts esc_format(
161
+ [i.container.name, max_full_name_len, :yellow],
162
+ [i.container.id, 12, :green],
163
+ [seconds_to_human(i.container.uptime), 12, :yellow],
164
+ [i.container.ip, 12, :yellow],
165
+ [i.container.ports.map { |p| "#{p[:from]}" }.join(', ')]
166
+ )
167
+ end
168
+ else
169
+ puts esc_format(
170
+ [app.full_name, max_full_name_len, :yellow],
171
+ ['no', 12],
172
+ ['', 12],
173
+ ['', 12],
174
+ ['']
175
+ )
176
+ end
156
177
  end
157
178
  end
158
179
 
@@ -161,15 +182,16 @@ module Jarl
161
182
  puts esc_yellow("#{app.full_name}: ") + 'down'
162
183
  return
163
184
  end
164
- container = app.running_container
165
- puts esc_yellow "#{app.full_name}: " + esc_green(container.id)
166
- puts " name: #{esc_yellow container.name}"
167
- puts " image: #{esc_yellow container.image}"
168
- puts " full ID: #{esc_yellow container.long_id}"
169
- puts " uptime: #{esc_yellow seconds_to_human container.uptime}"
170
- puts " IP: #{esc_yellow container.ip}"
171
- puts " ports: #{esc_yellow container.ports.map { |p| "#{p[:from]}->#{p[:to]}"}.join(', ')}"
172
- puts " volumes: #{esc_yellow container.params['Volumes']}"
185
+ app.instances.map(&:container).each do |container|
186
+ puts esc_yellow "#{container.name}: " + esc_green(container.id)
187
+ puts " app: #{esc_yellow app.full_name}"
188
+ puts " image: #{esc_yellow container.image}"
189
+ puts " full ID: #{esc_yellow container.long_id}"
190
+ puts " uptime: #{esc_yellow seconds_to_human container.uptime}"
191
+ puts " IP: #{esc_yellow container.ip}"
192
+ puts " ports: #{esc_yellow container.ports.map { |p| "#{p[:from]}->#{p[:to]}"}.join(', ')}"
193
+ puts " volumes: #{esc_yellow container.params['Volumes']}"
194
+ end
173
195
  end
174
196
  end # class CLI
175
197
  end # module Jarl
data/lib/jarl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jarl
2
- VERSION = '0.3.3'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Kukushkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor