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
noinspection RubyUnusedLocalVariable.
- .check_name(name, echo: false) ⇒ Object
- .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
- .prepare_folders(*services, folders: %w[stack volume]) ⇒ Object
- .profile_path ⇒ Object
- .read_swarm ⇒ Object
-
.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) ⇒ Boolean
noinspection RubyUnusedLocalVariable.
- .runner_path ⇒ Object
- .swarm_path ⇒ Object
- .swarm_status ⇒ Object
- .update_swarm(orchestrator = '') ⇒ Object
- .write_swarm(swarm = '') ⇒ Object
Class Method Details
.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false) ⇒ String
noinspection RubyUnusedLocalVariable
238 239 240 |
# File 'lib/docker_core.rb', line 238 def self.capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false) Error.no_method(__method__) end |
.check_name(name, echo: false) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/docker_core.rb', line 128 def self.check_name(name, echo: false) color = Color::YELLOW name = "#{name}" items = name.chars if items.empty? || 63 < items.length if echo Color.echo("'#{name}' should be between 1 and 63 characters long", color) end return false end if [items.first, items.last].include?('-') if echo Color.echo("'#{name}' should not start or end with a hyphen(-)", color) end return false end test = name.match?(/^[a-zA-Z0-9-]+$/) if false == test && echo Color.echo("'#{name}' should be a-z or A-Z or 0-9 and hyphen (-)", color) end return test end |
.deploy_path ⇒ Object
108 109 110 |
# File 'lib/docker_core.rb', line 108 def self.deploy_path return File.('~/deploy') end |
.detect_orchestrator ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/docker_core.rb', line 172 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
168 169 170 |
# File 'lib/docker_core.rb', line 168 def self.detect_services return { docker: Shell.is_active_unit('docker') } end |
.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') ⇒ Object
104 105 106 |
# File 'lib/docker_core.rb', line 104 def self.from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest') return "#{registry}/#{namespace}/#{image}:#{tag}" end |
.orchestrator ⇒ Object
noinspection RubyClassVariableUsageInspection
255 256 257 258 |
# File 'lib/docker_core.rb', line 255 def self.orchestrator @@orchestrator ||= self.detect_orchestrator return "#{@@orchestrator}" end |
.pair_paths(base, relative = '') ⇒ Object
208 209 210 211 212 213 214 215 216 |
# File 'lib/docker_core.rb', line 208 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 |
.prepare_folders(*services, folders: %w[stack volume]) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/docker_core.rb', line 220 def self.prepare_folders(*services, folders: %w[stack volume]) deploy = self.deploy_path folders.each do |folder| services.each do |service| FileUtils.mkdir_p(File.join(deploy, folder, service)) end end end |
.profile_path ⇒ Object
116 117 118 |
# File 'lib/docker_core.rb', line 116 def self.profile_path return File.realpath('profile.sh', self.deploy_path) end |
.read_swarm ⇒ Object
163 164 165 166 |
# File 'lib/docker_core.rb', line 163 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
noinspection RubyUnusedLocalVariable
250 251 252 |
# File 'lib/docker_core.rb', line 250 def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) Error.no_method(__method__) end |
.runner_path ⇒ Object
120 121 122 |
# File 'lib/docker_core.rb', line 120 def self.runner_path return File.realpath('runner.rb', self.deploy_path) end |
.swarm_path ⇒ Object
112 113 114 |
# File 'lib/docker_core.rb', line 112 def self.swarm_path return File.('~/.swarm') end |
.swarm_status ⇒ Object
184 185 186 187 188 |
# File 'lib/docker_core.rb', line 184 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(orchestrator = '') ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/docker_core.rb', line 191 def self.update_swarm(orchestrator = '') if false == orchestrator.empty? self.write_swarm(orchestrator) 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
159 160 161 |
# File 'lib/docker_core.rb', line 159 def self.write_swarm(swarm = '') return File.write(self.swarm_path, "#{swarm}\n") end |