Class: Mrsk::Commands::App
- Inherits:
-
Base
- Object
- Base
- Mrsk::Commands::App
show all
- Defined in:
- lib/mrsk/commands/app.rb
Constant Summary
Constants inherited
from Base
Base::MAX_LOG_SIZE
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
#container_id_for, #initialize, #run_over_ssh
Instance Method Details
#all_versions_from_available_containers ⇒ Object
92
93
94
95
96
|
# File 'lib/mrsk/commands/app.rb', line 92
def all_versions_from_available_containers
pipe \
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
"head -n 1"
end
|
#current_container_id ⇒ Object
74
75
76
|
# File 'lib/mrsk/commands/app.rb', line 74
def current_container_id
docker :ps, "-q", *service_filter
end
|
#current_running_version ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/mrsk/commands/app.rb', line 78
def current_running_version
pipe \
docker(:ps, "--filter", "label=service=#{config.service}", "--format", '"{{.Names}}"'),
%(sed 's/-/\\n/g'),
"tail -n 1"
end
|
#execute_in_existing_container(*command, interactive: false) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/mrsk/commands/app.rb', line 48
def execute_in_existing_container(*command, interactive: false)
docker :exec,
("-it" if interactive),
config.service_with_version,
*command
end
|
#execute_in_existing_container_over_ssh(*command, host:) ⇒ Object
65
66
67
|
# File 'lib/mrsk/commands/app.rb', line 65
def execute_in_existing_container_over_ssh(*command, host:)
run_over_ssh execute_in_existing_container(*command, interactive: true), host: host
end
|
#execute_in_new_container(*command, interactive: false) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/mrsk/commands/app.rb', line 55
def execute_in_new_container(*command, interactive: false)
docker :run,
("-it" if interactive),
"--rm",
*config.env_args,
*config.volume_args,
config.absolute_image,
*command
end
|
#execute_in_new_container_over_ssh(*command, host:) ⇒ Object
69
70
71
|
# File 'lib/mrsk/commands/app.rb', line 69
def execute_in_new_container_over_ssh(*command, host:)
run_over_ssh execute_in_new_container(*command, interactive: true), host: host
end
|
#follow_logs(host:, grep: nil) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/mrsk/commands/app.rb', line 37
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)
),
host: host
end
|
#info ⇒ Object
25
26
27
|
# File 'lib/mrsk/commands/app.rb', line 25
def info
docker :ps, *service_filter
end
|
#list_container_names ⇒ Object
103
104
105
|
# File 'lib/mrsk/commands/app.rb', line 103
def list_container_names
[ *list_containers, "--format", "'{{ .Names }}'" ]
end
|
#list_containers ⇒ Object
99
100
101
|
# File 'lib/mrsk/commands/app.rb', line 99
def list_containers
docker :container, :ls, "-a", *service_filter
end
|
#list_images ⇒ Object
117
118
119
|
# File 'lib/mrsk/commands/app.rb', line 117
def list_images
docker :image, :ls, config.repository
end
|
#logs(since: nil, lines: nil, grep: nil) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/mrsk/commands/app.rb', line 30
def logs(since: nil, lines: nil, grep: nil)
pipe \
current_container_id,
"xargs docker logs#{" --since #{since}" if since}#{" -n #{lines}" if lines} 2>&1",
("grep '#{grep}'" if grep)
end
|
#most_recent_version_from_available_images ⇒ Object
86
87
88
89
90
|
# File 'lib/mrsk/commands/app.rb', line 86
def most_recent_version_from_available_images
pipe \
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
"head -n 1"
end
|
#remove_container(version:) ⇒ Object
107
108
109
110
111
|
# File 'lib/mrsk/commands/app.rb', line 107
def remove_container(version:)
pipe \
container_id_for(container_name: service_with_version(version)),
xargs(docker(:container, :rm))
end
|
#remove_containers ⇒ Object
113
114
115
|
# File 'lib/mrsk/commands/app.rb', line 113
def remove_containers
docker :container, :prune, "-f", *service_filter
end
|
#remove_images ⇒ Object
121
122
123
|
# File 'lib/mrsk/commands/app.rb', line 121
def remove_images
docker :image, :prune, "-a", "-f", *service_filter
end
|
#run(role: :web) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/mrsk/commands/app.rb', line 2
def run(role: :web)
role = config.role(role)
docker :run,
"-d",
"--restart unless-stopped",
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
"--name", service_with_version,
*role.env_args,
*config.volume_args,
*role.label_args,
config.absolute_image,
role.cmd
end
|
#start ⇒ Object
17
18
19
|
# File 'lib/mrsk/commands/app.rb', line 17
def start
docker :start, service_with_version
end
|
#stop ⇒ Object
21
22
23
|
# File 'lib/mrsk/commands/app.rb', line 21
def stop
pipe current_container_id, xargs(docker(:stop))
end
|