Class: DockerApp::ManagerImage
- Inherits:
-
Object
- Object
- DockerApp::ManagerImage
- Defined in:
- lib/docker_app/manager_image.rb
Class Method Summary collapse
- .build_image(server_name, settings = nil) ⇒ Object
- .build_image_with_chef(settings) ⇒ Object
- .build_image_with_dockerfile(settings) ⇒ Object
- .build_image_with_dockerfile_github(settings) ⇒ Object
- .build_image_with_packer(settings) ⇒ Object
- .cmd(s) ⇒ Object
- .destroy_image(server_name, settings = {}) ⇒ Object
- .destroy_image_chef(settings) ⇒ Object
- .image_exist?(settings) ⇒ Boolean
Class Method Details
.build_image(server_name, settings = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/docker_app/manager_image.rb', line 5 def self.build_image(server_name, settings=nil) puts "building image for #{server_name}..." #puts "settings: #{settings}" #puts "debug: #{settings['properties']}" #settings = load_settings(server_name) t = settings['build']['build_type'] if t=='' || t=='none' # puts "no build needed..." elsif t.downcase=='dockerfile' return build_image_with_dockerfile(settings) elsif t.downcase=='github' return build_image_with_dockerfile_github(settings) elsif t=='chef' return build_image_with_chef(settings) elsif t=='packer' return build_image_with_packer(settings) end end |
.build_image_with_chef(settings) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/docker_app/manager_image.rb', line 45 def self.build_image_with_chef(settings) puts "build image with chef" # config json save_chef_config(settings) # check node cmd %Q(cd #{Config.root_path} && chef exec knife node show #{settings.chef_node_name} -c #{chef_config_knife_path}) #cmd %Q(SERVER_NAME=#{settings.name} SERVER_PATH=#{settings.dir_server_root} chef exec chef-client -z -N #{settings.image_name} -j #{settings.filename_config_json} -c #{chef_config_knife_path} #{chef_recipe_path('chef_build_image.rb')} ) res_recipe = run_chef_recipe(settings, 'chef_build_image.rb') end |
.build_image_with_dockerfile(settings) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/docker_app/manager_image.rb', line 29 def self.build_image_with_dockerfile(settings) puts "build image with Dockerfile" #cmd %Q(cd #{name} && docker build -t #{settings.image_name} . ) cmd %Q(docker build -t #{settings.image_name} #{settings.dir_server_root} ) end |
.build_image_with_dockerfile_github(settings) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/docker_app/manager_image.rb', line 37 def self.build_image_with_dockerfile_github(settings) puts "build image with Dockerfile from github" cmd %Q(docker build -t #{settings.image_name} #{settings.properties['build']['base_image']['repository']} ) end |
.build_image_with_packer(settings) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/docker_app/manager_image.rb', line 60 def self.build_image_with_packer(settings) require_relative '../../lib/docker_app/builder/packer' puts "build image with packer" builder = DockerApp::Builder::Packer.new(settings) builder.build end |
.cmd(s) ⇒ Object
114 115 116 |
# File 'lib/docker_app/manager_image.rb', line 114 def self.cmd(s) Command.cmd(s) end |
.destroy_image(server_name, settings = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/docker_app/manager_image.rb', line 70 def self.destroy_image(server_name, settings={}) puts "destroying image for server #{server_name}" cmd %Q(docker rmi #{settings.image_name} ) cmd %Q(docker rm -f chef.converge.#{settings.image_name} ) # delete chef data if settings['build']['build_type']=='chef' return destroy_image_chef(settings) end end |
.destroy_image_chef(settings) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/docker_app/manager_image.rb', line 83 def self.destroy_image_chef(settings) puts "destroying image with chef..." # config json save_chef_config(settings) # destroy temp container cmd %Q(docker rm -f chef-converge.#{settings.image_name} ) # cmd %Q(cd #{Config.root_path} && chef exec knife node delete #{settings.chef_node_name} -y -c #{chef_config_knife_path}) res_recipe = run_chef_recipe(settings, 'chef_destroy_image.rb') chef_remove_data(settings) # work - before 2016-nov-19 #cmd %Q(cd #{Config.root_path} && chef exec knife node delete #{settings.chef_node_name} -y -c #{chef_config_knife_path}) # clean chef client, node #cmd %Q(cd #{Config.root_path} && rm -f #{settings.filename_chef_node_json} ) #cmd %Q(cd #{Config.root_path} && rm -f #{settings.filename_chef_client_json} ) end |
.image_exist?(settings) ⇒ Boolean
109 110 111 |
# File 'lib/docker_app/manager_image.rb', line 109 def self.image_exist?(settings) end |