Class: DockerBuilder::Provisioner::Chef
- Inherits:
-
Object
- Object
- DockerBuilder::Provisioner::Chef
- Defined in:
- lib/docker_builder/provisioner/chef.rb
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #build_config ⇒ Object
- #copy_config_file ⇒ Object
- #docker_filename_config ⇒ Object
- #docker_run_cmd(s) ⇒ Object
- #filename_config ⇒ Object
-
#initialize(_settings) ⇒ Chef
constructor
A new instance of Chef.
-
#run_recipe_in_container(dir_base, recipe_name) ⇒ Object
run recipes.
- #save_config ⇒ Object
- #settings ⇒ Object
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
#server ⇒ Object
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_config ⇒ Object
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_file ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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 |
#settings ⇒ Object
16 17 18 |
# File 'lib/docker_builder/provisioner/chef.rb', line 16 def settings server end |