Class: DockerBuilder::ServerSettings
- Inherits:
-
Object
- Object
- DockerBuilder::ServerSettings
- Defined in:
- lib/docker_builder/server_settings.rb
Instance Attribute Summary collapse
-
#common_config ⇒ Object
Returns the value of attribute common_config.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(name, v) ⇒ Object
- #add_config(a) ⇒ Object
- #all_attributes ⇒ Object
- #attributes(a) ⇒ Object
- #attributes=(opts = {}) ⇒ Object
- #build(v) ⇒ Object
- #build=(opts = {}) ⇒ Object
- #chef_node_name ⇒ Object
- #container_name(name = nil) ⇒ Object
- #container_prefix ⇒ Object
- #dir_cookbooks ⇒ Object
- #dir_data ⇒ Object
- #dir_data_base ⇒ Object
- #dir_server_root ⇒ Object
- #docker(a) ⇒ Object
- #docker=(opts = {}) ⇒ Object
- #docker_link_build(r) ⇒ Object
- #docker_links ⇒ Object
- #docker_links_array ⇒ Object
- #docker_links_string ⇒ Object
- #docker_ports ⇒ Object
- #docker_ports_array ⇒ Object
- #docker_ports_string ⇒ Object
- #docker_volumes ⇒ Object
- #docker_volumes_array ⇒ Object
- #docker_volumes_from ⇒ Object
- #docker_volumes_from_array ⇒ Object
- #docker_volumes_from_string ⇒ Object
- #docker_volumes_string ⇒ Object
- #filename_chef_client_json ⇒ Object
- #filename_chef_config ⇒ Object
- #filename_chef_node_json ⇒ Object
- #filename_config_json ⇒ Object
- #get_binding ⇒ Object
- #image_name ⇒ Object
- #image_prefix ⇒ Object
- #is_swarm_mode? ⇒ Boolean
- #make_path_full(path) ⇒ Object
- #name ⇒ Object
- #need_build? ⇒ Boolean
- #node ⇒ Object
- #prefix ⇒ Object
- #properties_common(opt_name) ⇒ Object
- #provision(v) ⇒ Object
- #provision=(opts = {}) ⇒ Object
- #run_env_variables ⇒ Object
- #run_env_variables_string ⇒ Object
- #run_extra_options_string ⇒ Object
-
#service_name(name = nil) ⇒ Object
docker swarm services.
- #service_prefix ⇒ Object
- #set(name, v) ⇒ Object
- #volume_path_local(v) ⇒ Object
Instance Attribute Details
#common_config ⇒ Object
Returns the value of attribute common_config.
5 6 7 |
# File 'lib/docker_builder/server_settings.rb', line 5 def common_config @common_config end |
#properties ⇒ Object
Returns the value of attribute properties.
4 5 6 |
# File 'lib/docker_builder/server_settings.rb', line 4 def properties @properties end |
Instance Method Details
#[](key) ⇒ Object
322 323 324 |
# File 'lib/docker_builder/server_settings.rb', line 322 def [](key) properties[key] end |
#add(name, v) ⇒ Object
67 68 69 70 71 |
# File 'lib/docker_builder/server_settings.rb', line 67 def add(name, v) properties[name] = {} if properties[name].nil? properties[name].merge!(v) end |
#add_config(a) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/docker_builder/server_settings.rb', line 74 def add_config(a) # merge build(a['build']) if a['build'] provision(a['provision']) if a['provision'] docker(a['docker']) if a['docker'] attributes(a['attributes']) if a['attributes'] end |
#all_attributes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docker_builder/server_settings.rb', line 17 def all_attributes res = properties.clone res['base'] = { 'image_name'=> image_name, 'container_name'=> container_name, } # docker res['docker']['ports'] = docker_ports res['docker']['volumes'] = docker_volumes res['docker']['links'] = docker_links res end |
#attributes(a) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/docker_builder/server_settings.rb', line 101 def attributes(a) # merge properties['attributes'] ||= {} a.each do |k,v| properties['attributes'][k] = v end end |
#attributes=(opts = {}) ⇒ Object
58 59 60 |
# File 'lib/docker_builder/server_settings.rb', line 58 def attributes=(opts={}) attributes(opts) end |
#build(v) ⇒ Object
84 85 86 |
# File 'lib/docker_builder/server_settings.rb', line 84 def build(v) properties['build'] = v end |
#build=(opts = {}) ⇒ Object
48 49 50 |
# File 'lib/docker_builder/server_settings.rb', line 48 def build=(opts={}) build(opts) end |
#chef_node_name ⇒ Object
173 174 175 |
# File 'lib/docker_builder/server_settings.rb', line 173 def chef_node_name "#{prefix}#{name}" end |
#container_name(name = nil) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/docker_builder/server_settings.rb', line 166 def container_name(name=nil) name ||= properties['name'] s = name "#{container_prefix}#{s}" end |
#container_prefix ⇒ Object
121 122 123 |
# File 'lib/docker_builder/server_settings.rb', line 121 def container_prefix "#{prefix}#{properties_common('container_prefix')}" end |
#dir_cookbooks ⇒ Object
338 339 340 |
# File 'lib/docker_builder/server_settings.rb', line 338 def dir_cookbooks File.("servers/#{name}/cookbooks", Config.root_path) end |
#dir_data ⇒ Object
202 203 204 |
# File 'lib/docker_builder/server_settings.rb', line 202 def dir_data "#{properties_common('dir_data')}#{self.name}/" end |
#dir_data_base ⇒ Object
198 199 200 |
# File 'lib/docker_builder/server_settings.rb', line 198 def dir_data_base "#{properties_common('dir_data')}" end |
#dir_server_root ⇒ Object
342 343 344 |
# File 'lib/docker_builder/server_settings.rb', line 342 def dir_server_root File.("servers/#{name}", Config.root_path) end |
#docker(a) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/docker_builder/server_settings.rb', line 92 def docker(a) # merge properties['docker'] ||= {} a.each do |k,v| properties['docker'][k] = v end end |
#docker=(opts = {}) ⇒ Object
51 52 53 |
# File 'lib/docker_builder/server_settings.rb', line 51 def docker=(opts={}) docker(opts) end |
#docker_link_build(r) ⇒ Object
288 289 290 291 |
# File 'lib/docker_builder/server_settings.rb', line 288 def docker_link_build(r) # fix "#{container_prefix}#{r[0]}:#{r[1]}" end |
#docker_links ⇒ Object
274 275 276 277 278 |
# File 'lib/docker_builder/server_settings.rb', line 274 def docker_links a = properties['docker']['links'] || [] a end |
#docker_links_array ⇒ Object
284 285 286 |
# File 'lib/docker_builder/server_settings.rb', line 284 def docker_links_array docker_links.map{|d| docker_link_build(d)} end |
#docker_links_string ⇒ Object
280 281 282 |
# File 'lib/docker_builder/server_settings.rb', line 280 def docker_links_string docker_links_array.map{|s| "--link #{s}"}.join(' ') end |
#docker_ports ⇒ Object
260 261 262 263 |
# File 'lib/docker_builder/server_settings.rb', line 260 def docker_ports a = properties['docker']['ports'] || [] a end |
#docker_ports_array ⇒ Object
269 270 271 |
# File 'lib/docker_builder/server_settings.rb', line 269 def docker_ports_array docker_ports.map{|d| "#{d[0]}:#{d[1]}"} end |
#docker_ports_string ⇒ Object
265 266 267 |
# File 'lib/docker_builder/server_settings.rb', line 265 def docker_ports_string docker_ports.map{|r| "-p #{r[0]}:#{r[1]}"}.join(' ') end |
#docker_volumes ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/docker_builder/server_settings.rb', line 217 def docker_volumes a = properties['docker']['volumes'] || [] # fix paths res = a.map do |r| path_local = volume_path_local(r[0]) [path_local, r[1]] end res end |
#docker_volumes_array ⇒ Object
234 235 236 |
# File 'lib/docker_builder/server_settings.rb', line 234 def docker_volumes_array docker_volumes.map{|d| "#{d[0]}:#{d[1]}"} end |
#docker_volumes_from ⇒ Object
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/docker_builder/server_settings.rb', line 240 def docker_volumes_from a = properties['docker']['volumes_from'] || [] # fix paths res = a.map do |r| "#{prefix}#{r}" end res end |
#docker_volumes_from_array ⇒ Object
255 256 257 |
# File 'lib/docker_builder/server_settings.rb', line 255 def docker_volumes_from_array docker_volumes_from.map{|d| "#{d}"} end |
#docker_volumes_from_string ⇒ Object
251 252 253 |
# File 'lib/docker_builder/server_settings.rb', line 251 def docker_volumes_from_string docker_volumes_from.map{|d| "--volumes-from #{d}"}.join(' ') end |
#docker_volumes_string ⇒ Object
230 231 232 |
# File 'lib/docker_builder/server_settings.rb', line 230 def docker_volumes_string docker_volumes.map{|r| "-v #{r[0]}:#{r[1]}"}.join(' ') end |
#filename_chef_client_json ⇒ Object
349 350 351 |
# File 'lib/docker_builder/server_settings.rb', line 349 def filename_chef_client_json File.("clients/#{image_name}.json", dir_server_root) end |
#filename_chef_config ⇒ Object
328 329 330 331 332 |
# File 'lib/docker_builder/server_settings.rb', line 328 def filename_chef_config #File.join(File.dirname(__FILE__), '..', 'config' ,"config-#{name}.json") File.join(Config.root_path, 'temp', "#{name}.json") end |
#filename_chef_node_json ⇒ Object
346 347 348 |
# File 'lib/docker_builder/server_settings.rb', line 346 def filename_chef_node_json File.("nodes/#{image_name}.json", dir_server_root) end |
#filename_config_json ⇒ Object
334 335 336 |
# File 'lib/docker_builder/server_settings.rb', line 334 def filename_config_json File.join(Config.root_path, 'temp', "#{name}.json") end |
#get_binding ⇒ Object
7 8 9 |
# File 'lib/docker_builder/server_settings.rb', line 7 def get_binding return binding() end |
#image_name ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/docker_builder/server_settings.rb', line 142 def image_name if !need_build? bi = properties['build']['base_image'] return "#{bi['name']}:#{bi['tag']}" end # s = properties['name'] if properties['build']['image_name'] s = "#{properties['build']['image_name']}" end "#{image_prefix}#{s}" end |
#image_prefix ⇒ Object
125 126 127 |
# File 'lib/docker_builder/server_settings.rb', line 125 def image_prefix "#{prefix}#{properties_common('image_prefix')}" end |
#is_swarm_mode? ⇒ Boolean
315 316 317 318 319 |
# File 'lib/docker_builder/server_settings.rb', line 315 def is_swarm_mode? v = properties["docker"]["swarm_mode"] return false if v.nil? return v end |
#make_path_full(path) ⇒ Object
355 356 357 |
# File 'lib/docker_builder/server_settings.rb', line 355 def make_path_full(path) File.("#{path}", dir_server_root) end |
#name ⇒ Object
136 137 138 |
# File 'lib/docker_builder/server_settings.rb', line 136 def name properties['name'] end |
#need_build? ⇒ Boolean
158 159 160 161 162 163 164 |
# File 'lib/docker_builder/server_settings.rb', line 158 def need_build? build_type = properties['build']['build_type'] return false if build_type=='' || build_type=='none' true end |
#node ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/docker_builder/server_settings.rb', line 36 def node res = properties['attributes'] || {} res['name'] = name res['container_name'] = container_name res end |
#prefix ⇒ Object
116 117 118 119 |
# File 'lib/docker_builder/server_settings.rb', line 116 def prefix #properties['common']['prefix'] properties_common('prefix') end |
#properties_common(opt_name) ⇒ Object
112 113 114 |
# File 'lib/docker_builder/server_settings.rb', line 112 def properties_common(opt_name) common_config.[opt_name] || common_config.send(opt_name) end |
#provision(v) ⇒ Object
88 89 90 |
# File 'lib/docker_builder/server_settings.rb', line 88 def provision(v) properties['provision'] = v end |
#provision=(opts = {}) ⇒ Object
54 55 56 |
# File 'lib/docker_builder/server_settings.rb', line 54 def provision=(opts={}) provision(opts) end |
#run_env_variables ⇒ Object
295 296 297 298 299 |
# File 'lib/docker_builder/server_settings.rb', line 295 def run_env_variables a = properties['docker']['run_env'] || [] a end |
#run_env_variables_string ⇒ Object
301 302 303 |
# File 'lib/docker_builder/server_settings.rb', line 301 def run_env_variables_string run_env_variables.map{|r| "-e #{r[0]}=#{r[1]}"}.join(' ') end |
#run_extra_options_string ⇒ Object
308 309 310 311 |
# File 'lib/docker_builder/server_settings.rb', line 308 def s = properties['docker']['run_extra_options'] || '' s end |
#service_name(name = nil) ⇒ Object
docker swarm services
209 210 211 212 213 214 |
# File 'lib/docker_builder/server_settings.rb', line 209 def service_name(name=nil) name ||= properties['name'] s = name "#{service_prefix}#{s}" end |
#service_prefix ⇒ Object
129 130 131 |
# File 'lib/docker_builder/server_settings.rb', line 129 def service_prefix "#{prefix}#{properties_common('service_prefix')}" end |
#set(name, v) ⇒ Object
63 64 65 |
# File 'lib/docker_builder/server_settings.rb', line 63 def set(name, v) properties[name] = v end |
#volume_path_local(v) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/docker_builder/server_settings.rb', line 177 def volume_path_local(v) res = v.to_s if v =~ /^\./ s = v.gsub /^\.\//, '' #res = "$PWD/servers/#{self.name}/#{s}" res = File.(s, dir_server_root) #res = File.expand_path(s, properties_common('root_path')) elsif v =~ /^\/\// res = dir_data_base+(v.gsub /^\/\//, '') elsif v =~ /^\// res = v else res = self.dir_data+v end res end |