module Centurion::DeployDSL
Public Instance Methods
add_capability(new_cap_adds)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 23 def add_capability(new_cap_adds) if !valid_capability?(new_cap_adds) abort("Invalid capability addition #{new_cap_adds} specified.") end current = fetch(:cap_adds, []) set(:cap_adds, current << new_cap_adds) end
command(command)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 53 def command(command) set(:command, command) end
defined_health_check()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 126 def defined_health_check Centurion::HealthCheck.new(fetch(:health_check, method(:http_status_ok?)), fetch(:status_endpoint, '/'), fetch(:rolling_deploy_wait_time, 5), fetch(:rolling_deploy_retries, 24)) end
defined_restart_policy()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 133 def defined_restart_policy Centurion::Service::RestartPolicy.new(fetch(:restart_policy_name, 'on-failure'), fetch(:restart_policy_max_retry_count, 10)) end
defined_service()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 122 def defined_service Centurion::Service.from_env end
drop_capability(new_cap_drops)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 31 def drop_capability(new_cap_drops) if !valid_capability?(new_cap_drops) abort("Invalid capability drop #{new_cap_drops} specified.") end current = fetch(:cap_drops, []) set(:cap_drops, current << new_cap_drops) end
env_vars(new_vars)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 15 def env_vars(new_vars) current = fetch(:env_vars, {}) new_vars.each_pair do |new_key, new_value| current[new_key.to_s] = new_value.to_s end set(:env_vars, current) end
extra_host(ip, name)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 116 def extra_host(ip, name) current = fetch(:extra_hosts, []) current.push("#{name}:#{ip}") set(:extra_hosts, current) end
health_check(method)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 111 def health_check(method) abort("Health check expects a callable (lambda, proc, method), but #{method.class} was specified") unless method.respond_to?(:call) set(:health_check, method) end
host(hostname)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 39 def host(hostname) current = fetch(:hosts, []) current << hostname set(:hosts, current) end
host_port(port, options)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 64 def host_port(port, options) validate_options_keys(options, [ :host_ip, :container_port, :type ]) require_options_keys(options, [ :container_port ]) set(:port_bindings, fetch(:port_bindings, []).tap do |bindings| bindings << Centurion::Service::PortBinding.new(port, options[:container_port], options[:type] || 'tcp', options[:host_ip]) end) end
host_volume(volume, options)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 90 def host_volume(volume, options) validate_options_keys(options, [ :container_volume ]) require_options_keys(options, [ :container_volume ]) set(:binds, fetch(:binds, []).tap do |volumes| volumes << Centurion::Service::Volume.new(volume, options[:container_volume]) end) end
localhost()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 57 def localhost # DOCKER_HOST is like 'tcp://127.0.0.1:2375' docker_host_uri = URI.parse(ENV['DOCKER_HOST'] || "tcp://127.0.0.1") host_and_port = [docker_host_uri.host, docker_host_uri.port].compact.join(':') host(host_and_port) end
memory(memory)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 45 def memory(memory) set(:memory, memory) end
network_mode(mode)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 73 def network_mode(mode) if %w(bridge host).include?(mode) or mode =~ /container.*/ set(:network_mode, mode) else abort("invalid value for network_mode: #{mode}, value must be one of 'bridge', 'host', or 'container:<name|id>'") end end
on_each_docker_host(&block)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 7 def on_each_docker_host(&block) build_server_group.tap { |hosts| hosts.each { |host| block.call(host) } } end
on_first_docker_host(&block)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 11 def on_first_docker_host(&block) build_server_group.tap { |hosts| block.call(hosts.first) } end
public_port_for(port_bindings)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 81 def public_port_for(port_bindings) # port_bindings = [#<struct Centurion::Service::PortBinding # host_port=17090, # container_port=80, # type="tcp", # host_ip=nil>] port_bindings.first.host_port end
registry(type)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 107 def registry(type) set(:registry, type.to_s) end
Private Instance Methods
build_server_group()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 139 def build_server_group hosts, docker_path = fetch(:hosts, []), fetch(:docker_path) Centurion::DockerServerGroup.new(hosts, docker_path, build_tls_params) end
build_tls_params()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 171 def build_tls_params return {} unless fetch(:tlsverify) { tls: fetch(:tlsverify || tls_paths_available?), tlscacert: fetch(:tlscacert), tlscert: fetch(:tlscert), tlskey: fetch(:tlskey) } end
require_options_keys(options, required_keys)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 150 def require_options_keys(options, required_keys) missing = required_keys.reject { |k| options.keys.include?(k) } unless missing.empty? raise ArgumentError.new("Options must contain #{missing.inspect}") end end
tls_paths_available?()
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 167 def tls_paths_available? Centurion::DockerViaCli.tls_keys.all? { |key| fetch(key).present? } end
valid_capability?(capability)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 158 def valid_capability?(capability) %w(ALL SETPCAP SYS_MODULE SYS_RAWIO SYS_PACCT SYS_ADMIN SYS_NICE SYS_RESOURCE SYS_TIME SYS_TTY_CONFIG MKNOD AUDIT_WRITE AUDIT_CONTROL MAC_OVERRIDE MAC_ADMIN NET_ADMIN SYSLOG CHOWN NET_RAW DAC_OVERRIDE FOWNER DAC_READ_SEARCH FSETID KILL SETGID SETUID LINUX_IMMUTABLE NET_BIND_SERVICE NET_BROADCAST IPC_LOCK IPC_OWNER SYS_CHROOT SYS_PTRACE SYS_BOOT LEASE SETFCAP WAKE_ALARM BLOCK_SUSPEND).include?(capability) end
validate_options_keys(options, valid_keys)
click to toggle source
# File lib/centurion/deploy_dsl.rb, line 144 def validate_options_keys(options, valid_keys) unless options.keys.all? { |k| valid_keys.include?(k) } raise ArgumentError.new('Options passed with invalid key!') end end