Class: Mrsk::Commands::Accessory
- Defined in:
- lib/mrsk/commands/accessory.rb
Instance Attribute Summary collapse
-
#accessory_config ⇒ Object
readonly
Returns the value of attribute accessory_config.
Attributes inherited from Base
Instance Method Summary collapse
- #ensure_local_file_present(local_file) ⇒ Object
- #execute_in_existing_container(*command, interactive: false) ⇒ Object
- #execute_in_existing_container_over_ssh(*command) ⇒ Object
- #execute_in_new_container(*command, interactive: false) ⇒ Object
- #execute_in_new_container_over_ssh(*command) ⇒ Object
- #follow_logs(grep: nil) ⇒ Object
- #info ⇒ Object
-
#initialize(config, name:) ⇒ Accessory
constructor
A new instance of Accessory.
- #logs(since: nil, lines: nil, grep: nil) ⇒ Object
- #make_directory(path) ⇒ Object
- #make_directory_for(remote_file) ⇒ Object
- #remove_container ⇒ Object
- #remove_image ⇒ Object
- #remove_service_directory ⇒ Object
- #run ⇒ Object
- #run_over_ssh(command) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config, name:) ⇒ Accessory
Returns a new instance of Accessory.
7 8 9 10 |
# File 'lib/mrsk/commands/accessory.rb', line 7 def initialize(config, name:) super(config) @accessory_config = config.accessory(name) end |
Instance Attribute Details
#accessory_config ⇒ Object (readonly)
Returns the value of attribute accessory_config.
4 5 6 |
# File 'lib/mrsk/commands/accessory.rb', line 4 def accessory_config @accessory_config end |
Instance Method Details
#ensure_local_file_present(local_file) ⇒ Object
81 82 83 84 85 |
# File 'lib/mrsk/commands/accessory.rb', line 81 def ensure_local_file_present(local_file) if !local_file.is_a?(StringIO) && !Pathname.new(local_file).exist? raise "Missing file: #{local_file}" end end |
#execute_in_existing_container(*command, interactive: false) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/mrsk/commands/accessory.rb', line 51 def execute_in_existing_container(*command, interactive: false) docker :exec, ("-it" if interactive), service_name, *command end |
#execute_in_existing_container_over_ssh(*command) ⇒ Object
68 69 70 |
# File 'lib/mrsk/commands/accessory.rb', line 68 def execute_in_existing_container_over_ssh(*command) run_over_ssh execute_in_existing_container(*command, interactive: true).join(" ") end |
#execute_in_new_container(*command, interactive: false) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/mrsk/commands/accessory.rb', line 58 def execute_in_new_container(*command, interactive: false) docker :run, ("-it" if interactive), "--rm", *env_args, *volume_args, image, *command end |
#execute_in_new_container_over_ssh(*command) ⇒ Object
72 73 74 |
# File 'lib/mrsk/commands/accessory.rb', line 72 def execute_in_new_container_over_ssh(*command) run_over_ssh execute_in_new_container(*command, interactive: true).join(" ") end |
#follow_logs(grep: nil) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/mrsk/commands/accessory.rb', line 43 def follow_logs(grep: nil) run_over_ssh pipe( docker(:logs, service_name, "-t", "-n", "10", "-f", "2>&1"), (%(grep "#{grep}") if grep) ).join(" ") end |
#info ⇒ Object
32 33 34 |
# File 'lib/mrsk/commands/accessory.rb', line 32 def info docker :ps, *service_filter end |
#logs(since: nil, lines: nil, grep: nil) ⇒ Object
37 38 39 40 41 |
# File 'lib/mrsk/commands/accessory.rb', line 37 def logs(since: nil, lines: nil, grep: nil) pipe \ docker(:logs, service_name, (" --since #{since}" if since), (" -n #{lines}" if lines), "-t", "2>&1"), ("grep '#{grep}'" if grep) end |
#make_directory(path) ⇒ Object
91 92 93 |
# File 'lib/mrsk/commands/accessory.rb', line 91 def make_directory(path) [ :mkdir, "-p", path ] end |
#make_directory_for(remote_file) ⇒ Object
87 88 89 |
# File 'lib/mrsk/commands/accessory.rb', line 87 def make_directory_for(remote_file) make_directory Pathname.new(remote_file).dirname.to_s end |
#remove_container ⇒ Object
99 100 101 |
# File 'lib/mrsk/commands/accessory.rb', line 99 def remove_container docker :container, :prune, "-f", *service_filter end |
#remove_image ⇒ Object
103 104 105 |
# File 'lib/mrsk/commands/accessory.rb', line 103 def remove_image docker :image, :prune, "-a", "-f", *service_filter end |
#remove_service_directory ⇒ Object
95 96 97 |
# File 'lib/mrsk/commands/accessory.rb', line 95 def remove_service_directory [ :rm, "-rf", service_name ] end |
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mrsk/commands/accessory.rb', line 12 def run docker :run, "--name", service_name, "-d", "--restart", "unless-stopped", "-p", port, *env_args, *volume_args, *label_args, image end |
#run_over_ssh(command) ⇒ Object
76 77 78 |
# File 'lib/mrsk/commands/accessory.rb', line 76 def run_over_ssh(command) super command, host: host end |
#start ⇒ Object
24 25 26 |
# File 'lib/mrsk/commands/accessory.rb', line 24 def start docker :container, :start, service_name end |
#stop ⇒ Object
28 29 30 |
# File 'lib/mrsk/commands/accessory.rb', line 28 def stop docker :container, :stop, service_name end |