Module: Neptuno::TTY::Config
- Includes:
- File
- Included in:
- CLI::Activate, CLI::Base, CLI::Execute, CLI::Init, CLI::Install, CLI::List, Docker::Attach, Docker::Log, Docker::Services, K8s::Attach, Overmind::Connect, Overmind::Start, Services::Add, Command
- Defined in:
- lib/neptuno/tty/config.rb
Overview
Wrapper class for TTY gem
Constant Summary
collapse
- TTY =
::TTY::Config.new
- ABORT_MESSAGE =
"fatal: there are no registered services. Add one with: neptuno services add"
Instance Method Summary
collapse
Methods included from File
#file, #in_service?, #make_service_files, #neptuno_path, #project, #service
Instance Method Details
#auto_restart_procs ⇒ Object
31
32
33
|
# File 'lib/neptuno/tty/config.rb', line 31
def auto_restart_procs
config.fetch("auto_restart_procs")
end
|
#config ⇒ Object
13
14
15
|
# File 'lib/neptuno/tty/config.rb', line 13
def config
TTY
end
|
41
42
43
|
# File 'lib/neptuno/tty/config.rb', line 41
def configured_services
config.fetch("configured_services")
end
|
#docker_compose_hash ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/neptuno/tty/config.rb', line 17
def docker_compose_hash
source = ::File.read("#{neptuno_path}/docker-compose.yml")
@@docker_compose ||= begin
YAML.load(source, aliases: true)
rescue ArgumentError
YAML.load(source)
end
@@docker_compose
end
|
#docker_compose_services ⇒ Object
27
28
29
|
# File 'lib/neptuno/tty/config.rb', line 27
def docker_compose_services
docker_compose_hash.fetch("services").keys.sort
end
|
#get_dependants(services = []) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/neptuno/tty/config.rb', line 72
def get_dependants(services = [])
return [] if services.empty?
deps = services.map { |service| docker_compose_hash.dig("services", service, "depends_on") }.flatten.uniq
[deps, get_dependants(deps - services)].flatten.compact.uniq
end
|
#healthy_services(status: nil) ⇒ Object
63
64
65
66
|
# File 'lib/neptuno/tty/config.rb', line 63
def healthy_services(status: nil)
data = status || json_services_status
data.select { |service| service.last.match(/\(healthy\)/) }
end
|
#json_services_status ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/neptuno/tty/config.rb', line 49
def json_services_status
neptuno_path = "./"
services = `cd #{neptuno_path} && docker compose ps --all --format json`.split("\n")
services.map do |line|
service = JSON.parse(line)
[service.dig("Service"), service.dig("Status")]
end
end
|
#running_services ⇒ Object
45
46
47
|
# File 'lib/neptuno/tty/config.rb', line 45
def running_services
`cd #{neptuno_path} && docker compose ps --status running --services`.split
end
|
#services ⇒ Object
35
36
37
38
39
|
# File 'lib/neptuno/tty/config.rb', line 35
def services
s = docker_compose_services
abort ABORT_MESSAGE if s.count.zero?
s
end
|
#services_with_procs ⇒ Object
68
69
70
|
# File 'lib/neptuno/tty/config.rb', line 68
def services_with_procs
`cd #{neptuno_path} && find procfiles -type f -size +0`.split.map { |x| x.split("/")[1] }
end
|
#starting_services(status: nil) ⇒ Object
58
59
60
61
|
# File 'lib/neptuno/tty/config.rb', line 58
def starting_services(status: nil)
data = status || json_services_status
data.select { |service| service.last.match(/starting\)|\(unhealthy\)/) }
end
|