Class | BoxGrinder::RPMBasedOSPlugin |
In: |
lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb
lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb |
Parent: | BasePlugin |
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 27 27: def after_init 28: set_default_config_value('format', 'raw') 29: 30: register_deliverable( 31: :disk => "#{@appliance_config.name}-sda.#{@plugin_config['format']}", 32: :descriptor => "#{@appliance_config.name}.xml" 33: ) 34: 35: @linux_helper = LinuxHelper.new(:log => @log) 36: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 27 27: def after_init 28: set_default_config_value('format', 'raw') 29: 30: register_deliverable( 31: :disk => "#{@appliance_config.name}-sda.#{@plugin_config['format']}", 32: :descriptor => "#{@appliance_config.name}.xml" 33: ) 34: 35: @linux_helper = LinuxHelper.new(:log => @log) 36: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 150 150: def apply_root_password(guestfs) 151: @log.debug "Applying root password..." 152: guestfs.sh("/usr/bin/passwd -d root") 153: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 154: @log.debug "Password applied." 155: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 150 150: def apply_root_password(guestfs) 151: @log.debug "Applying root password..." 152: guestfs.sh("/usr/bin/passwd -d root") 153: guestfs.sh("/usr/sbin/usermod -p '#{@appliance_config.os.password.crypt((0...8).map { 65.+(rand(25)).chr }.join)}' root") 154: @log.debug "Password applied." 155: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 67 67: def build_with_appliance_creator(appliance_definition_file, repos = {}) 68: if File.extname(appliance_definition_file).eql?('.ks') 69: kickstart_file = appliance_definition_file 70: else 71: kickstart_file = Kickstart.new(@config, @appliance_config, repos, @dir, :log => @log).create 72: end 73: 74: RPMDependencyValidator.new(@config, @appliance_config, @dir, kickstart_file, @options).resolve_packages 75: 76: @log.info "Building #{@appliance_config.name} appliance..." 77: 78: @exec_helper.execute "appliance-creator -d -v -t '#{@dir.tmp}' --cache=#{@config.dir.cache}/rpms-cache/#{@appliance_config.path.main} --config '#{kickstart_file}' -o '#{@dir.tmp}' --name '#{@appliance_config.name}' --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus} --format #{@plugin_config['format']}" 79: 80: FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp) 81: FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/") 82: 83: @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper| 84: # TODO is this really needed? 85: @log.debug "Uploading '/etc/resolv.conf'..." 86: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 87: @log.debug "'/etc/resolv.conf' uploaded." 88: 89: change_configuration(guestfs_helper) 90: # TODO check if this is still required 91: apply_root_password(guestfs) 92: fix_partition_labels(guestfs) 93: use_labels_for_partitions(guestfs) 94: disable_firewall(guestfs) 95: set_motd(guestfs) 96: install_repos(guestfs) 97: 98: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 99: 100: @log.info "Executing post operations after build..." 101: 102: unless @appliance_config.post['base'].nil? 103: @appliance_config.post['base'].each do |cmd| 104: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 105: end 106: @log.debug "Post commands from appliance definition file executed." 107: else 108: @log.debug "No commands specified, skipping." 109: end 110: 111: yield guestfs, guestfs_helper if block_given? 112: 113: @log.info "Post operations executed." 114: end 115: 116: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 117: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 67 67: def build_with_appliance_creator(appliance_definition_file, repos = {}) 68: if File.extname(appliance_definition_file).eql?('.ks') 69: kickstart_file = appliance_definition_file 70: else 71: kickstart_file = Kickstart.new(@config, @appliance_config, repos, @dir, :log => @log).create 72: end 73: 74: RPMDependencyValidator.new(@config, @appliance_config, @dir, kickstart_file, @options).resolve_packages 75: 76: @log.info "Building #{@appliance_config.name} appliance..." 77: 78: @exec_helper.execute "appliance-creator -d -v -t '#{@dir.tmp}' --cache=#{@config.dir.cache}/rpms-cache/#{@appliance_config.path.main} --config '#{kickstart_file}' -o '#{@dir.tmp}' --name '#{@appliance_config.name}' --vmem #{@appliance_config.hardware.memory} --vcpu #{@appliance_config.hardware.cpus} --format #{@plugin_config['format']}" 79: 80: FileUtils.mv(Dir.glob("#{@dir.tmp}/#{@appliance_config.name}/*"), @dir.tmp) 81: FileUtils.rm_rf("#{@dir.tmp}/#{@appliance_config.name}/") 82: 83: @image_helper.customize(@deliverables.disk) do |guestfs, guestfs_helper| 84: # TODO is this really needed? 85: @log.debug "Uploading '/etc/resolv.conf'..." 86: guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf") 87: @log.debug "'/etc/resolv.conf' uploaded." 88: 89: change_configuration(guestfs_helper) 90: # TODO check if this is still required 91: apply_root_password(guestfs) 92: fix_partition_labels(guestfs) 93: use_labels_for_partitions(guestfs) 94: disable_firewall(guestfs) 95: set_motd(guestfs) 96: install_repos(guestfs) 97: 98: guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0 99: 100: @log.info "Executing post operations after build..." 101: 102: unless @appliance_config.post['base'].nil? 103: @appliance_config.post['base'].each do |cmd| 104: guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch) 105: end 106: @log.debug "Post commands from appliance definition file executed." 107: else 108: @log.debug "No commands specified, skipping." 109: end 110: 111: yield guestfs, guestfs_helper if block_given? 112: 113: @log.info "Post operations executed." 114: end 115: 116: @log.info "Base image for #{@appliance_config.name} appliance was built successfully." 117: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 157 157: def change_configuration(guestfs_helper) 158: guestfs_helper.augeas do 159: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 160: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 161: end 162: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 157 157: def change_configuration(guestfs_helper) 158: guestfs_helper.augeas do 159: set('/etc/ssh/sshd_config', 'UseDNS', 'no') 160: set('/etc/sysconfig/selinux', 'SELINUX', 'permissive') 161: end 162: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 120 120: def disable_firewall(guestfs) 121: @log.debug "Disabling firewall..." 122: guestfs.sh("lokkit -q --disabled") 123: @log.debug "Firewall disabled." 124: end
issues.jboss.org/browse/BGBUILD-177
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 120 120: def disable_firewall(guestfs) 121: @log.debug "Disabling firewall..." 122: guestfs.sh("lokkit -q --disabled") 123: @log.debug "Firewall disabled." 124: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 126 126: def fix_partition_labels(guestfs) 127: guestfs.list_partitions.each do |partition| 128: guestfs.sh("/sbin/e2label #{partition} #{read_label(guestfs, partition)}") 129: end 130: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 126 126: def fix_partition_labels(guestfs) 127: guestfs.list_partitions.each do |partition| 128: guestfs.sh("/sbin/e2label #{partition} #{read_label(guestfs, partition)}") 129: end 130: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 181 181: def install_repos(guestfs) 182: @log.debug "Installing repositories from appliance definition file..." 183: @appliance_config.repos.each do |repo| 184: if repo['ephemeral'] 185: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 186: next 187: end 188: 189: @log.debug "Installing #{repo['name']} repo..." 190: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 191: 192: ['baseurl', 'mirrorlist'].each do |type| 193: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 194: end 195: 196: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 197: end 198: @log.debug "Repositories installed." 199: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 181 181: def install_repos(guestfs) 182: @log.debug "Installing repositories from appliance definition file..." 183: @appliance_config.repos.each do |repo| 184: if repo['ephemeral'] 185: @log.debug "Repository '#{repo['name']}' is an ephemeral repo. It'll not be installed in the appliance." 186: next 187: end 188: 189: @log.debug "Installing #{repo['name']} repo..." 190: repo_file = File.read("#{File.dirname(__FILE__)}/src/base.repo").gsub(/#NAME#/, repo['name']) 191: 192: ['baseurl', 'mirrorlist'].each do |type| 193: repo_file << ("#{type}=#{repo[type]}\n") unless repo[type].nil? 194: end 195: 196: guestfs.write_file("/etc/yum.repos.d/#{repo['name']}.repo", repo_file, 0) 197: end 198: @log.debug "Repositories installed." 199: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 38 38: def read_file(file) 39: read_kickstart(file) if File.extname(file).eql?('.ks') 40: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 38 38: def read_file(file) 39: read_kickstart(file) if File.extname(file).eql?('.ks') 40: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 42 42: def read_kickstart(file) 43: appliance_config = ApplianceConfig.new 44: 45: appliance_config.name = File.basename(file, '.ks') 46: 47: name = nil 48: version = nil 49: 50: File.read(file).each do |line| 51: n = line.scan(/^# bg_os_name: (.*)/).flatten.first 52: v = line.scan(/^# bg_os_version: (.*)/).flatten.first 53: 54: name = n unless n.nil? 55: version = v unless v.nil? 56: end 57: 58: raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil? 59: raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil? 60: 61: appliance_config.os.name = name 62: appliance_config.os.version = version 63: 64: appliance_config 65: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 42 42: def read_kickstart(file) 43: appliance_config = ApplianceConfig.new 44: 45: appliance_config.name = File.basename(file, '.ks') 46: 47: name = nil 48: version = nil 49: 50: File.read(file).each do |line| 51: n = line.scan(/^# bg_os_name: (.*)/).flatten.first 52: v = line.scan(/^# bg_os_version: (.*)/).flatten.first 53: 54: name = n unless n.nil? 55: version = v unless v.nil? 56: end 57: 58: raise "No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora" if name.nil? 59: raise "No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14" if version.nil? 60: 61: appliance_config.os.name = name 62: appliance_config.os.version = version 63: 64: appliance_config 65: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 146 146: def read_label(guestfs, partition) 147: (guestfs.respond_to?(:vfs_label) ? guestfs.vfs_label(partition) : guestfs.sh("/sbin/e2label #{partition}").chomp.strip).gsub('_', '') 148: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 146 146: def read_label(guestfs, partition) 147: (guestfs.respond_to?(:vfs_label) ? guestfs.vfs_label(partition) : guestfs.sh("/sbin/e2label #{partition}").chomp.strip).gsub('_', '') 148: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 177 177: def recreate_kernel_image(guestfs, modules = []) 178: @linux_helper.recreate_kernel_image(guestfs, modules) 179: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 177 177: def recreate_kernel_image(guestfs, modules = []) 178: @linux_helper.recreate_kernel_image(guestfs, modules) 179: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 164 164: def set_motd(guestfs) 165: @log.debug "Setting up '/etc/motd'..." 166: # set nice banner for SSH 167: motd_file = "/etc/init.d/motd" 168: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 169: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 170: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 171: 172: guestfs.sh("/bin/chmod +x #{motd_file}") 173: guestfs.sh("/sbin/chkconfig --add motd") 174: @log.debug "'/etc/motd' is nice now." 175: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 164 164: def set_motd(guestfs) 165: @log.debug "Setting up '/etc/motd'..." 166: # set nice banner for SSH 167: motd_file = "/etc/init.d/motd" 168: guestfs.upload("#{File.dirname(__FILE__)}/src/motd.init", motd_file) 169: guestfs.sh("sed -i s/#VERSION#/'#{@appliance_config.version}.#{@appliance_config.release}'/ #{motd_file}") 170: guestfs.sh("sed -i s/#APPLIANCE#/'#{@appliance_config.name} appliance'/ #{motd_file}") 171: 172: guestfs.sh("/bin/chmod +x #{motd_file}") 173: guestfs.sh("/sbin/chkconfig --add motd") 174: @log.debug "'/etc/motd' is nice now." 175: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 132 132: def use_labels_for_partitions(guestfs) 133: device = guestfs.list_devices.first 134: 135: # /etc/fstab 136: if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" } 137: guestfs.write_file('/etc/fstab', fstab, 0) 138: end 139: 140: # /boot/grub/grub.conf 141: if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" } 142: guestfs.write_file('/boot/grub/grub.conf', grub, 0) 143: end 144: end
# File lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb, line 132 132: def use_labels_for_partitions(guestfs) 133: device = guestfs.list_devices.first 134: 135: # /etc/fstab 136: if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" } 137: guestfs.write_file('/etc/fstab', fstab, 0) 138: end 139: 140: # /boot/grub/grub.conf 141: if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" } 142: guestfs.write_file('/boot/grub/grub.conf', grub, 0) 143: end 144: end