module DockerCore::Swarm
Public Class Methods
capture_command(*arguments, environment: {}, bind: {}, throw: false, wait: 0, strip: true, echo: false)
click to toggle source
noinspection RubyUnusedLocalVariable
@param [Array] arguments @param [Hash] environment @param [Hash] bind @param [Boolean] throw @param [Numeric] wait @param [Boolean] strip @param [Boolean] echo @return [String]
# File lib/docker_core.rb, line 237 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)
click to toggle source
@see github.com/moby/moby/issues/31564 @param [String] name @param [Boolean] echo
# File lib/docker_core.rb, line 127 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()
click to toggle source
# File lib/docker_core.rb, line 108 def self.deploy_path return File.expand_path('~/deploy') end
detect_orchestrator()
click to toggle source
# File lib/docker_core.rb, line 171 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()
click to toggle source
# File lib/docker_core.rb, line 167 def self.detect_services return { docker: Shell.is_active_unit('docker') } end
from_image(image, registry: REGISTRY, namespace: NAMESPACE, tag: 'latest')
click to toggle source
@param [String] image @param [String] registry @param [String] namespace @param [String] tag
# 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()
click to toggle source
noinspection RubyClassVariableUsageInspection
# File lib/docker_core.rb, line 254 def self.orchestrator @@orchestrator ||= self.detect_orchestrator return "#{@@orchestrator}" end
pair_paths(base, relative = '')
click to toggle source
@param [String] base @param [String] relative
# File lib/docker_core.rb, line 207 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])
click to toggle source
@param [Array<String>] arguments @param [Array<String>] folders
# File lib/docker_core.rb, line 219 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()
click to toggle source
# File lib/docker_core.rb, line 116 def self.profile_path return File.realpath('profile.sh', self.deploy_path) end
read_swarm()
click to toggle source
# File lib/docker_core.rb, line 162 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)
click to toggle source
noinspection RubyUnusedLocalVariable
@param [Array] arguments @param [Hash] environment @param [Hash] bind @param [Boolean] throw @param [Numeric] wait @param [Boolean] echo @return [Boolean]
# File lib/docker_core.rb, line 249 def self.run_command(*arguments, environment: {}, bind: {}, throw: true, wait: 0, echo: true) Error.no_method(__method__) end
runner_path()
click to toggle source
# File lib/docker_core.rb, line 120 def self.runner_path return File.realpath('runner.rb', self.deploy_path) end
swarm_path()
click to toggle source
# File lib/docker_core.rb, line 112 def self.swarm_path return File.expand_path('~/.swarm') end
swarm_status()
click to toggle source
# File lib/docker_core.rb, line 183 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 = '')
click to toggle source
@param [String] orchestrator
# File lib/docker_core.rb, line 190 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 = '')
click to toggle source
@param [String] swarm
# File lib/docker_core.rb, line 158 def self.write_swarm(swarm = '') return File.write(self.swarm_path, "#{swarm}\n") end