Class: Kamal::Commands::Accessory
- Defined in:
- lib/kamal/commands/accessory.rb
Constant Summary
Constants inherited from Base
Base::DOCKER_HEALTH_STATUS_FORMAT
Instance Attribute Summary collapse
-
#accessory_config ⇒ Object
readonly
Returns the value of attribute accessory_config.
Attributes inherited from Base
Instance Method Summary collapse
- #ensure_env_directory ⇒ Object
- #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(timestamps: true, grep: nil, grep_options: nil) ⇒ Object
- #info ⇒ Object
-
#initialize(config, name:) ⇒ Accessory
constructor
A new instance of Accessory.
- #logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
- #remove_container ⇒ Object
- #remove_image ⇒ Object
- #remove_service_directory ⇒ Object
- #run ⇒ Object
- #run_over_ssh(command) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from Base
#container_id_for, #make_directory, #make_directory_for, #remove_directory, #remove_file
Constructor Details
#initialize(config, name:) ⇒ Accessory
Returns a new instance of Accessory.
8 9 10 11 |
# File 'lib/kamal/commands/accessory.rb', line 8 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.
2 3 4 |
# File 'lib/kamal/commands/accessory.rb', line 2 def accessory_config @accessory_config end |
Instance Method Details
#ensure_env_directory ⇒ Object
105 106 107 |
# File 'lib/kamal/commands/accessory.rb', line 105 def ensure_env_directory make_directory env_directory end |
#ensure_local_file_present(local_file) ⇒ Object
87 88 89 90 91 |
# File 'lib/kamal/commands/accessory.rb', line 87 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
56 57 58 59 60 61 |
# File 'lib/kamal/commands/accessory.rb', line 56 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
74 75 76 |
# File 'lib/kamal/commands/accessory.rb', line 74 def execute_in_existing_container_over_ssh(*command) run_over_ssh execute_in_existing_container(*command, interactive: true) end |
#execute_in_new_container(*command, interactive: false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/kamal/commands/accessory.rb', line 63 def execute_in_new_container(*command, interactive: false) docker :run, ("-it" if interactive), "--rm", *network_args, *env_args, *volume_args, image, *command end |
#execute_in_new_container_over_ssh(*command) ⇒ Object
78 79 80 |
# File 'lib/kamal/commands/accessory.rb', line 78 def execute_in_new_container_over_ssh(*command) run_over_ssh execute_in_new_container(*command, interactive: true) end |
#follow_logs(timestamps: true, grep: nil, grep_options: nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/kamal/commands/accessory.rb', line 48 def follow_logs(timestamps: true, grep: nil, grep_options: nil) run_over_ssh \ pipe \ docker(:logs, service_name, ("--timestamps" if ), "--tail", "10", "--follow", "2>&1"), (%(grep "#{grep}"#{" #{}" if }) if grep) end |
#info ⇒ Object
37 38 39 |
# File 'lib/kamal/commands/accessory.rb', line 37 def info docker :ps, *service_filter end |
#logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/kamal/commands/accessory.rb', line 42 def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) pipe \ docker(:logs, service_name, (" --since #{since}" if since), (" --tail #{lines}" if lines), ("--timestamps" if ), "2>&1"), ("grep '#{grep}'#{" #{}" if }" if grep) end |
#remove_container ⇒ Object
97 98 99 |
# File 'lib/kamal/commands/accessory.rb', line 97 def remove_container docker :container, :prune, "--force", *service_filter end |
#remove_image ⇒ Object
101 102 103 |
# File 'lib/kamal/commands/accessory.rb', line 101 def remove_image docker :image, :rm, "--force", image end |
#remove_service_directory ⇒ Object
93 94 95 |
# File 'lib/kamal/commands/accessory.rb', line 93 def remove_service_directory [ :rm, "-rf", service_name ] end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kamal/commands/accessory.rb', line 13 def run docker :run, "--name", service_name, "--detach", "--restart", "unless-stopped", *network_args, *config.logging_args, *publish_args, *env_args, *volume_args, *label_args, *option_args, image, cmd end |
#run_over_ssh(command) ⇒ Object
82 83 84 |
# File 'lib/kamal/commands/accessory.rb', line 82 def run_over_ssh(command) super command, host: hosts.first end |
#start ⇒ Object
29 30 31 |
# File 'lib/kamal/commands/accessory.rb', line 29 def start docker :container, :start, service_name end |
#stop ⇒ Object
33 34 35 |
# File 'lib/kamal/commands/accessory.rb', line 33 def stop docker :container, :stop, service_name end |