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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdc228f546309ef55d73857144c42342aab59774
4
- data.tar.gz: be9080480a0f1ce0632a0730ede8170cd7e48091
3
+ metadata.gz: 7991702d66db4cdc6aa280b8ccaa5f840fe3a78d
4
+ data.tar.gz: a8cd115657504495412dc2058dc5c68524e999e4
5
5
  SHA512:
6
- metadata.gz: b36299c95d25c838dfed38ccecac1617473f87269cbc4ce3f96b634d4557ccd95ecfb4f6391c16e3a2a5e84c17bacb4a0d46270501cb0b73d771235b8aabad11
7
- data.tar.gz: 75729de146953bde8b911242738446ba0412b795478ac2feb8802b7bda679ba313d7551aa2a2a7d676bda8b9a0121e86c3d0a9d3d6874967d5025ea87d247cb1
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 APPLICATION_CONTAINER ENV [COMPONENT_TYPE]',
7
- 'Fetch the logs from a application container. You can find the container for your application through the "busbar containers" command.'
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: 'Only return logs newer than a relative duration like 5s, 2m, or 3h. ' \
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: '100',
13
+ default: '30',
15
14
  type: :string,
16
- desc: 'Last <size> lines of the logs to be returned' \
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
- resource_id,
22
- environment_name = Services::AppConfig.get_or_exit('environment'),
23
- component = nil
19
+ app_id,
20
+ environment_name,
21
+ component_id = nil
24
22
  )
25
23
  Services::Kube.configure_temporary_profile(options['profile'])
26
24
 
27
- if !component.nil? && AppsRepository.find(app_id: resource_id)
28
- Services::ComponentLogs.call(
29
- component: Component.new(
30
- app_id: resource_id,
31
- environment_name: environment_name,
32
- type: component
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'.freeze
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
 
@@ -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(container_id:, environment_name:, since:)
3
+ def self.call(app_id:, environment_name:, component_id:, since:, size:)
4
4
  Services::Kube.setup
5
+ require 'open3'
5
6
 
6
- container_name = container_id.split('-')[0..-3].join('-')
7
+ @environment_name = environment_name
8
+ @app_id = app_id
9
+ @component_id = component_id
7
10
 
8
- Kernel.exec(
9
- "#{KUBECTL} --context=#{Services::Kube.current_profile} " \
10
- "logs -f --since=#{since} #{container_id} #{container_name} -n #{environment_name}"
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.3
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
@@ -1,9 +0,0 @@
1
- module Services
2
- class ComponentLogs
3
- def self.call(component:, size:)
4
- Printer.print_resource(
5
- ComponentsRepository.log_for(component: component, size: size)
6
- )
7
- end
8
- end
9
- end