Class: Vanagon::Platform::RPM
- Inherits:
-
Vanagon::Platform
- Object
- Vanagon::Platform
- Vanagon::Platform::RPM
- Defined in:
- lib/vanagon/platform/rpm.rb,
lib/vanagon/platform/rpm/aix.rb,
lib/vanagon/platform/rpm/eos.rb,
lib/vanagon/platform/rpm/wrl.rb,
lib/vanagon/platform/rpm/sles.rb
Defined Under Namespace
Constant Summary
Constants inherited from Vanagon::Platform
Instance Attribute Summary
Attributes inherited from Vanagon::Platform
#abs_resource_name, #architecture, #aws_ami, #aws_instance_type, #aws_key, #aws_key_name, #aws_region, #aws_shutdown_behavior, #aws_subnet_id, #aws_user_data, #aws_vpc_id, #build_dependencies, #build_hosts, #cflags, #codename, #copy, #cross_compiled, #defaultdir, #dist, #docker_image, #docker_run_args, #environment, #find, #install, #ldflags, #make, #mktemp, #name, #num_cores, #os_name, #os_version, #package_type, #patch, #platform_triple, #provisioning, #rpmbuild, #sed, #servicedir, #servicetype, #servicetypes, #settings, #shasum, #shell, #sort, #ssh_port, #tar, #target_user, #use_docker_exec, #valid_operators, #vmpooler_template
Instance Method Summary collapse
-
#add_repository(definition) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#generate_package(project) ⇒ Array
The specific bits used to generate an rpm package for a given project.
-
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build an rpm package for the project.
-
#initialize(name) ⇒ Vanagon::Platform::RPM
constructor
Constructor.
- #output_dir(target_repo = "products") ⇒ Object
-
#package_name(project) ⇒ String
Method to derive the package name for the project.
-
#package_override(project, var) ⇒ Object
Pass in a packaging override.
- #rpm_defines ⇒ Object
-
#source_output_dir(target_repo = "products") ⇒ Object
Method to derive the directory for source artifacts.
Methods inherited from Vanagon::Platform
#[], #add_build_repository, #add_group, #add_user, #generate_compiled_archive, #get_service_dir, #get_service_types, #is_aix?, #is_cisco_wrlinux?, #is_cross_compiled?, #is_cross_compiled_linux?, #is_deb?, #is_debian?, #is_el8?, #is_el?, #is_eos?, #is_fedora?, #is_fips?, #is_huaweios?, #is_linux?, #is_macos?, #is_osx?, #is_rpm?, #is_sles?, #is_solaris?, #is_ubuntu?, #is_unix?, #is_windows?, load_platform, #provision_with, #validate_operator, #version_munger
Methods included from HashableAttributes
Methods included from Utilities
#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #http_request_code, #http_request_generic, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command
Constructor Details
#initialize(name) ⇒ Vanagon::Platform::RPM
Constructor. Sets up some defaults for the rpm platform and calls the parent constructor
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vanagon/platform/rpm.rb', line 99 def initialize(name) @name = name @make ||= "/usr/bin/make" @tar ||= "tar" @patch ||= "/usr/bin/patch" @num_cores ||= "/bin/grep -c 'processor' /proc/cpuinfo" @rpmbuild ||= "/usr/bin/rpmbuild" @curl = "curl --silent --show-error --fail --location" super(name) end |
Instance Method Details
#add_repository(definition) ⇒ Object
rubocop:disable Metrics/AbcSize
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vanagon/platform/rpm.rb', line 64 def add_repository(definition) # rubocop:disable Metrics/AbcSize definition = URI.parse(definition) commands = ["rpm -q curl > /dev/null || yum -y install curl"] if definition.scheme =~ /^(http|ftp)/ if File.extname(definition.path) == '.rpm' # repo definition is an rpm (like puppetlabs-release) commands << "#{@curl} -o local.rpm '#{definition}'; rpm -Uvh local.rpm; rm -f local.rpm" else reponame = "#{SecureRandom.hex}-#{File.basename(definition.path)}" reponame = "#{reponame}.repo" if File.extname(reponame) != '.repo' if is_cisco_wrlinux? commands << "#{@curl} -o '/etc/yum/repos.d/#{reponame}' '#{definition}'" else commands << "#{@curl} -o '/etc/yum.repos.d/#{reponame}' '#{definition}'" end end end commands end |
#generate_package(project) ⇒ Array
The specific bits used to generate an rpm package for a given project
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vanagon/platform/rpm.rb', line 8 def generate_package(project) # rubocop:disable Metrics/AbcSize target_dir = project.repo ? output_dir(project.repo) : output_dir target_source_output_dir = project.repo ? source_output_dir(project.repo) : source_output_dir if project.source_artifacts rpmbuild = "#{@rpmbuild} -ba" artifact_copy = "mkdir -p output/#{target_source_output_dir}; cp $(tempdir)/rpmbuild/RPMS/**/*.rpm ./output/#{target_dir}; cp $(tempdir)/rpmbuild/SRPMS/*.rpm ./output/#{target_source_output_dir}" else rpmbuild = "#{@rpmbuild} -bb" artifact_copy = "cp $(tempdir)/rpmbuild/*RPMS/**/*.rpm ./output/#{target_dir}" end ["bash -c 'mkdir -p $(tempdir)/rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}'", "cp #{project.name}-#{project.version}.tar.gz $(tempdir)/rpmbuild/SOURCES", "cp file-list-for-rpm $(tempdir)/rpmbuild/SOURCES", "cp #{project.name}.spec $(tempdir)/rpmbuild/SPECS", "PATH=/opt/freeware/bin:$$PATH #{rpmbuild} --target #{@architecture} #{rpm_defines} $(tempdir)/rpmbuild/SPECS/#{project.name}.spec", "mkdir -p output/#{target_dir}", artifact_copy] end |
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build an rpm package for the project
34 35 36 |
# File 'lib/vanagon/platform/rpm.rb', line 34 def generate_packaging_artifacts(workdir, name, binding, project) erb_file(File.join(VANAGON_ROOT, "resources/rpm/project.spec.erb"), File.join(workdir, "#{name}.spec"), false, { :binding => binding }) end |
#output_dir(target_repo = "products") ⇒ Object
46 47 48 |
# File 'lib/vanagon/platform/rpm.rb', line 46 def output_dir(target_repo = "products") super end |
#package_name(project) ⇒ String
Method to derive the package name for the project
42 43 44 |
# File 'lib/vanagon/platform/rpm.rb', line 42 def package_name(project) "#{project.name}-#{project.version}-#{project.release}.#{project.noarch ? 'noarch' : @architecture}.rpm" end |
#package_override(project, var) ⇒ Object
Pass in a packaging override. This will get added to the spec file, and is a good way to pass in arbitrary ‘%_define` or `%_global`
91 92 93 |
# File 'lib/vanagon/platform/rpm.rb', line 91 def package_override(project, var) project.package_overrides << var end |
#rpm_defines ⇒ Object
57 58 59 60 61 62 |
# File 'lib/vanagon/platform/rpm.rb', line 57 def rpm_defines defines = %(--define '_topdir $(tempdir)/rpmbuild' ) # RPM doesn't allow dashes in the os_name. This was added to # convert cisco-wrlinux to cisco_wrlinux defines << %(--define 'dist .#{dist}') end |
#source_output_dir(target_repo = "products") ⇒ Object
Method to derive the directory for source artifacts
53 54 55 |
# File 'lib/vanagon/platform/rpm.rb', line 53 def source_output_dir(target_repo = "products") @source_output_dir ||= File.join(@os_name, @os_version, target_repo, 'SRPMS') end |