Class: DockerApp::Provisioner::Base
- Inherits:
-
Object
- Object
- DockerApp::Provisioner::Base
- Defined in:
- lib/docker_app/provisioner/base.rb
Class Method Summary collapse
-
._run_bootstrap_script(settings, script) ⇒ Object
provision - bootstrap.
- ._run_bootstrap_script_in_container_chef(settings, script) ⇒ Object
- ._run_bootstrap_script_in_container_shell(settings, script) ⇒ Object
- ._run_bootstrap_script_on_host_shell(settings, script) ⇒ Object
-
._run_setup_script(settings, script) ⇒ Object
provision - setup.
- ._run_setup_script_on_host_chef(settings, script) ⇒ Object
- ._run_setup_script_on_host_shell(settings, script) ⇒ Object
- .cmd(s) ⇒ Object
- .run_provision_scripts_bootstrap(settings) ⇒ Object
- .run_provision_scripts_setup(settings) ⇒ Object
-
.run_script_in_container_shell(settings, script_name) ⇒ Object
helpers - shell.
Class Method Details
._run_bootstrap_script(settings, script) ⇒ Object
provision - bootstrap
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/docker_app/provisioner/base.rb', line 118 def self._run_bootstrap_script(settings, script) puts "run BS script #{script}" if script['type']=='shell' && script['run_from']=='host' return _run_bootstrap_script_on_host_shell(settings, script) elsif script['type']=='shell' && (script['run_from'].nil? || script['run_from']=='') _run_bootstrap_script_in_container_shell(settings, script) elsif script['type']=='chef' _run_bootstrap_script_in_container_chef(settings, script) end return nil end |
._run_bootstrap_script_in_container_chef(settings, script) ⇒ Object
148 149 150 151 |
# File 'lib/docker_app/provisioner/base.rb', line 148 def self._run_bootstrap_script_in_container_chef(settings, script) req = DockerApp::Provisioner::Chef.new(settings) return req.run_recipe_in_container script['dir_base'], script['recipe_name'] end |
._run_bootstrap_script_in_container_shell(settings, script) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/docker_app/provisioner/base.rb', line 139 def self._run_bootstrap_script_in_container_shell(settings, script) script_path = script['script'] = script['exec_options'] || '' # exec cmd %Q(docker exec #{} #{settings.container_name} #{script_path} ) end |
._run_bootstrap_script_on_host_shell(settings, script) ⇒ Object
133 134 135 136 |
# File 'lib/docker_app/provisioner/base.rb', line 133 def self._run_bootstrap_script_on_host_shell(settings, script) cmd %Q(cd #{settings.dir_server_root} && #{script['script']} ) end |
._run_setup_script(settings, script) ⇒ Object
provision - setup
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/docker_app/provisioner/base.rb', line 73 def self._run_setup_script(settings, script) puts "run script #{script}" if script['type']=='shell' return _run_setup_script_on_host_shell(settings, script) elsif script['type']=='chef' return _run_setup_script_on_host_chef(settings, script) end return nil end |
._run_setup_script_on_host_chef(settings, script) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/docker_app/provisioner/base.rb', line 89 def self._run_setup_script_on_host_chef(settings, script) raise 'NOT implemented' # run script on host machine script_name = settings['install']['host']['script'] || 'install_host' # check script exists #script_path = "#{settings.name}/cookbooks/#{settings.name}/recipes/#{script_name}.rb" #f = File.expand_path('.', script_path) #if !File.exists?(f) # puts "script not found: #{f}. Skipping" # return false #end #puts "pwd= #{Dir.pwd}" #puts "root = #{Config.root_path}" #exit # return true end |
._run_setup_script_on_host_shell(settings, script) ⇒ Object
85 86 87 |
# File 'lib/docker_app/provisioner/base.rb', line 85 def self._run_setup_script_on_host_shell(settings, script) cmd %Q(cd #{settings.dir_server_root} && #{script['script']} ) end |
.cmd(s) ⇒ Object
173 174 175 |
# File 'lib/docker_app/provisioner/base.rb', line 173 def self.cmd(s) Command.cmd(s) end |
.run_provision_scripts_bootstrap(settings) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/docker_app/provisioner/base.rb', line 17 def self.run_provision_scripts_bootstrap(settings) # bootstrap_scripts = (settings['provision']['bootstrap'] rescue []) if bootstrap_scripts bootstrap_scripts.each do |script| _run_bootstrap_script(settings, script) end end =begin # commented - 2017-02-22 # install_node_script_type = (settings['install']['node']['script_type'] rescue nil) install_bootstrap_script = (settings['install']['bootstrap']['script'] rescue nil) if install_node_script_type && install_node_script_type=='chef_recipe' # run container and provision with chef #_run_container_chef(settings) # ??? #_provision_container_chef_recipe(settings) elsif install_node_script_type && install_node_script_type=='shell' # docker run #create_and_run_container(settings) # provision with shell script run_shell_script_in_container(settings, "install.sh") else # no script for provision #_run_container_docker(settings) # docker run #create_and_run_container(settings) end # bootstrap if install_bootstrap_script #script = settings['install']['bootstrap']['script'] || '/opt/bootstrap/bootstrap.sh' # bootstsrap with shell script run_bootstrap_shell_script_in_container(settings, install_bootstrap_script) end =end end |
.run_provision_scripts_setup(settings) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/docker_app/provisioner/base.rb', line 5 def self.run_provision_scripts_setup(settings) # setup_scripts = (settings['provision']['setup'] rescue []) if setup_scripts setup_scripts.each do |script| _run_setup_script(settings, script) end end end |
.run_script_in_container_shell(settings, script_name) ⇒ Object
helpers - shell
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/docker_app/provisioner/base.rb', line 157 def self.run_script_in_container_shell(settings, script_name) script_path = settings.make_path_full("scripts/#{script_name}") # copy cmd %Q(cd #{Config.root_path} && docker cp #{script_path} #{settings.container_name}:/tmp/#{script_name} ) # exec cmd %Q(docker exec #{settings.container_name} chmod +x /tmp/#{script_name} ) cmd %Q(docker exec #{settings.container_name} /tmp/#{script_name} ) end |