Module: DockerCore::Command::Swarm
- Defined in:
- lib/docker_core.rb
Class Method Summary collapse
- .detect_services ⇒ Object
- .detect_swarm ⇒ Object
- .read_swarm ⇒ Object
- .service_actived(service) ⇒ Object
- .swarm_path ⇒ Object
- .swarm_status ⇒ Object
- .update_swarm(swarm = '') ⇒ Object
- .use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') ⇒ Object
- .write_swarm(swarm = '') ⇒ Object
Class Method Details
.detect_services ⇒ Object
72 73 74 |
# File 'lib/docker_core.rb', line 72 def self.detect_services return { docker: self.service_actived('docker') } end |
.detect_swarm ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/docker_core.rb', line 76 def self.detect_swarm swarm = self.read_swarm.to_sym detect = self.detect_services if detect.has_key?(swarm) && detect[swarm] return "#{swarm}" end index = detect.key(true) return "#{index}" end |
.read_swarm ⇒ Object
67 68 69 70 |
# File 'lib/docker_core.rb', line 67 def self.read_swarm file = self.swarm_path return File.exists?(file) ? File.read(file).strip : '' end |
.service_actived(service) ⇒ Object
54 55 56 |
# File 'lib/docker_core.rb', line 54 def self.service_actived(service) return 'active' == Process.capture("systemctl is-active #{service}").downcase end |
.swarm_path ⇒ Object
58 59 60 |
# File 'lib/docker_core.rb', line 58 def self.swarm_path return File.('~/.swarm') end |
.swarm_status ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/docker_core.rb', line 88 def self.swarm_status color = Color::GREEN detect = self.detect_swarm Color.echo("Swarm: #{detect}", color) Color.echo(self.detect_services.to_yaml, color) end |
.update_swarm(swarm = '') ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/docker_core.rb', line 97 def self.update_swarm(swarm = '') if false == swarm.empty? self.write_swarm(swarm) end swarm = self.detect_swarm self.write_swarm(swarm) if swarm.empty? swarm = 'none' end Color.echo("Swarm: #{swarm}", Color::GREEN) end |
.use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') ⇒ Object
49 50 51 |
# File 'lib/docker_core.rb', line 49 def self.use_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') return [registry, namespace, image].join('/') + ":#{tag}" end |
.write_swarm(swarm = '') ⇒ Object
63 64 65 |
# File 'lib/docker_core.rb', line 63 def self.write_swarm(swarm = '') return File.write(self.swarm_path, "#{swarm}\n") end |