Class: Renuo::Cli::Commands::Debug
- Inherits:
-
Object
- Object
- Renuo::Cli::Commands::Debug
- Defined in:
- lib/renuo/cli/commands/debug.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- Cache =
Renuo::Cli::Services::Cache
- Deploio =
Renuo::Cli::Services::Deploio
- Heroku =
Renuo::Cli::Services::Heroku
- Hetzner =
Renuo::Cli::Services::Hetzner
Instance Method Summary collapse
-
#run(args, options) ⇒ Object
rubocop:todo Metrics/PerceivedComplexity rubocop:todo Metrics/MethodLength rubocop:todo Metrics/AbcSize.
Instance Method Details
#run(args, options) ⇒ Object
rubocop:todo Metrics/PerceivedComplexity rubocop:todo Metrics/MethodLength rubocop:todo Metrics/AbcSize
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/renuo/cli/commands/debug.rb', line 36 def run(args, ) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity query = args[0] abort(">> Please provide an app name or domain.") if query.blank? cloud_unspecified = !.heroku && !.deploio && !.hetzner should_scan_heroku = .heroku || cloud_unspecified should_scan_deploio = .deploio || cloud_unspecified should_scan_hetzner = .hetzner || cloud_unspecified choose do || # rubocop:todo Metrics/BlockLength deploio_cache_info = "Deploio: #{Cache.stored_at("deploio_apps") || "never"}" heroku_cache_info = "Heroku: #{Cache.stored_at("heroku_apps") || "never"}" hetzner_cache_info = "Hetzner: #{Cache.stored_at("hetzner_vms") || "never"}" .choice "Update caches (#{deploio_cache_info}, #{heroku_cache_info}, #{hetzner_cache_info})" do if should_scan_deploio say "Updating Deploio cache" Cache.store("deploio_apps", Deploio.fetch_apps) Cache.store("deploio_vms", Deploio.fetch_vms) end if should_scan_heroku say "Updating Heroku cache..." Cache.store("heroku_apps", Heroku.fetch_apps) end if should_scan_hetzner say "Updating Hetzner cache..." Cache.store("hetzner_vms", Hetzner.fetch_vms) end say "Caches updated" end open_cmds = [] if should_scan_deploio && Cache.stored_at("deploio_apps") select_deploio_targets(query).each do |app| display_cmd, exec_cmd = nctl_command(app, "exec", "bash") .choice(display_cmd) { exec exec_cmd.squish } display_cmd, exec_cmd = nctl_command(app, "exec", "bundle exec rails console") .choice(display_cmd) { exec exec_cmd.squish } display_cmd, exec_cmd = nctl_command(app, "logs", "-f") .choice(display_cmd) { exec exec_cmd.squish } app[:hosts].each { |host| open_cmds << "open https://#{host}" } end end if should_scan_deploio && Cache.stored_at("deploio_vms") select_deploio_vm_targets(query).each do |vm| bash_cmd = "ssh root@#{vm[:fqdn]} docker ps" .choice(bash_cmd) { exec bash_cmd.squish } end end if should_scan_heroku && Cache.stored_at("heroku_apps") select_heroku_targets(query).each do |app| exec_cmd = "heroku #{bold("run")} bash --app #{bold(app[:name])}" .choice(exec_cmd) { exec exec_cmd.squish } rails_console_cmd = "heroku #{bold("run")} bundle exec rails console --app #{bold(app[:name])}" .choice(rails_console_cmd) { exec rails_console_cmd.squish } log_cmd = "heroku #{bold("logs")} -t --app #{bold(app[:name])}" .choice(log_cmd) { exec log_cmd.squish } app[:domains].each do |host| open_cmds << "open https://#{host}" end end end if should_scan_hetzner && Cache.stored_at("hetzner_vms") select_hetzner_vm_targets(query).each do |vm| bash_cmd = "ssh root@#{vm[:fqdn] || vm[:public_ip]} docker ps" .choice(bash_cmd) { exec bash_cmd.squish } open_cmds << "open https://console.hetzner.com/projects/#{vm[:project_id]}/servers/#{vm[:id]}" end end open_cmds.uniq.each do |cmd| .choice(cmd) { exec cmd.squish } end end end |