Module: Centurion::DeployDSL
- Defined in:
- lib/centurion/deploy_dsl.rb
Instance Method Summary collapse
- #add_capability(new_cap_adds) ⇒ Object
- #command(command) ⇒ Object
- #cpu_shares(cpu_shares) ⇒ Object
- #defined_health_check ⇒ Object
- #defined_restart_policy ⇒ Object
- #defined_service ⇒ Object
- #drop_capability(new_cap_drops) ⇒ Object
- #env_vars(new_vars) ⇒ Object
- #extra_host(ip, name) ⇒ Object
- #get_current_tags_for(image) ⇒ Object
- #health_check(method) ⇒ Object
- #host(hostname) ⇒ Object
- #host_port(port, options) ⇒ Object
- #host_volume(volume, options) ⇒ Object
- #localhost ⇒ Object
- #memory(memory) ⇒ Object
- #network_mode(mode) ⇒ Object
- #on_each_docker_host(&block) ⇒ Object
- #on_first_docker_host(&block) ⇒ Object
- #public_port_for(port_bindings) ⇒ Object
- #registry(type) ⇒ Object
Instance Method Details
#add_capability(new_cap_adds) ⇒ Object
23 24 25 26 27 28 29 |
# 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) ⇒ Object
53 54 55 |
# File 'lib/centurion/deploy_dsl.rb', line 53 def command(command) set(:command, command) end |
#cpu_shares(cpu_shares) ⇒ Object
49 50 51 |
# File 'lib/centurion/deploy_dsl.rb', line 49 def cpu_shares(cpu_shares) set(:cpu_shares, cpu_shares) end |
#defined_health_check ⇒ Object
126 127 128 129 130 131 |
# 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 ⇒ Object
133 134 135 |
# 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 ⇒ Object
122 123 124 |
# File 'lib/centurion/deploy_dsl.rb', line 122 def defined_service Centurion::Service.from_env end |
#drop_capability(new_cap_drops) ⇒ Object
31 32 33 34 35 36 37 |
# 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) ⇒ Object
15 16 17 18 19 20 21 |
# 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) ⇒ Object
116 117 118 119 120 |
# 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 |
#get_current_tags_for(image) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/centurion/deploy_dsl.rb', line 99 def (image) build_server_group.inject([]) do |memo, target_server| = target_server.(image) memo += [{ server: target_server.hostname, tags: }] if memo end end |
#health_check(method) ⇒ Object
111 112 113 114 |
# 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) ⇒ Object
39 40 41 42 43 |
# File 'lib/centurion/deploy_dsl.rb', line 39 def host(hostname) current = fetch(:hosts, []) current << hostname set(:hosts, current) end |
#host_port(port, options) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/centurion/deploy_dsl.rb', line 64 def host_port(port, ) (, [ :host_ip, :container_port, :type ]) (, [ :container_port ]) set(:port_bindings, fetch(:port_bindings, []).tap do |bindings| bindings << Centurion::Service::PortBinding.new(port, [:container_port], [:type] || 'tcp', [:host_ip]) end) end |
#host_volume(volume, options) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/centurion/deploy_dsl.rb', line 90 def host_volume(volume, ) (, [ :container_volume ]) (, [ :container_volume ]) set(:binds, fetch(:binds, []).tap do |volumes| volumes << Centurion::Service::Volume.new(volume, [:container_volume]) end) end |
#localhost ⇒ Object
57 58 59 60 61 62 |
# 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) ⇒ Object
45 46 47 |
# File 'lib/centurion/deploy_dsl.rb', line 45 def memory(memory) set(:memory, memory) end |
#network_mode(mode) ⇒ Object
73 74 75 76 77 78 79 |
# 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) ⇒ Object
7 8 9 |
# 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) ⇒ Object
11 12 13 |
# 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) ⇒ Object
81 82 83 84 85 86 87 88 |
# 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) ⇒ Object
107 108 109 |
# File 'lib/centurion/deploy_dsl.rb', line 107 def registry(type) set(:registry, type.to_s) end |