Class: Mrsk::Cli::App
Instance Method Summary collapse
- #boot ⇒ Object
- #containers ⇒ Object
- #current ⇒ Object
- #current_version ⇒ Object
- #details ⇒ Object
- #exec(cmd) ⇒ Object
- #images ⇒ Object
- #logs ⇒ Object
- #remove ⇒ Object
- #remove_container(version) ⇒ Object
- #remove_containers ⇒ Object
- #remove_images ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Mrsk::Cli::Base
Instance Method Details
#boot ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mrsk/cli/app.rb', line 5 def boot cli = self say "Ensure no other version of the app is running...", :magenta stop say "Get most recent version available as an image...", :magenta unless [:version] using_version([:version] || most_recent_version_available) do |version| say "Start container with version #{version} (or reboot if already running)...", :magenta MRSK.config.roles.each do |role| on(role.hosts) do |host| execute *MRSK.auditor.record("app boot version #{version}"), verbosity: :debug begin execute *MRSK.app.run(role: role.name) rescue SSHKit::Command::Failed => e if e. =~ /already in use/ error "Rebooting container with same version already deployed on #{host}" cli.remove_container version execute *MRSK.app.run(role: role.name) else raise end end end end end end |
#containers ⇒ Object
100 101 102 |
# File 'lib/mrsk/cli/app.rb', line 100 def containers on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_containers) } end |
#current ⇒ Object
110 111 112 |
# File 'lib/mrsk/cli/app.rb', line 110 def current on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_container_id) } end |
#current_version ⇒ Object
175 176 177 |
# File 'lib/mrsk/cli/app.rb', line 175 def current_version on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_running_version).strip } end |
#details ⇒ Object
53 54 55 |
# File 'lib/mrsk/cli/app.rb', line 53 def details on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.info) } end |
#exec(cmd) ⇒ Object
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 |
# File 'lib/mrsk/cli/app.rb', line 60 def exec(cmd) case when [:interactive] && [:reuse] say "Get current version of running container...", :magenta unless [:version] using_version([:version] || current_running_version) do |version| say "Launching interactive command with version #{version} via SSH from existing container on #{MRSK.primary_host}...", :magenta run_locally { exec MRSK.app.execute_in_existing_container_over_ssh(cmd, host: MRSK.primary_host) } end when [:interactive] say "Get most recent version available as an image...", :magenta unless [:version] using_version([:version] || most_recent_version_available) do |version| say "Launching interactive command with version #{version} via SSH from new container on #{MRSK.primary_host}...", :magenta run_locally { exec MRSK.app.execute_in_new_container_over_ssh(cmd, host: MRSK.primary_host) } end when [:reuse] say "Get current version of running container...", :magenta unless [:version] using_version([:version] || current_running_version) do |version| say "Launching command with version #{version} from existing container...", :magenta on(MRSK.hosts) do |host| execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug puts_by_host host, capture_with_info(*MRSK.app.execute_in_existing_container(cmd)) end end else say "Get most recent version available as an image...", :magenta unless [:version] using_version([:version] || most_recent_version_available) do |version| say "Launching command with version #{version} from new container...", :magenta on(MRSK.hosts) do |host| execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug puts_by_host host, capture_with_info(*MRSK.app.execute_in_new_container(cmd)) end end end end |
#images ⇒ Object
105 106 107 |
# File 'lib/mrsk/cli/app.rb', line 105 def images on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_images) } end |
#logs ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mrsk/cli/app.rb', line 119 def logs # FIXME: Catch when app containers aren't running grep = [:grep] if [:follow] run_locally do info "Following logs on #{MRSK.primary_host}..." info MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep) exec MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep) end else since = [:since] lines = [:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set on(MRSK.hosts) do |host| begin puts_by_host host, capture_with_info(*MRSK.app.logs(since: since, lines: lines, grep: grep)) rescue SSHKit::Command::Failed puts_by_host host, "Nothing found" end end end end |
#remove ⇒ Object
145 146 147 148 |
# File 'lib/mrsk/cli/app.rb', line 145 def remove remove_containers remove_images end |
#remove_container(version) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/mrsk/cli/app.rb', line 151 def remove_container(version) on(MRSK.hosts) do execute *MRSK.auditor.record("app remove container #{version}"), verbosity: :debug execute *MRSK.app.remove_container(version: version) end end |
#remove_containers ⇒ Object
159 160 161 162 163 164 |
# File 'lib/mrsk/cli/app.rb', line 159 def remove_containers on(MRSK.hosts) do execute *MRSK.auditor.record("app remove containers"), verbosity: :debug execute *MRSK.app.remove_containers end end |
#remove_images ⇒ Object
167 168 169 170 171 172 |
# File 'lib/mrsk/cli/app.rb', line 167 def remove_images on(MRSK.hosts) do execute *MRSK.auditor.record("app remove images"), verbosity: :debug execute *MRSK.app.remove_images end end |