Class: Mrsk::Commands::App
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #bash(host:) ⇒ Object
- #console(host:) ⇒ Object
- #current_container_id ⇒ Object
- #exec(*command, interactive: false) ⇒ Object
- #exec_over_ssh(*command, host:) ⇒ Object
- #follow_logs(host:, grep: nil) ⇒ Object
- #info ⇒ Object
- #list_containers ⇒ Object
- #logs(since: nil, lines: nil, grep: nil) ⇒ Object
- #remove_containers ⇒ Object
- #remove_images ⇒ Object
- #run(role: :web) ⇒ Object
- #run_exec(*command, interactive: false) ⇒ Object
- #start(version: config.version) ⇒ Object
- #stop ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Mrsk::Commands::Base
Instance Method Details
#bash(host:) ⇒ Object
79 80 81 |
# File 'lib/mrsk/commands/app.rb', line 79 def bash(host:) exec_over_ssh "bash", host: host end |
#console(host:) ⇒ Object
75 76 77 |
# File 'lib/mrsk/commands/app.rb', line 75 def console(host:) exec_over_ssh "bin/rails", "c", host: host end |
#current_container_id ⇒ Object
23 24 25 |
# File 'lib/mrsk/commands/app.rb', line 23 def current_container_id docker :ps, "-q", *service_filter end |
#exec(*command, interactive: false) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/mrsk/commands/app.rb', line 42 def exec(*command, interactive: false) docker :exec, ("-it" if interactive), *rails_master_key_arg, *config.env_args, *config.volume_args, config.service_with_version, *command end |
#exec_over_ssh(*command, host:) ⇒ Object
63 64 65 |
# File 'lib/mrsk/commands/app.rb', line 63 def exec_over_ssh(*command, host:) run_over_ssh run_exec(*command, interactive: true).join(" "), host: host end |
#follow_logs(host:, grep: nil) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/mrsk/commands/app.rb', line 67 def follow_logs(host:, grep: nil) run_over_ssh pipe( current_container_id, "xargs docker logs -t -n 10 -f 2>&1", ("grep '#{grep}'" if grep) ).join(" "), host: host end |
#info ⇒ Object
31 32 33 |
# File 'lib/mrsk/commands/app.rb', line 31 def info docker :ps, *service_filter end |
#list_containers ⇒ Object
83 84 85 |
# File 'lib/mrsk/commands/app.rb', line 83 def list_containers docker :container, :ls, "-a", *service_filter end |
#logs(since: nil, lines: nil, grep: nil) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/mrsk/commands/app.rb', line 35 def logs(since: nil, lines: nil, grep: nil) pipe \ current_container_id, "xargs docker logs#{" --since #{since}" if since}#{" -n #{lines}" if lines} -t 2>&1", ("grep '#{grep}'" if grep) end |
#remove_containers ⇒ Object
87 88 89 |
# File 'lib/mrsk/commands/app.rb', line 87 def remove_containers docker :container, :prune, "-f", *service_filter end |
#remove_images ⇒ Object
91 92 93 |
# File 'lib/mrsk/commands/app.rb', line 91 def remove_images docker :image, :prune, "-a", "-f", *service_filter end |
#run(role: :web) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mrsk/commands/app.rb', line 4 def run(role: :web) role = config.role(role) docker :run, "-d", "--restart unless-stopped", "--name", config.service_with_version, *rails_master_key_arg, *role.env_args, *config.volume_args, *role.label_args, config.absolute_image, role.cmd end |
#run_exec(*command, interactive: false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mrsk/commands/app.rb', line 52 def run_exec(*command, interactive: false) docker :run, ("-it" if interactive), "--rm", *rails_master_key_arg, *config.env_args, *config.volume_args, config.absolute_image, *command end |
#start(version: config.version) ⇒ Object
19 20 21 |
# File 'lib/mrsk/commands/app.rb', line 19 def start(version: config.version) docker :start, "#{config.service}-#{version}" end |
#stop ⇒ Object
27 28 29 |
# File 'lib/mrsk/commands/app.rb', line 27 def stop pipe current_container_id, "xargs docker stop" end |