busbar-cli 1.9.3 → 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/busbar_cli/commands/logs.rb +16 -27
- data/lib/busbar_cli/config/version.rb +1 -1
- data/lib/busbar_cli/repositories/environments_repository.rb +7 -0
- data/lib/busbar_cli/services.rb +0 -1
- data/lib/busbar_cli/services/logs.rb +62 -5
- metadata +1 -2
- data/lib/busbar_cli/services/component_logs.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7991702d66db4cdc6aa280b8ccaa5f840fe3a78d
|
4
|
+
data.tar.gz: a8cd115657504495412dc2058dc5c68524e999e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d456631e1130fd40a8a5826bc0542724cf15788498ac06bc259efb1571131dffb326cbfe96824eb9859ad7837cba4c690e9402c44b70f6d155986807d122416a
|
7
|
+
data.tar.gz: 808ec6689929bd252cf78f0a4be4b6648337a81b9f61d92e5923e5c6e9075b14ca013d9b7dfc95f7bf97a3afbe07ae34a5dbb593fa9924e7acda18aa55d7b5a5
|
@@ -3,43 +3,32 @@ module Commands
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
desc 'logs
|
7
|
-
'
|
6
|
+
desc 'logs APP ENV [COMPONENT]',
|
7
|
+
'Stream the application logs.'
|
8
8
|
method_option :since,
|
9
9
|
default: '0',
|
10
10
|
type: :string,
|
11
|
-
desc: '
|
12
|
-
'Defaults to all logs.'
|
11
|
+
desc: 'Look-back duration in seconds, minutes, or hours (5s, 2m, 3h).'
|
13
12
|
method_option :size,
|
14
|
-
default: '
|
13
|
+
default: '30',
|
15
14
|
type: :string,
|
16
|
-
desc: '
|
17
|
-
'Defaults to 100.'
|
15
|
+
desc: 'Number of lines.'
|
18
16
|
method_option :profile,
|
19
|
-
desc: 'Profile used to run the command'
|
17
|
+
desc: 'Profile used to run the command.'
|
20
18
|
def logs(
|
21
|
-
|
22
|
-
environment_name
|
23
|
-
|
19
|
+
app_id,
|
20
|
+
environment_name,
|
21
|
+
component_id = nil
|
24
22
|
)
|
25
23
|
Services::Kube.configure_temporary_profile(options['profile'])
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
size: options['size'].to_i
|
35
|
-
)
|
36
|
-
else
|
37
|
-
Services::Logs.call(
|
38
|
-
container_id: resource_id,
|
39
|
-
environment_name: environment_name,
|
40
|
-
since: options['since']
|
41
|
-
)
|
42
|
-
end
|
25
|
+
Services::Logs.call(
|
26
|
+
app_id: app_id,
|
27
|
+
environment_name: environment_name,
|
28
|
+
component_id: component_id,
|
29
|
+
since: options['since'],
|
30
|
+
size: options['size'].to_i
|
31
|
+
)
|
43
32
|
end
|
44
33
|
end
|
45
34
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Version Variables
|
2
2
|
VERSION = '1.9'.freeze
|
3
|
-
BUSBAR_PATCH_VERSION = '
|
3
|
+
BUSBAR_PATCH_VERSION = '4'.freeze
|
4
4
|
KUBECTL_PATCH_VERSION = '6'.freeze
|
5
5
|
BUSBAR_VERSION = "#{VERSION}.#{BUSBAR_PATCH_VERSION}".freeze
|
6
6
|
KUBECTL_VERSION = "#{VERSION}.#{KUBECTL_PATCH_VERSION}".freeze
|
@@ -27,6 +27,13 @@ class EnvironmentsRepository
|
|
27
27
|
Environment.new(environment_data)
|
28
28
|
end
|
29
29
|
|
30
|
+
def get(environment_name, app_id)
|
31
|
+
@environment_name = environment_name
|
32
|
+
@app_id = app_id
|
33
|
+
|
34
|
+
Request.get(environment_route).body
|
35
|
+
end
|
36
|
+
|
30
37
|
def create(params)
|
31
38
|
@app_id = params[:app_id]
|
32
39
|
|
data/lib/busbar_cli/services.rb
CHANGED
@@ -6,7 +6,6 @@ require 'busbar_cli/services/app_config/displayer'
|
|
6
6
|
require 'busbar_cli/services/app_config/reseter'
|
7
7
|
require 'busbar_cli/services/app_config/unseter'
|
8
8
|
require 'busbar_cli/services/console'
|
9
|
-
require 'busbar_cli/services/component_logs'
|
10
9
|
require 'busbar_cli/services/database_creator'
|
11
10
|
require 'busbar_cli/services/database_destroyer'
|
12
11
|
require 'busbar_cli/services/deploy'
|
@@ -1,14 +1,71 @@
|
|
1
1
|
module Services
|
2
2
|
class Logs
|
3
|
-
def self.call(
|
3
|
+
def self.call(app_id:, environment_name:, component_id:, since:, size:)
|
4
4
|
Services::Kube.setup
|
5
|
+
require 'open3'
|
5
6
|
|
6
|
-
|
7
|
+
@environment_name = environment_name
|
8
|
+
@app_id = app_id
|
9
|
+
@component_id = component_id
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
# Retrieve Component Data
|
12
|
+
if @component_id.nil? then
|
13
|
+
# retrieve app components from server
|
14
|
+
environment_data = JSON.parse(EnvironmentsRepository.get(environment_name, app_id))
|
15
|
+
components_data = environment_data['data']['components']
|
16
|
+
|
17
|
+
if components_data.length == 1 then
|
18
|
+
@component_id = components_data[0]['type']
|
19
|
+
else
|
20
|
+
puts "More than one component found for #{@app_id} #{@environment_name}."
|
21
|
+
puts "Available components:"
|
22
|
+
components_data.each do |component|
|
23
|
+
puts " #{component['type']}"
|
24
|
+
end
|
25
|
+
puts "Please choose one from the list above and try again."
|
26
|
+
return
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Retrieve a Pod Name
|
31
|
+
stdout, stderr, status = Open3.capture3(
|
32
|
+
"#{KUBECTL} --context=#{Services::Kube.current_profile} --namespace #{environment_name} " \
|
33
|
+
"get pod -l busbar.io/app=#{app_id},busbar.io/component=#{@component_id} | grep -v '^NAME' | head -n 1 | awk '{print $1}'"
|
34
|
+
)
|
35
|
+
|
36
|
+
if status.to_s.end_with?('0') and stdout.length > 0 then
|
37
|
+
pod_name = stdout.to_s.chomp
|
38
|
+
else
|
39
|
+
puts "Application not found."
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieve pod data and set a container name
|
44
|
+
stdout, stderr, status = Open3.capture3(
|
45
|
+
"#{KUBECTL} --context=#{Services::Kube.current_profile} --namespace #{environment_name} " \
|
46
|
+
"get pod #{pod_name} --output json"
|
11
47
|
)
|
48
|
+
|
49
|
+
if status.to_s.end_with?('0') then
|
50
|
+
pod_data_json = JSON.parse(stdout)
|
51
|
+
|
52
|
+
if pod_data_json['spec']['containers'].length == 1 then
|
53
|
+
@container_name = pod_data_json['spec']['containers'][0]['name']
|
54
|
+
else
|
55
|
+
pod_data_json['spec']['containers'].each do |record|
|
56
|
+
@container_name = record['name'] unless record['name'].end_with?('nginx')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Fetch components => pod => container log
|
61
|
+
Kernel.exec(
|
62
|
+
"#{KUBECTL} --context=#{Services::Kube.current_profile} --namespace #{environment_name} " \
|
63
|
+
"logs --follow=true --since=#{since} --tail=#{size} #{pod_name} --container #{@container_name}"
|
64
|
+
)
|
65
|
+
else
|
66
|
+
puts "Error while retrieving pod data:"
|
67
|
+
puts " #{stderr}"
|
68
|
+
end
|
12
69
|
end
|
13
70
|
end
|
14
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: busbar-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Marques
|
@@ -208,7 +208,6 @@ files:
|
|
208
208
|
- lib/busbar_cli/services/app_destroyer.rb
|
209
209
|
- lib/busbar_cli/services/apps.rb
|
210
210
|
- lib/busbar_cli/services/busbar_config.rb
|
211
|
-
- lib/busbar_cli/services/component_logs.rb
|
212
211
|
- lib/busbar_cli/services/console.rb
|
213
212
|
- lib/busbar_cli/services/database_creator.rb
|
214
213
|
- lib/busbar_cli/services/database_destroyer.rb
|