Class: DockerBuilder::Provisioner::Chef

Inherits:
Object
  • Object
show all
Defined in:
lib/docker_builder/provisioner/chef.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_settings) ⇒ Chef

Returns a new instance of Chef.



21
22
23
24
# File 'lib/docker_builder/provisioner/chef.rb', line 21

def initialize(_settings)
  self.server = _settings

end

Instance Attribute Details

#serverObject

Returns the value of attribute server.



5
6
7
# File 'lib/docker_builder/provisioner/chef.rb', line 5

def server
  @server
end

Instance Method Details

#build_configObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/docker_builder/provisioner/chef.rb', line 56

def build_config
  res = {}

  attr = settings.properties['attributes']
  res = attr

  #res = settings.all_attributes

  res
end

#copy_config_fileObject



28
29
30
31
32
33
34
35
# File 'lib/docker_builder/provisioner/chef.rb', line 28

def copy_config_file
  # config json
  save_config

  # copy to container
  DockerBuilder::Command.cmd %Q(docker cp #{filename_config} #{settings.container_name}:#{docker_filename_config})

end

#docker_filename_configObject



52
53
54
# File 'lib/docker_builder/provisioner/chef.rb', line 52

def docker_filename_config
  "/opt/bootstrap/config.json"
end

#docker_run_cmd(s) ⇒ Object



85
86
87
# File 'lib/docker_builder/provisioner/chef.rb', line 85

def docker_run_cmd(s)
  DockerBuilder::Command.cmd %Q(docker exec #{settings.container_name} bash -c '#{s}')
end

#filename_configObject



48
49
50
# File 'lib/docker_builder/provisioner/chef.rb', line 48

def filename_config
  File.join(Config.root_path, 'temp', "bootstrap-#{settings.name}.json")
end

#run_recipe_in_container(dir_base, recipe_name) ⇒ Object

run recipes



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/docker_builder/provisioner/chef.rb', line 69

def run_recipe_in_container(dir_base, recipe_name)

  recipe_name ||= "server::bootstrap"

  # generate config
  copy_config_file


  #
  q = %Q(cd #{dir_base} && chef-client -z -j #{docker_filename_config} --override-runlist "recipe[#{recipe_name}]" )

  # exec
  docker_run_cmd q
end

#save_configObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/docker_builder/provisioner/chef.rb', line 37

def save_config
  require 'json'
  filename = filename_config
  FileUtils.mkdir_p(File.dirname(filename))
  File.open(filename,"w+") do |f|
    f.write(build_config.to_json)
  end

  true
end

#settingsObject



16
17
18
# File 'lib/docker_builder/provisioner/chef.rb', line 16

def settings
  server
end