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
- #bash(host:) ⇒ Object
- #ensure_local_file_present(local_file) ⇒ Object
- #exec(*command, interactive: false) ⇒ 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_exec(*command, interactive: false) ⇒ 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
#bash(host:) ⇒ Object
68 69 70 |
# File 'lib/mrsk/commands/accessory.rb', line 68 def bash(host:) exec_over_ssh "bash", host: host end |
#ensure_local_file_present(local_file) ⇒ Object
72 73 74 75 76 |
# File 'lib/mrsk/commands/accessory.rb', line 72 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 |
#exec(*command, interactive: false) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/mrsk/commands/accessory.rb', line 49 def exec(*command, interactive: false) docker :exec, ("-it" if interactive), *env_args, *volume_args, service_name, *command end |
#follow_logs(grep: nil) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/mrsk/commands/accessory.rb', line 42 def follow_logs(grep: nil) run_over_ssh pipe( docker(:logs, service_name, "-t", "-n", "10", "-f", "2>&1"), ("grep '#{grep}'" if grep) ).join(" "), host: host 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
36 37 38 39 40 |
# File 'lib/mrsk/commands/accessory.rb', line 36 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
82 83 84 |
# File 'lib/mrsk/commands/accessory.rb', line 82 def make_directory(path) [ :mkdir, "-p", path ] end |
#make_directory_for(remote_file) ⇒ Object
78 79 80 |
# File 'lib/mrsk/commands/accessory.rb', line 78 def make_directory_for(remote_file) make_directory Pathname.new(remote_file).dirname.to_s end |
#remove_container ⇒ Object
90 91 92 |
# File 'lib/mrsk/commands/accessory.rb', line 90 def remove_container docker :container, :prune, "-f", *service_filter end |
#remove_image ⇒ Object
94 95 96 |
# File 'lib/mrsk/commands/accessory.rb', line 94 def remove_image docker :image, :prune, "-a", "-f", *service_filter end |
#remove_service_directory ⇒ Object
86 87 88 |
# File 'lib/mrsk/commands/accessory.rb', line 86 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_exec(*command, interactive: false) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/mrsk/commands/accessory.rb', line 58 def run_exec(*command, interactive: false) docker :run, ("-it" if interactive), "--rm", *env_args, *volume_args, image, *command 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 |