Class: Dash::Commands::Accessory
- Inherits:
-
Base
- Object
- Base
- Dash::Commands::Accessory
show all
- Includes:
- Proxy
- Defined in:
- lib/dash/commands/accessory.rb
Defined Under Namespace
Modules: Proxy
Constant Summary
Constants inherited
from Base
Base::DOCKER_HEALTH_STATUS_FORMAT, Base::EXEC_PROBE_FAILED, Base::NO_HEALTHCHECK, Base::READINESS_PROGRESS_PREFIX, Base::READY_STATUSES
Instance Attribute Summary collapse
Attributes inherited from Base
#config
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(all: false, quiet: false) ⇒ Object
-
#initialize(config, name:) ⇒ Accessory
constructor
A new instance of Accessory.
-
#logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
-
#pull_image ⇒ Object
-
#remove_container ⇒ Object
-
#remove_image ⇒ Object
-
#remove_service_directory ⇒ Object
-
#run(host: nil) ⇒ Object
-
#run_over_ssh(command) ⇒ Object
-
#start ⇒ Object
-
#stop ⇒ Object
Methods included from Proxy
#deploy, #remove
Methods inherited from Base
#confirmed_empty?, #container_id_for, #ensure_docker_installed, #ensure_run_directory, #make_directory, #make_directory_for, #read_file, #remove_directory, #remove_file
Constructor Details
#initialize(config, name:) ⇒ Accessory
Returns a new instance of Accessory.
10
11
12
13
|
# File 'lib/dash/commands/accessory.rb', line 10
def initialize(config, name:)
super(config)
@accessory_config = config.accessory(name)
end
|
Instance Attribute Details
#accessory_config ⇒ Object
Returns the value of attribute accessory_config.
4
5
6
|
# File 'lib/dash/commands/accessory.rb', line 4
def accessory_config
@accessory_config
end
|
Instance Method Details
#ensure_env_directory ⇒ Object
110
111
112
|
# File 'lib/dash/commands/accessory.rb', line 110
def ensure_env_directory
make_directory env_directory
end
|
#ensure_local_file_present(local_file) ⇒ Object
88
89
90
91
92
|
# File 'lib/dash/commands/accessory.rb', line 88
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
57
58
59
60
61
62
|
# File 'lib/dash/commands/accessory.rb', line 57
def execute_in_existing_container(*command, interactive: false)
docker :exec,
(docker_interactive_args if interactive),
service_name,
*command
end
|
#execute_in_existing_container_over_ssh(*command) ⇒ Object
76
77
78
|
# File 'lib/dash/commands/accessory.rb', line 76
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
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/dash/commands/accessory.rb', line 64
def execute_in_new_container(*command, interactive: false)
docker :run,
(docker_interactive_args if interactive),
"--rm",
*network_args,
*env_args,
*volume_args,
*option_args,
image,
*command
end
|
#execute_in_new_container_over_ssh(*command) ⇒ Object
80
81
82
|
# File 'lib/dash/commands/accessory.rb', line 80
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
50
51
52
53
54
55
|
# File 'lib/dash/commands/accessory.rb', line 50
def follow_logs(timestamps: true, grep: nil, grep_options: nil)
run_over_ssh \
pipe \
docker(:logs, service_name, ("--timestamps" if timestamps), "--tail", "10", "--follow", "2>&1"),
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
end
|
#info(all: false, quiet: false) ⇒ Object
40
41
42
|
# File 'lib/dash/commands/accessory.rb', line 40
def info(all: false, quiet: false)
docker :ps, *("-a" if all), *("-q" if quiet), *service_filter
end
|
#logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
44
45
46
47
48
|
# File 'lib/dash/commands/accessory.rb', line 44
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 timestamps), "2>&1"),
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
end
|
#pull_image ⇒ Object
94
95
96
|
# File 'lib/dash/commands/accessory.rb', line 94
def pull_image
docker :image, :pull, image
end
|
#remove_container ⇒ Object
102
103
104
|
# File 'lib/dash/commands/accessory.rb', line 102
def remove_container
docker :container, :prune, "--force", *service_filter
end
|
#remove_image ⇒ Object
106
107
108
|
# File 'lib/dash/commands/accessory.rb', line 106
def remove_image
docker :image, :rm, "--force", image
end
|
#remove_service_directory ⇒ Object
98
99
100
|
# File 'lib/dash/commands/accessory.rb', line 98
def remove_service_directory
[ :rm, "-rf", service_name ]
end
|
#run(host: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/dash/commands/accessory.rb', line 15
def run(host: nil)
docker :run,
"--name", service_name,
"--detach",
"--restart", restart_policy,
*network_args,
*config.logging_args,
*publish_args,
*([ "--env", "DASH_HOST=\"#{host}\"", "--env", "KAMAL_HOST=\"#{host}\"" ] if host),
*env_args,
*volume_args,
*label_args,
*option_args,
image,
cmd
end
|
#run_over_ssh(command) ⇒ Object
84
85
86
|
# File 'lib/dash/commands/accessory.rb', line 84
def run_over_ssh(command)
super command, host: hosts.first
end
|
#start ⇒ Object
32
33
34
|
# File 'lib/dash/commands/accessory.rb', line 32
def start
docker :container, :start, service_name
end
|
#stop ⇒ Object
36
37
38
|
# File 'lib/dash/commands/accessory.rb', line 36
def stop
docker :container, :stop, service_name
end
|