Module: DockerCore::Swarm
- Defined in:
- lib/docker_core.rb
Class Method Summary collapse
- .capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false) ⇒ String
- .deploy_path ⇒ Object
- .detect_orchestrator ⇒ Object
- .detect_services ⇒ Object
- .from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') ⇒ Object
-
.orchestrator ⇒ Object
noinspection RubyClassVariableUsageInspection.
- .pair_paths(base, relative = '') ⇒ Object
- .read_swarm ⇒ Object
- .run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) ⇒ Boolean
- .swarm_path ⇒ Object
- .swarm_status ⇒ Object
- .update_swarm(swarm = '') ⇒ Object
- .write_swarm(swarm = '') ⇒ Object
Class Method Details
.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false) ⇒ String
134 135 136 |
# File 'lib/docker_core.rb', line 134 def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false) raise "No implement #{__method__} method" end |
.deploy_path ⇒ Object
58 59 60 |
# File 'lib/docker_core.rb', line 58 def self.deploy_path return File.('~/deploy') end |
.detect_orchestrator ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/docker_core.rb', line 80 def self.detect_orchestrator 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 |
.detect_services ⇒ Object
76 77 78 |
# File 'lib/docker_core.rb', line 76 def self.detect_services return { docker: Shell.is_active_unit('docker') } end |
.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') ⇒ Object
54 55 56 |
# File 'lib/docker_core.rb', line 54 def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') return "#{registry}/#{namespace}/#{image}:#{tag}" end |
.orchestrator ⇒ Object
noinspection RubyClassVariableUsageInspection
150 151 152 153 |
# File 'lib/docker_core.rb', line 150 def self.orchestrator @@orchestrator ||= self.detect_orchestrator return "#{@@orchestrator}" end |
.pair_paths(base, relative = '') ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/docker_core.rb', line 116 def self.pair_paths(base, relative = '') items = {} { inside: base, outside: Dir.pwd }.each do |key, value| items[key] = File.join(value, relative) end return items end |
.read_swarm ⇒ Object
71 72 73 74 |
# File 'lib/docker_core.rb', line 71 def self.read_swarm file = self.swarm_path return File.exists?(file) ? File.read(file).strip : '' end |
.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) ⇒ Boolean
145 146 147 |
# File 'lib/docker_core.rb', line 145 def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) raise "No implement #{__method__} method" end |
.swarm_path ⇒ Object
62 63 64 |
# File 'lib/docker_core.rb', line 62 def self.swarm_path return File.('~/.swarm') end |
.swarm_status ⇒ Object
92 93 94 95 96 |
# File 'lib/docker_core.rb', line 92 def self.swarm_status color = Color::GREEN Color.echo("Swarm: #{self.detect_orchestrator}", color) Color.echo(self.detect_services.to_yaml, color) end |
.update_swarm(swarm = '') ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/docker_core.rb', line 99 def self.update_swarm(swarm = '') if false == swarm.empty? self.write_swarm(swarm) end orchestrator = self.detect_orchestrator self.write_swarm(orchestrator) if orchestrator.empty? orchestrator = '<none>' end Color.echo("Swarm: #{orchestrator}", Color::GREEN) end |
.write_swarm(swarm = '') ⇒ Object
67 68 69 |
# File 'lib/docker_core.rb', line 67 def self.write_swarm(swarm = '') return File.write(self.swarm_path, "#{swarm}\n") end |