jarl 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jarl/application.rb +73 -33
- data/lib/jarl/cli.rb +47 -25
- data/lib/jarl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e076c0b533e66716c968624611648d1a04994765
|
4
|
+
data.tar.gz: efadec1a212ef32fc557c67573a5b3e36f43ee9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d69a18c739d116b3cb92948a331d399363eb963d2ef2d0e75dd76681d186d5f8c8c9907b0036217c7277e09aaf19b898551405def83dbbe9d88b0b8071121925
|
7
|
+
data.tar.gz: 7ce1a86f9a063d968320b9586db3671b7b26835e02265169a3072c3f1afae3e1782e38967e6fda0be99df7fc30b474f4dd08a220d5968b071fccb3e464a77ad9
|
data/lib/jarl/application.rb
CHANGED
@@ -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
|
-
|
57
|
+
instances.size > 0
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
-
Docker.containers_running.
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
60
|
-
|
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.
|
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 |
|
113
|
-
threads << Thread.new {
|
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
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
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.
|
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-
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|