Class: Vanagon::Platform::DEB
- Inherits:
-
Vanagon::Platform
- Object
- Vanagon::Platform
- Vanagon::Platform::DEB
- Defined in:
- lib/vanagon/platform/deb.rb
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, #source_output_dir, #ssh_port, #tar, #target_user, #use_docker_exec, #valid_operators, #vmpooler_template
Instance Method Summary collapse
-
#add_gpg_key(gpg_key) ⇒ String
Returns the string to add a gpg key to the platforms’ provisioning.
-
#add_repo_target(definition) ⇒ String
Returns the string to add a target repo to the platforms’ provisioning.
-
#add_repository(definition, gpg_key = nil) ⇒ Object
Returns the commands to add a given repo target and optionally a gpg key to the build system.
-
#generate_package(project) ⇒ Array
The specific bits used to generate a debian package for a given project.
-
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build a debian package for the project.
-
#initialize(name) ⇒ Vanagon::Platform::DEB
constructor
Constructor.
-
#output_dir(target_repo = "") ⇒ String
Get the expected output dir for the debian packages.
-
#package_name(project) ⇒ String
Method to derive the package name for the project.
-
#package_override(project, var) ⇒ Object
Pass in a packaging override.
- #version_munger(version_string, default: '=') ⇒ Object
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
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::DEB
Constructor. Sets up some defaults for the debian platform and calls the parent constructor
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/vanagon/platform/deb.rb', line 139 def initialize(name) @name = name @make = "/usr/bin/make" @tar = "tar" @patch = "/usr/bin/patch" @num_cores = "/usr/bin/nproc" @curl = "curl --silent --show-error --fail --location" @valid_operators = ['<', '>', '<=', '>=', '=', '<<', '>>'] super(name) end |
Instance Method Details
#add_gpg_key(gpg_key) ⇒ String
Returns the string to add a gpg key to the platforms’ provisioning
89 90 91 92 93 |
# File 'lib/vanagon/platform/deb.rb', line 89 def add_gpg_key(gpg_key) gpgname = "#{SecureRandom.hex}-#{File.basename(gpg_key.path)}" gpgname = "#{gpgname}.gpg" if gpgname !~ /\.gpg$/ "#{@curl} -o '/etc/apt/trusted.gpg.d/#{gpgname}' '#{gpg_key}'" end |
#add_repo_target(definition) ⇒ String
Returns the string to add a target repo to the platforms’ provisioning
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vanagon/platform/deb.rb', line 74 def add_repo_target(definition) if File.extname(definition.path) == '.deb' # repo definition is an deb (like puppetlabs-release) "#{@curl} -o local.deb '#{definition}' && dpkg -i local.deb; rm -f local.deb" else reponame = "#{SecureRandom.hex}-#{File.basename(definition.path)}" reponame = "#{reponame}.list" if File.extname(reponame) != '.list' "#{@curl} -o '/etc/apt/sources.list.d/#{reponame}' '#{definition}'" end end |
#add_repository(definition, gpg_key = nil) ⇒ Object
Returns the commands to add a given repo target and optionally a gpg key to the build system
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vanagon/platform/deb.rb', line 99 def add_repository(definition, gpg_key = nil) # i.e., definition = http://builds.delivery.puppetlabs.net/puppet-agent/0.2.1/repo_configs/deb/pl-puppet-agent-0.2.1-wheezy.list # parse the definition and gpg_key if set to ensure they are both valid URIs definition = URI.parse(definition) gpg_key = URI.parse(gpg_key) if gpg_key provisioning = ["apt-get -qq update && DEBIAN_FRONTEND=noninteractive apt-get -qq install curl"] if definition.scheme =~ /^(http|ftp)/ provisioning << add_repo_target(definition) end if gpg_key provisioning << add_gpg_key(gpg_key) end provisioning << "apt-get -qq update" end |
#generate_package(project) ⇒ Array
The specific bits used to generate a debian package for a given project
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vanagon/platform/deb.rb', line 8 def generate_package(project) # rubocop:disable Metrics/AbcSize target_dir = project.repo ? output_dir(project.repo) : output_dir if project.source_artifacts copy_extensions = '*.{deb,build,tar.gz,changes,dsc}' else copy_extensions = '*.deb' end pkg_arch_opt = project.noarch ? "" : "-a#{@architecture}" pkg_arch_opt = '-aarm64' if pkg_arch_opt == '-aaarch64' ["mkdir -p output/#{target_dir}", "mkdir -p $(tempdir)/#{project.name}-#{project.version}", "cp #{project.name}-#{project.version}.tar.gz $(tempdir)/#{project.name}_#{project.version}.orig.tar.gz", "cat file-list >> debian/install", "cp -pr debian $(tempdir)/#{project.name}-#{project.version}", "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/#{project.name}-#{project.version}' --strip-components 1 -xf -", "#{sed} -i 's/\ /?/g' $(tempdir)/#{project.name}-#{project.version}/debian/install", "(cd $(tempdir)/#{project.name}-#{project.version}; debuild --no-lintian #{pkg_arch_opt} -uc -us)", "cp $(tempdir)/#{copy_extensions} ./output/#{target_dir}"] end |
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build a debian package for the project
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vanagon/platform/deb.rb', line 35 def generate_packaging_artifacts(workdir, name, binding, project) # rubocop:disable Metrics/AbcSize deb_dir = File.join(workdir, "debian") FileUtils.mkdir_p(deb_dir) unless project.get_interest_triggers("install").empty? && project.get_interest_triggers("upgrade").empty? && project.get_activate_triggers.empty? erb_file(File.join(VANAGON_ROOT, "resources/deb/triggers.erb"), File.join(deb_dir, "#{name}.triggers"), false, { :binding => binding }) end # Lots of templates here ["changelog", "conffiles", "control", "docs", "dirs", "install", "preinst", "postinst", "postrm", "prerm", "rules"].each do |deb_file| erb_file(File.join(VANAGON_ROOT, "resources/deb/#{deb_file}.erb"), File.join(deb_dir, deb_file), false, { :binding => binding }) end # These could be templates, but their content is static, so that seems weird. File.open(File.join(deb_dir, "compat"), "w") { |f| f.puts("7") } FileUtils.mkdir_p(File.join(deb_dir, "source")) File.open(File.join(deb_dir, "source", "format"), "w") { |f| f.puts("3.0 (quilt)") } end |
#output_dir(target_repo = "") ⇒ String
Get the expected output dir for the debian packages. This allows us to use some standard tools to ship internally.
66 67 68 |
# File 'lib/vanagon/platform/deb.rb', line 66 def output_dir(target_repo = "") @output_dir ||= File.join("deb", @codename, target_repo) end |
#package_name(project) ⇒ String
Method to derive the package name for the project
58 59 60 |
# File 'lib/vanagon/platform/deb.rb', line 58 def package_name(project) "#{project.name}_#{project.version}-#{project.release}#{@codename}_#{project.noarch ? 'all' : @architecture}.deb" end |
#package_override(project, var) ⇒ Object
Pass in a packaging override. This will get added to the rules file, and is a good way to pass in arbitrary environment variables
123 124 125 |
# File 'lib/vanagon/platform/deb.rb', line 123 def package_override(project, var) project.package_overrides << var end |
#version_munger(version_string, default: '=') ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/vanagon/platform/deb.rb', line 127 def version_munger(version_string, default: '=') operator, version = super.split(' ') if operator =~ /^[<>]$/ operator = "#{operator}#{operator}" end "#{operator} #{version}" end |