Class: Vanagon::Platform
- Inherits:
-
Object
- Object
- Vanagon::Platform
- Includes:
- HashableAttributes, Utilities
- Defined in:
- lib/vanagon/extensions/hashable.rb,
lib/vanagon/platform.rb,
lib/vanagon/platform/deb.rb,
lib/vanagon/platform/dsl.rb,
lib/vanagon/platform/osx.rb,
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/windows.rb,
lib/vanagon/platform/rpm/sles.rb,
lib/vanagon/platform/solaris_10.rb,
lib/vanagon/platform/solaris_11.rb
Overview
Vanagon classes generally don’t implement JSON or Hash functionality so those need to be monkey-patched for useful inspection.
Defined Under Namespace
Classes: DEB, DSL, OSX, RPM, Solaris10, Solaris11, Windows
Constant Summary collapse
- PLATFORM_REGEX =
Platform names currently contain some information about the platform. Fields within the name are delimited by the ‘-’ character, and this regex can be used to extract those fields.
/^(.*)-(.*)-(.*)$/.freeze
- VERSION_REGEX =
/^([=<>]+)\s*([^<>=]*)$/.freeze
Instance Attribute Summary collapse
-
#abs_resource_name ⇒ Object
Always-Be-Scheduling engine specific.
-
#architecture ⇒ String
Sets and gets the architecture of the platform.
-
#aws_ami ⇒ Object
AWS engine specific.
-
#aws_instance_type ⇒ Object
Returns the value of attribute aws_instance_type.
-
#aws_key ⇒ Object
Returns the value of attribute aws_key.
-
#aws_key_name ⇒ Object
Returns the value of attribute aws_key_name.
-
#aws_region ⇒ Object
Returns the value of attribute aws_region.
-
#aws_shutdown_behavior ⇒ Object
Returns the value of attribute aws_shutdown_behavior.
-
#aws_subnet_id ⇒ Object
Returns the value of attribute aws_subnet_id.
-
#aws_user_data ⇒ Object
Returns the value of attribute aws_user_data.
-
#aws_vpc_id ⇒ Object
Returns the value of attribute aws_vpc_id.
-
#brew ⇒ Object
This is macOS specific.
-
#build_dependencies ⇒ Object
Stores an Array of OpenStructs, each representing a complete command to be run to install external the needed toolchains and build dependencies for a given target platform.
-
#build_hosts ⇒ Object
Hardware engine specific.
-
#cflags ⇒ Object
Hold a string containing the values that a given platform should use when a Makefile is run - resolves to the CFLAGS and LDFLAGS variables.
-
#codename ⇒ Object
this is Debian/Ubuntu specific.
-
#copy ⇒ Object
Each of these holds the path or name of the command in question, e.g.
-
#cross_compiled ⇒ Object
Determines if a platform should be treated as cross-compiled or natively compiled.
-
#defaultdir ⇒ Object
Where does a given platform’s init system expect to find something resembling ‘defaults’ files.
-
#dist ⇒ String
Get the value of @dist, or derive it from the value of @os_name and @os_version.
-
#docker_image ⇒ Object
Docker engine specific.
-
#docker_run_args ⇒ Object
Returns the value of attribute docker_run_args.
-
#environment ⇒ Object
The overall Environment that a given platform should pass to each component.
-
#find ⇒ Object
Returns the value of attribute find.
-
#install ⇒ Object
Returns the value of attribute install.
-
#ldflags ⇒ Object
Returns the value of attribute ldflags.
-
#make ⇒ Object
Returns the value of attribute make.
-
#mktemp ⇒ Object
Returns the value of attribute mktemp.
-
#name ⇒ Object
Basic generic information related to a given instance of Platform.
-
#num_cores ⇒ Object
A string, containing the script that will be executed on the remote build target to determine how many CPU cores are available on that platform.
-
#os_name ⇒ String
Sets and gets the name of the operating system for the platform.
-
#os_version ⇒ String
Sets and gets the version of the operating system for the platform.
-
#output_dir(target_repo = "") ⇒ String
Get the output dir for packages.
-
#package_type ⇒ Object
The name of the sort of package type that a given platform expects, e.g.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#platform_triple ⇒ Object
Returns the value of attribute platform_triple.
-
#provisioning ⇒ Object
Stores an Array of Strings, which will be passed in as a shell script as part of the provisioning step for a given build target.
-
#rpmbuild ⇒ Object
This is RedHat/EL/Fedora/SLES specific.
-
#sed ⇒ Object
Returns the value of attribute sed.
-
#servicedir ⇒ Object
Where does a given platform expect to find init scripts/service files? e.g.
-
#servicetype ⇒ Object
The name of the sort of init system that a given platform uses.
-
#servicetypes ⇒ Object
Array of OpenStructs containing the servicetype and the corresponding servicedir.
-
#settings ⇒ Object
Freeform Hash of leftover settings.
-
#shasum ⇒ Object
Returns the value of attribute shasum.
-
#shell ⇒ Object
rubocop:disable Lint/DuplicateMethods.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#source_output_dir(target_repo = "") ⇒ String
Get the source dir for packages.
-
#ssh_port ⇒ Object
Generic engine.
-
#tar ⇒ Object
Returns the value of attribute tar.
-
#target_user ⇒ Object
Username to use when connecting to a build target.
-
#use_docker_exec ⇒ Object
Returns the value of attribute use_docker_exec.
-
#valid_operators ⇒ Object
Returns the value of attribute valid_operators.
-
#vmpooler_template ⇒ Object
VMpooler engine specific.
Class Method Summary collapse
-
.load_platform(platform_name, config_directory) ⇒ Vanagon::Platform
Loads a platform from the config/platforms directory.
Instance Method Summary collapse
-
#[](key) ⇒ Object
This allows instance variables to be accessed using the hash lookup syntax.
-
#add_build_repository(*args) ⇒ Object
Generic adder for build repositories.
-
#add_group(user) ⇒ String
Generate the scripts required to add a group to the package generated.
-
#add_user(user) ⇒ String
Generate the scripts required to add a user to the package generated.
-
#generate_compiled_archive(project) ⇒ Object
Save the generic compiled archive and relevant metadata as packaging output.
-
#get_service_dir(servicetype = '') ⇒ Object
Get configured service dir (added through plat.servicedir, or plat.servicetype ‘foo’, servicedir: ‘bar’).
-
#get_service_types ⇒ Object
Get all configured service types (added through plat.servicetype).
-
#initialize(name) ⇒ Vanagon::Platform
constructor
Platform constructor.
-
#is_aix? ⇒ true, false
Utility matcher to determine is the platform is an aix variety.
-
#is_amazon? ⇒ true, false
Utility matcher to determine is the platform is a amazon linux variety.
-
#is_cisco_wrlinux? ⇒ true, false
Utility matcher to determine is the platform is a cisco-wrlinux variety.
-
#is_cross_compiled? ⇒ true, false
Utility matcher to determine if the platform is a cross-compiled variety.
-
#is_cross_compiled_linux? ⇒ true, false
Utility matcher to determine if the platform is a cross-compiled Linux variety.
-
#is_deb? ⇒ true, false
Utility matcher to determine is the platform is a debian variety.
-
#is_debian? ⇒ true, false
Utility matcher to determine is the platform is a debian variety.
-
#is_el8? ⇒ true, false
Utility matcher to determine if the platform is of an EL 8 variety.
-
#is_el? ⇒ true, false
Utility matcher to determine is the platform is an enterprise linux variety.
-
#is_eos? ⇒ true, false
Utility matcher to determine is the platform is an eos variety.
-
#is_fedora? ⇒ true, false
Utility matcher to determine is the platform is a fedora variety.
-
#is_fips? ⇒ true, false
Utility matcher to determine if the platform is a FIPS platform.
-
#is_huaweios? ⇒ true, false
Utility matcher to determine is the platform is a HuaweiOS variety.
-
#is_linux? ⇒ true, false
Utility matcher to determine is the platform is a linux variety.
-
#is_macos? ⇒ true, false
Utility matcher to determine if the platform is a macos or osx variety is_osx is a deprecated method that calls is_macos We still match for osx currently but this will change.
-
#is_osx? ⇒ true, false
deprecated
Deprecated.
Please use is_macos? instead
-
#is_rpm? ⇒ true, false
Utility matcher to determine is the platform is a redhat variety or uses rpm under the hood.
-
#is_sles? ⇒ true, false
Utility matcher to determine is the platform is a sles variety.
-
#is_solaris? ⇒ true, false
Utility matcher to determine is the platform is a solaris variety.
-
#is_ubuntu? ⇒ true, false
Utility matcher to determine is the platform is a ubuntu variety.
-
#is_unix? ⇒ true, false
Utility matcher to determine is the platform is a unix variety.
-
#is_windows? ⇒ true, false
Utility matcher to determine is the platform is a windows variety.
-
#package_override(project, var) ⇒ Object
Pass in a packaging override.
-
#provision_with(command) ⇒ Object
Set the command to turn the target machine into a builder for vanagon.
- #validate_operator(operator_string) ⇒ Object
-
#version_munger(version_string, default: '=') ⇒ Object
version strings for dependencies, conflicts, replaces, etc need some munging based on platform.
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
Platform constructor. Takes just the name. Also sets the @name, @os_name, @os_version and @architecture instance attributes as a side effect
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/vanagon/platform.rb', line 239 def initialize(name) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize @name = name @settings = {} @os_name = os_name @os_version = os_version @architecture = architecture @ssh_port = 22 # Environments are like Hashes but with specific constraints # around their keys and values. @environment = Vanagon::Environment.new @provisioning = [] @install ||= "install" @mktemp ||= "mktemp -d -p /var/tmp" @target_user ||= "root" @find ||= "find" @sed ||= "sed" @sort ||= "sort" @copy ||= "cp" @shasum ||= "sha1sum" @use_docker_exec = false # Our first attempt at defining metadata about a platform @cross_compiled ||= false @valid_operators ||= ['<', '>', '<=', '>=', '='] @servicetypes = [] end |
Instance Attribute Details
#abs_resource_name ⇒ Object
Always-Be-Scheduling engine specific
115 116 117 |
# File 'lib/vanagon/platform.rb', line 115 def abs_resource_name @abs_resource_name end |
#architecture ⇒ String
Sets and gets the architecture of the platform. Also has the side effect of setting the @architecture instance attribute
328 329 330 |
# File 'lib/vanagon/platform.rb', line 328 def architecture @architecture end |
#aws_ami ⇒ Object
AWS engine specific
126 127 128 |
# File 'lib/vanagon/platform.rb', line 126 def aws_ami @aws_ami end |
#aws_instance_type ⇒ Object
Returns the value of attribute aws_instance_type.
132 133 134 |
# File 'lib/vanagon/platform.rb', line 132 def aws_instance_type @aws_instance_type end |
#aws_key ⇒ Object
Returns the value of attribute aws_key.
131 132 133 |
# File 'lib/vanagon/platform.rb', line 131 def aws_key @aws_key end |
#aws_key_name ⇒ Object
Returns the value of attribute aws_key_name.
129 130 131 |
# File 'lib/vanagon/platform.rb', line 129 def aws_key_name @aws_key_name end |
#aws_region ⇒ Object
Returns the value of attribute aws_region.
130 131 132 |
# File 'lib/vanagon/platform.rb', line 130 def aws_region @aws_region end |
#aws_shutdown_behavior ⇒ Object
Returns the value of attribute aws_shutdown_behavior.
128 129 130 |
# File 'lib/vanagon/platform.rb', line 128 def aws_shutdown_behavior @aws_shutdown_behavior end |
#aws_subnet_id ⇒ Object
Returns the value of attribute aws_subnet_id.
134 135 136 |
# File 'lib/vanagon/platform.rb', line 134 def aws_subnet_id @aws_subnet_id end |
#aws_user_data ⇒ Object
Returns the value of attribute aws_user_data.
127 128 129 |
# File 'lib/vanagon/platform.rb', line 127 def aws_user_data @aws_user_data end |
#aws_vpc_id ⇒ Object
Returns the value of attribute aws_vpc_id.
133 134 135 |
# File 'lib/vanagon/platform.rb', line 133 def aws_vpc_id @aws_vpc_id end |
#brew ⇒ Object
This is macOS specific
57 58 59 |
# File 'lib/vanagon/platform.rb', line 57 def brew @brew end |
#build_dependencies ⇒ Object
Stores an Array of OpenStructs, each representing a complete command to be run to install external the needed toolchains and build dependencies for a given target platform.
76 77 78 |
# File 'lib/vanagon/platform.rb', line 76 def build_dependencies @build_dependencies end |
#build_hosts ⇒ Object
Hardware engine specific
112 113 114 |
# File 'lib/vanagon/platform.rb', line 112 def build_hosts @build_hosts end |
#cflags ⇒ Object
Hold a string containing the values that a given platform should use when a Makefile is run - resolves to the CFLAGS and LDFLAGS variables. This should be changed to take advantage of the Environment, so that we can better leverage Make’s Implicit Variables.
It should also be extended to support CXXFLAGS and CPPFLAGS ASAP.
66 67 68 |
# File 'lib/vanagon/platform.rb', line 66 def cflags @cflags end |
#codename ⇒ Object
this is Debian/Ubuntu specific
24 25 26 |
# File 'lib/vanagon/platform.rb', line 24 def codename @codename end |
#copy ⇒ Object
Each of these holds the path or name of the command in question, e.g. ‘copy = “/usr/local/bin/gcp”`, or `copy = “cp”`
46 47 48 |
# File 'lib/vanagon/platform.rb', line 46 def copy @copy end |
#cross_compiled ⇒ Object
Determines if a platform should be treated as cross-compiled or natively compiled.
94 95 96 |
# File 'lib/vanagon/platform.rb', line 94 def cross_compiled @cross_compiled end |
#defaultdir ⇒ Object
Where does a given platform’s init system expect to find something resembling ‘defaults’ files. Most likely to apply to Linux systems that use SysV-ish, upstart, or systemd init systems.
42 43 44 |
# File 'lib/vanagon/platform.rb', line 42 def defaultdir @defaultdir end |
#dist ⇒ String
Get the value of @dist, or derive it from the value of @os_name and @os_version. This is relatively RPM specific but ‘#codename’ is defined in Platform, and that’s just as Deb/Ubuntu specific. All of the accessors in the top-level Platform namespace should be refactored, but #dist will live here for now.
304 305 306 |
# File 'lib/vanagon/platform.rb', line 304 def dist @dist ||= @os_name.tr('-', '_') + @os_version end |
#docker_image ⇒ Object
Docker engine specific
121 122 123 |
# File 'lib/vanagon/platform.rb', line 121 def docker_image @docker_image end |
#docker_run_args ⇒ Object
Returns the value of attribute docker_run_args.
122 123 124 |
# File 'lib/vanagon/platform.rb', line 122 def docker_run_args @docker_run_args end |
#environment ⇒ Object
The overall Environment that a given platform should pass to each component
71 72 73 |
# File 'lib/vanagon/platform.rb', line 71 def environment @environment end |
#find ⇒ Object
Returns the value of attribute find.
47 48 49 |
# File 'lib/vanagon/platform.rb', line 47 def find @find end |
#install ⇒ Object
Returns the value of attribute install.
48 49 50 |
# File 'lib/vanagon/platform.rb', line 48 def install @install end |
#ldflags ⇒ Object
Returns the value of attribute ldflags.
67 68 69 |
# File 'lib/vanagon/platform.rb', line 67 def ldflags @ldflags end |
#make ⇒ Object
Returns the value of attribute make.
49 50 51 |
# File 'lib/vanagon/platform.rb', line 49 def make @make end |
#mktemp ⇒ Object
Returns the value of attribute mktemp.
50 51 52 |
# File 'lib/vanagon/platform.rb', line 50 def mktemp @mktemp end |
#name ⇒ Object
Basic generic information related to a given instance of Platform. e.g. The name we call it, the platform triplet (name-version-arch), etc.
19 20 21 |
# File 'lib/vanagon/platform.rb', line 19 def name @name end |
#num_cores ⇒ Object
A string, containing the script that will be executed on the remote build target to determine how many CPU cores are available on that platform. Vanagon will use that count to determine how many build threads should be initialized for compilations.
106 107 108 |
# File 'lib/vanagon/platform.rb', line 106 def num_cores @num_cores end |
#os_name ⇒ String
Sets and gets the name of the operating system for the platform. Also has the side effect of setting the @os_name instance attribute
312 313 314 |
# File 'lib/vanagon/platform.rb', line 312 def os_name @os_name end |
#os_version ⇒ String
Sets and gets the version of the operating system for the platform. Also has the side effect of setting the @os_version instance attribute
320 321 322 |
# File 'lib/vanagon/platform.rb', line 320 def os_version @os_version end |
#output_dir(target_repo = "") ⇒ String
Get the output dir for packages. If the output_dir was defined already (by the platform config) then don’t change it.
79 80 81 |
# File 'lib/vanagon/platform.rb', line 79 def output_dir @output_dir end |
#package_type ⇒ Object
The name of the sort of package type that a given platform expects, e.g. msi, rpm,
29 30 31 |
# File 'lib/vanagon/platform.rb', line 29 def package_type @package_type end |
#patch ⇒ Object
Returns the value of attribute patch.
51 52 53 |
# File 'lib/vanagon/platform.rb', line 51 def patch @patch end |
#platform_triple ⇒ Object
Returns the value of attribute platform_triple.
20 21 22 |
# File 'lib/vanagon/platform.rb', line 20 def platform_triple @platform_triple end |
#provisioning ⇒ Object
Stores an Array of Strings, which will be passed in as a shell script as part of the provisioning step for a given build target
90 91 92 |
# File 'lib/vanagon/platform.rb', line 90 def provisioning @provisioning end |
#rpmbuild ⇒ Object
This is RedHat/EL/Fedora/SLES specific
52 53 54 |
# File 'lib/vanagon/platform.rb', line 52 def rpmbuild @rpmbuild end |
#sed ⇒ Object
Returns the value of attribute sed.
53 54 55 |
# File 'lib/vanagon/platform.rb', line 53 def sed @sed end |
#servicedir ⇒ Object
Where does a given platform expect to find init scripts/service files? e.g. /etc/init.d, /usr/lib/systemd/system
35 36 37 |
# File 'lib/vanagon/platform.rb', line 35 def servicedir @servicedir end |
#servicetype ⇒ Object
The name of the sort of init system that a given platform uses
32 33 34 |
# File 'lib/vanagon/platform.rb', line 32 def servicetype @servicetype end |
#servicetypes ⇒ Object
Array of OpenStructs containing the servicetype and the corresponding servicedir
38 39 40 |
# File 'lib/vanagon/platform.rb', line 38 def servicetypes @servicetypes end |
#settings ⇒ Object
Freeform Hash of leftover settings
137 138 139 |
# File 'lib/vanagon/platform.rb', line 137 def settings @settings end |
#shasum ⇒ Object
Returns the value of attribute shasum.
56 57 58 |
# File 'lib/vanagon/platform.rb', line 56 def shasum @shasum end |
#shell ⇒ Object
rubocop:disable Lint/DuplicateMethods
99 100 101 |
# File 'lib/vanagon/platform.rb', line 99 def shell @shell end |
#sort ⇒ Object
Returns the value of attribute sort.
54 55 56 |
# File 'lib/vanagon/platform.rb', line 54 def sort @sort end |
#source_output_dir(target_repo = "") ⇒ String
Get the source dir for packages. Don’t change it if it was already defined by the platform config. Defaults to output_dir unless specified otherwise (RPM specifies this)
defined at the project level
82 83 84 |
# File 'lib/vanagon/platform.rb', line 82 def source_output_dir @source_output_dir end |
#ssh_port ⇒ Object
Generic engine
109 110 111 |
# File 'lib/vanagon/platform.rb', line 109 def ssh_port @ssh_port end |
#tar ⇒ Object
Returns the value of attribute tar.
55 56 57 |
# File 'lib/vanagon/platform.rb', line 55 def tar @tar end |
#target_user ⇒ Object
Username to use when connecting to a build target
85 86 87 |
# File 'lib/vanagon/platform.rb', line 85 def target_user @target_user end |
#use_docker_exec ⇒ Object
Returns the value of attribute use_docker_exec.
123 124 125 |
# File 'lib/vanagon/platform.rb', line 123 def use_docker_exec @use_docker_exec end |
#valid_operators ⇒ Object
Returns the value of attribute valid_operators.
139 140 141 |
# File 'lib/vanagon/platform.rb', line 139 def valid_operators @valid_operators end |
#vmpooler_template ⇒ Object
VMpooler engine specific
118 119 120 |
# File 'lib/vanagon/platform.rb', line 118 def vmpooler_template @vmpooler_template end |
Class Method Details
.load_platform(platform_name, config_directory) ⇒ Vanagon::Platform
Loads a platform from the config/platforms directory
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/vanagon/platform.rb', line 154 def self.load_platform(platform_name, config_directory) platform_name = File.basename(platform_name, '.rb') platform_file_name = "#{platform_name}.rb" platform_path = File.join(config_directory, platform_file_name) begin platform_definition = File.read(platform_path) rescue Errno::ENOENT, Errno::EACCES => e VanagonLogger.error "Error loading '#{platform_name}': #{e}" exit 1 end dsl = Vanagon::Platform::DSL.new(platform_name) begin dsl.instance_eval(platform_definition, platform_path, 1) dsl._platform rescue StandardError => e VanagonLogger.error "Error loading platform '#{platform_name}' using '#{platform_path}':" VanagonLogger.error(e) VanagonLogger.error e.backtrace.join("\n") raise e end end |
Instance Method Details
#[](key) ⇒ Object
This allows instance variables to be accessed using the hash lookup syntax
272 273 274 275 276 |
# File 'lib/vanagon/platform.rb', line 272 def [](key) if instance_variable_get("@#{key}") instance_variable_get("@#{key}") end end |
#add_build_repository(*args) ⇒ Object
Generic adder for build repositories
509 510 511 512 513 514 515 |
# File 'lib/vanagon/platform.rb', line 509 def add_build_repository(*args) if self.respond_to?(:add_repository) self.provision_with self.send(:add_repository, *args) else raise Vanagon::Error, "Adding a build repository not defined for #{name}" end end |
#add_group(user) ⇒ String
Generate the scripts required to add a group to the package generated. This will also update the group if it has changed.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/vanagon/platform.rb', line 183 def add_group(user) cmd_args = ["'#{user.group}'"] cmd_args.unshift '--system' if user.is_system groupadd_args = cmd_args.join "\s" groupmod_args = (cmd_args - ["--system"]).join "\s" return <<-HERE.undent if getent group '#{user.group}' > /dev/null 2>&1; then /usr/sbin/groupmod #{groupmod_args} else /usr/sbin/groupadd #{groupadd_args} fi HERE end |
#add_user(user) ⇒ String
Generate the scripts required to add a user to the package generated. This will also update the user if it has changed.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/vanagon/platform.rb', line 204 def add_user(user) # rubocop:disable Metrics/AbcSize cmd_args = ["'#{user.name}'"] cmd_args.unshift "--home '#{user.homedir}'" if user.homedir if user.shell cmd_args.unshift "--shell '#{user.shell}'" elsif user.is_system cmd_args.unshift "--shell '/usr/sbin/nologin'" end cmd_args.unshift "--gid '#{user.group}'" if user.group cmd_args.unshift '--system' if user.is_system # Collapse the cmd_args array into a string that can be used # as an argument to `useradd` useradd_args = cmd_args.join "\s" # Collapse the cmd_args array into a string that can be used # as an argument to `usermod`; If this is a system account, # then specify it as such for user addition only (strip # --system from usermod_args) usermod_args = (cmd_args - ["--system"]).join "\s" return <<-HERE.undent if getent passwd '#{user.name}' > /dev/null 2>&1; then /usr/sbin/usermod #{usermod_args} else /usr/sbin/useradd #{useradd_args} fi HERE end |
#generate_compiled_archive(project) ⇒ Object
Save the generic compiled archive and relevant metadata as packaging output. This will include a json file with all of the components/versions that were built and a bill of materials when relevant. The archive will be a gzipped tarball.
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/vanagon/platform.rb', line 524 def generate_compiled_archive(project) name_and_version = "#{project.name}-#{project.version}" name_and_version_and_platform = "#{name_and_version}.#{name}" name_and_platform = "#{project.name}.#{name}" final_archive = "output/#{name_and_version_and_platform}.tar.gz" archive_directory = "#{project.name}-archive" # previously, we weren't properly handling the case of custom BOM paths. # If we have a custom BOM path, during Makefile execution, the top-level # BOM is moved to the custom path. So, when cleaning up BOMs for non-custom # paths we just want to remove the BOM at the top level of the tarball. # But, if we have a custom BOM path we want to move it back to where it # was prior to the Makefile execution so we can preserve it as an artifact # but not leave it to conflict if it's installed in the same custom path # as a project using this archive. bill_of_materials_command = 'rm -f bill-of-materials' if project.bill_of_materials bill_of_materials_command = "mv .#{project.bill_of_materials.path}/bill-of-materials ../.." end [ "mkdir output", "mkdir #{archive_directory}", "gunzip -c #{name_and_version}.tar.gz | '#{tar}' -C #{archive_directory} -xf -", "rm #{name_and_version}.tar.gz", "cd #{archive_directory}/#{name_and_version}; #{bill_of_materials_command}; #{tar} cf ../../#{name_and_version_and_platform}.tar *", "gzip -9c #{name_and_version_and_platform}.tar > #{name_and_version_and_platform}.tar.gz", "cp build_metadata.#{name_and_platform}.json output/#{name_and_version_and_platform}.json", "cp bill-of-materials output/#{name_and_version_and_platform}-bill-of-materials ||:", "cp #{name_and_version_and_platform}.tar.gz output", "#{shasum} #{final_archive} > #{final_archive}.sha1" ] end |
#get_service_dir(servicetype = '') ⇒ Object
Get configured service dir (added through plat.servicedir, or plat.servicetype ‘foo’, servicedir: ‘bar’)
606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/vanagon/platform.rb', line 606 def get_service_dir(servicetype = '') if @servicetypes.empty? return @servicedir end servicedir = @servicetypes.select { |s| s.servicetype.include?(servicetype) }.flat_map(&:servicedir).compact if servicedir.size > 1 raise Vanagon::Error, "You can only have one service dir for each service type. Found '#{servicedir.join(',')}' for service type #{servicetype}" end servicedir.first end |
#get_service_types ⇒ Object
Get all configured service types (added through plat.servicetype)
593 594 595 596 597 598 599 600 601 |
# File 'lib/vanagon/platform.rb', line 593 def get_service_types if @servicetypes.any? @servicetypes.flat_map(&:servicetype).compact elsif @servicetype [@servicetype] else [] end end |
#is_aix? ⇒ true, false
Utility matcher to determine is the platform is an aix variety
407 408 409 |
# File 'lib/vanagon/platform.rb', line 407 def is_aix? return !!@name.match(/^aix-.*$/) end |
#is_amazon? ⇒ true, false
Utility matcher to determine is the platform is a amazon linux variety
386 387 388 |
# File 'lib/vanagon/platform.rb', line 386 def is_amazon? return !!@name.match(/^amazon-.*$/) end |
#is_cisco_wrlinux? ⇒ true, false
Utility matcher to determine is the platform is a cisco-wrlinux variety
otherwise
430 431 432 |
# File 'lib/vanagon/platform.rb', line 430 def is_cisco_wrlinux? return !!@name.match(/^cisco-wrlinux-.*$/) end |
#is_cross_compiled? ⇒ true, false
Utility matcher to determine if the platform is a cross-compiled variety
483 484 485 |
# File 'lib/vanagon/platform.rb', line 483 def is_cross_compiled? return @cross_compiled end |
#is_cross_compiled_linux? ⇒ true, false
Utility matcher to determine if the platform is a cross-compiled Linux variety. Many of the customizations needed to cross-compile for Linux are similar, so it’s useful to group them together vs. other cross-compiled OSes.
492 493 494 |
# File 'lib/vanagon/platform.rb', line 492 def is_cross_compiled_linux? is_cross_compiled? && is_linux? end |
#is_deb? ⇒ true, false
Utility matcher to determine is the platform is a debian variety
335 336 337 |
# File 'lib/vanagon/platform.rb', line 335 def is_deb? return !!@name.match(/^(debian|ubuntu|cumulus|huaweios)-.*$/) end |
#is_debian? ⇒ true, false
Utility matcher to determine is the platform is a debian variety
393 394 395 |
# File 'lib/vanagon/platform.rb', line 393 def is_debian? return !!@name.match(/^debian-.*$/) end |
#is_el8? ⇒ true, false
Utility matcher to determine if the platform is of an EL 8 variety
358 359 360 |
# File 'lib/vanagon/platform.rb', line 358 def is_el8? return !!@name.match(/^(el|redhat|redhatfips)-8.*$/) end |
#is_el? ⇒ true, false
Utility matcher to determine is the platform is an enterprise linux variety
351 352 353 |
# File 'lib/vanagon/platform.rb', line 351 def is_el? return !!@name.match(/^(el|redhat|redhatfips)-.*$/) end |
#is_eos? ⇒ true, false
Utility matcher to determine is the platform is an eos variety
414 415 416 |
# File 'lib/vanagon/platform.rb', line 414 def is_eos? return !!@name.match(/^eos-.*$/) end |
#is_fedora? ⇒ true, false
Utility matcher to determine is the platform is a fedora variety
379 380 381 |
# File 'lib/vanagon/platform.rb', line 379 def is_fedora? return !!@name.match(/^fedora-.*$/) end |
#is_fips? ⇒ true, false
Utility matcher to determine if the platform is a FIPS platform
365 366 367 |
# File 'lib/vanagon/platform.rb', line 365 def is_fips? return @name.include?('fips') end |
#is_huaweios? ⇒ true, false
Utility matcher to determine is the platform is a HuaweiOS variety
421 422 423 |
# File 'lib/vanagon/platform.rb', line 421 def is_huaweios? return !!@name.match(/^huaweios-.*$/) end |
#is_linux? ⇒ true, false
Utility matcher to determine is the platform is a linux variety
476 477 478 |
# File 'lib/vanagon/platform.rb', line 476 def is_linux? !is_windows? && !is_unix? end |
#is_macos? ⇒ true, false
Utility matcher to determine if the platform is a macos or osx variety is_osx is a deprecated method that calls is_macos We still match for osx currently but this will change
448 449 450 |
# File 'lib/vanagon/platform.rb', line 448 def is_macos? !!(@name =~ /^macos-.*$/ || @name =~ /^osx-.*$/) end |
#is_osx? ⇒ true, false
Please use is_macos? instead
Utility matcher to determine if the platform is an osx variety
438 439 440 441 |
# File 'lib/vanagon/platform.rb', line 438 def is_osx? VanagonLogger.info "is_osx? is a deprecated method, please use #is_macos? instead." is_macos? end |
#is_rpm? ⇒ true, false
Utility matcher to determine is the platform is a redhat variety or uses rpm under the hood
under the hood, false otherwise
344 345 346 |
# File 'lib/vanagon/platform.rb', line 344 def is_rpm? return !!@name.match(/^(aix|cisco-wrlinux|el|eos|fedora|sles|redhat|redhatfips)-.*$/) end |
#is_sles? ⇒ true, false
Utility matcher to determine is the platform is a sles variety
372 373 374 |
# File 'lib/vanagon/platform.rb', line 372 def is_sles? return !!@name.match(/^sles-.*$/) end |
#is_solaris? ⇒ true, false
Utility matcher to determine is the platform is a solaris variety
455 456 457 |
# File 'lib/vanagon/platform.rb', line 455 def is_solaris? return !!@name.match(/^solaris-.*$/) end |
#is_ubuntu? ⇒ true, false
Utility matcher to determine is the platform is a ubuntu variety
400 401 402 |
# File 'lib/vanagon/platform.rb', line 400 def is_ubuntu? return !!@name.match(/^ubuntu-.*$/) end |
#is_unix? ⇒ true, false
Utility matcher to determine is the platform is a unix variety
462 463 464 |
# File 'lib/vanagon/platform.rb', line 462 def is_unix? return !!@name.match(/^(solaris|aix|osx)-.*$/) end |
#is_windows? ⇒ true, false
Utility matcher to determine is the platform is a windows variety
469 470 471 |
# File 'lib/vanagon/platform.rb', line 469 def is_windows? return !!@name.match(/^windows.*$/) end |
#package_override(project, var) ⇒ Object
Pass in a packaging override. This needs to be implemented for each individual platform so that this input ends up in the right place.
501 502 503 |
# File 'lib/vanagon/platform.rb', line 501 def package_override(project, var) fail "I don't know how to set package overrides for #{name}, teach me?" end |
#provision_with(command) ⇒ Object
Set the command to turn the target machine into a builder for vanagon
561 562 563 564 |
# File 'lib/vanagon/platform.rb', line 561 def provision_with(command) provisioning << command provisioning.flatten! end |
#validate_operator(operator_string) ⇒ Object
587 588 589 |
# File 'lib/vanagon/platform.rb', line 587 def validate_operator(operator_string) valid_operators.include?(operator_string) end |
#version_munger(version_string, default: '=') ⇒ Object
version strings for dependencies, conflicts, replaces, etc need some munging based on platform.
573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/vanagon/platform.rb', line 573 def version_munger(version_string, default: '=') match = version_string.match(VERSION_REGEX) if match.nil? VanagonLogger.info "Passing a version without an operator is deprecated!" operator = default version = version_string end operator ||= match[1] version ||= match[2] fail "Operator '#{operator}' is invalid" unless validate_operator(operator) "#{operator} #{version}" end |