Class: Vanagon::Platform::DSL
- Inherits:
-
Object
- Object
- Vanagon::Platform::DSL
- Defined in:
- lib/vanagon/platform/dsl.rb
Instance Method Summary collapse
-
#_platform ⇒ Vanagon::Platform
Accessor for the platform.
-
#abs_resource_name(resource_name) ⇒ Object
Set the name of this platform as always-be-scheduling (ABS) expects it.
-
#add_build_repository(*args) ⇒ Object
Generic adder for build repositories.
-
#apt_repo(definition, gpg_key = nil) ⇒ Object
deprecated
Deprecated.
Please use the add_build_repository DSL method instead. apt_repo will be removed in a future vanagon release.
-
#aws_ami(ami_name) ⇒ Object
Set the ami for the platform to use.
-
#aws_instance_type(instance_type = 't1.micro') ⇒ Object
Set the instaince type.
-
#aws_key_name(key_name = 'vanagon') ⇒ Object
Set the key_name used.
-
#aws_region(region = 'us-east-1') ⇒ Object
Set the region, this defaults to us-east-1.
-
#aws_shutdown_behavior(shutdown_behavior = 'terminate') ⇒ Object
Set the shutdown behavior for aws.
-
#aws_subnet_id(subnet_id) ⇒ Object
Set the subnet_id.
-
#aws_user_data(userdata) ⇒ Object
Set the user data used in AWS to do setup.
-
#build_hosts(*args) ⇒ Object
(also: #build_host)
Set the list of possible host to perform a build on (when not using pooler or CLI flags).
-
#codename(codename) ⇒ Object
Set any codename this platform may have (debian for example).
-
#copy(copy_cmd) ⇒ Object
Set the path to copy for the platform.
-
#cross_compiled(xcc_flag) ⇒ Object
Set the cross_compiled flag for the platform.
-
#defaultdir(dir) ⇒ Object
Set the directory where default or sysconfig files live for the platform.
-
#dist(dist_string) ⇒ Object
define an explicit Dist for the platform (most likely used for RPM platforms).
-
#docker_image(image_name) ⇒ Object
Set the name of the docker image to use.
-
#docker_run_args(args) ⇒ Object
Set additional ‘docker run` arguments to pass when creating containers.
-
#environment(key, value) ⇒ Object
Adds an arbitrary environment variable to a Platform, which will be merged with any environment variables defined by the Project into the rendered Makefile.
-
#find(find_cmd) ⇒ Object
Set the path to find for the platform.
-
#initialize(platform_name) ⇒ Vanagon::Platform::DSL
constructor
Constructor for the DSL object.
-
#install(install_cmd) ⇒ Object
Set the path to the install command.
-
#install_build_dependencies_with(command, suffix = nil) ⇒ Object
Set the command to install any needed build dependencies for the target machine.
-
#make(make_cmd) ⇒ Object
Set the path to make for the platform.
-
#method_missing(method_name, *args) ⇒ Object
All purpose getter.
-
#mktemp(command) ⇒ Object
Set the path and options for the mktemp command be used by default.
-
#num_cores(num_cores_cmd) ⇒ Object
Sets the command to retrieve the number of cores available on a platform.
- #output_dir(directory) ⇒ Object
-
#package_type(pkg_type) ⇒ Object
Set the type of package we are going to build for this platform.
-
#patch(patch_cmd) ⇒ Object
Set the path to patch for the platform.
-
#platform(platform_name, &block) {|_self| ... } ⇒ Object
Primary way of interacting with the DSL.
-
#platform_triple(triple) ⇒ Object
Set the platform_triple for the platform.
-
#provision_with(command) ⇒ Object
Set the command to turn the target machine into a builder for vanagon.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#rpmbuild(rpmbuild_cmd) ⇒ Object
Set the path to rpmbuild for the platform.
-
#sed(command) ⇒ Object
Set the path to sed for the platform.
-
#servicedir(dir) ⇒ Object
Set the directory where service files or init scripts live for the platform.
-
#servicetype(type, servicedir: nil) ⇒ Object
Set the servicetype for the platform so that services can be installed correctly.
- #setting(name, value) ⇒ Object
- #settings ⇒ Object
- #shasum(sha1sum_command) ⇒ Object
-
#shell(shell_path) ⇒ Object
Set the path for Make’s SHELL for the platform.
-
#sort(sort_cmd) ⇒ Object
Set the path to sort for the platform.
- #source_output_dir(directory) ⇒ Object
-
#ssh_port(port = 22) ⇒ Object
Set the port for ssh to use if it’s not 22.
-
#tar(tar_cmd) ⇒ Object
Set the path to tar for the platform.
-
#target_host(target_host) ⇒ Object
Set the target ip address or hostname to start build.
-
#target_user(user = "root") ⇒ Object
Set the target user to login with.
-
#use_docker_exec(bool) ⇒ Object
Specify whether to use Docker exec instead of SSH to run commands.
-
#vcloud_name(cloud_name) ⇒ Object
deprecated
Deprecated.
Please use vmpooler_template instead, this will be removed in a future vanagon release.
-
#vmpooler_template(template_name) ⇒ Object
Set the name of this platform as the vm pooler expects it.
-
#yum_repo(definition) ⇒ Object
deprecated
Deprecated.
Please use the add_build_repository DSL method instead. yum_repo will be removed in a future vanagon release.
-
#zypper_repo(definition) ⇒ Object
deprecated
Deprecated.
Please use the add_build_repository DSL method instead. zypper_repo will be removed in a future vanagon release.
Constructor Details
#initialize(platform_name) ⇒ Vanagon::Platform::DSL
Constructor for the DSL object
23 24 25 |
# File 'lib/vanagon/platform/dsl.rb', line 23 def initialize(platform_name) @name = platform_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
All purpose getter. This object, which is passed to the platform block, won’t have easy access to the attributes of the @platform, so we make a getter for each attribute.
We only magically handle get_ methods, any other methods just get the standard method_missing treatment.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vanagon/platform/dsl.rb', line 73 def method_missing(method_name, *args) attribute_match = method_name.to_s.match(/get_(.*)/) if attribute_match attribute = attribute_match.captures.first else super end @platform.send(attribute) end |
Instance Method Details
#_platform ⇒ Vanagon::Platform
Accessor for the platform.
62 63 64 |
# File 'lib/vanagon/platform/dsl.rb', line 62 def _platform @platform end |
#abs_resource_name(resource_name) ⇒ Object
Set the name of this platform as always-be-scheduling (ABS) expects it
286 287 288 |
# File 'lib/vanagon/platform/dsl.rb', line 286 def abs_resource_name(resource_name) @platform.abs_resource_name = resource_name end |
#add_build_repository(*args) ⇒ Object
Generic adder for build repositories
440 441 442 |
# File 'lib/vanagon/platform/dsl.rb', line 440 def add_build_repository(*args) @platform.add_build_repository(*args) end |
#apt_repo(definition, gpg_key = nil) ⇒ Object
Please use the add_build_repository DSL method instead. apt_repo will be removed in a future vanagon release.
Helper to setup a apt repository on a target system
413 414 415 416 |
# File 'lib/vanagon/platform/dsl.rb', line 413 def apt_repo(definition, gpg_key = nil) VanagonLogger.info "Please use the add_build_repository DSL method instead. apt_repo will be removed in a future vanagon release." self.add_build_repository(definition, gpg_key) end |
#aws_ami(ami_name) ⇒ Object
Set the ami for the platform to use
318 319 320 |
# File 'lib/vanagon/platform/dsl.rb', line 318 def aws_ami(ami_name) @platform.aws_ami = ami_name end |
#aws_instance_type(instance_type = 't1.micro') ⇒ Object
Set the instaince type. This defaults to t1.micro which is the free instance
353 354 355 |
# File 'lib/vanagon/platform/dsl.rb', line 353 def aws_instance_type(instance_type = 't1.micro') @platform.aws_instance_type = instance_type end |
#aws_key_name(key_name = 'vanagon') ⇒ Object
Set the key_name used. This should already exist on AWS.
346 347 348 |
# File 'lib/vanagon/platform/dsl.rb', line 346 def aws_key_name(key_name = 'vanagon') @platform.aws_key_name = key_name end |
#aws_region(region = 'us-east-1') ⇒ Object
Set the region, this defaults to us-east-1
332 333 334 |
# File 'lib/vanagon/platform/dsl.rb', line 332 def aws_region(region = 'us-east-1') @platform.aws_region = region end |
#aws_shutdown_behavior(shutdown_behavior = 'terminate') ⇒ Object
Set the shutdown behavior for aws. This will default to terminate the instance on shutdown
339 340 341 |
# File 'lib/vanagon/platform/dsl.rb', line 339 def aws_shutdown_behavior(shutdown_behavior = 'terminate') @platform.aws_shutdown_behavior = shutdown_behavior end |
#aws_subnet_id(subnet_id) ⇒ Object
Set the subnet_id. Use this to setup a subnet for your VPC to use.
360 361 362 |
# File 'lib/vanagon/platform/dsl.rb', line 360 def aws_subnet_id(subnet_id) @platform.aws_subnet_id = subnet_id end |
#aws_user_data(userdata) ⇒ Object
Set the user data used in AWS to do setup. Like cloud-config
325 326 327 |
# File 'lib/vanagon/platform/dsl.rb', line 325 def aws_user_data(userdata) @platform.aws_user_data = userdata end |
#build_hosts(*args) ⇒ Object Also known as: build_host
Set the list of possible host to perform a build on (when not using pooler or CLI flags)
259 260 261 262 |
# File 'lib/vanagon/platform/dsl.rb', line 259 def build_hosts(*args) raise ArgumentError, "build_hosts requires at least one host to be a build target." if args.empty? @platform.build_hosts = Array(args).flatten end |
#codename(codename) ⇒ Object
Set any codename this platform may have (debian for example)
396 397 398 |
# File 'lib/vanagon/platform/dsl.rb', line 396 def codename(codename) @platform.codename = codename end |
#copy(copy_cmd) ⇒ Object
Set the path to copy for the platform
151 152 153 |
# File 'lib/vanagon/platform/dsl.rb', line 151 def copy(copy_cmd) @platform.copy = copy_cmd end |
#cross_compiled(xcc_flag) ⇒ Object
Set the cross_compiled flag for the platform
158 159 160 |
# File 'lib/vanagon/platform/dsl.rb', line 158 def cross_compiled(xcc_flag) @platform.cross_compiled = !!xcc_flag end |
#defaultdir(dir) ⇒ Object
Set the directory where default or sysconfig files live for the platform
233 234 235 |
# File 'lib/vanagon/platform/dsl.rb', line 233 def defaultdir(dir) @platform.defaultdir = dir end |
#dist(dist_string) ⇒ Object
define an explicit Dist for the platform (most likely used for RPM platforms)
165 166 167 |
# File 'lib/vanagon/platform/dsl.rb', line 165 def dist(dist_string) @platform.dist = dist_string end |
#docker_image(image_name) ⇒ Object
Set the name of the docker image to use
293 294 295 |
# File 'lib/vanagon/platform/dsl.rb', line 293 def docker_image(image_name) @platform.docker_image = image_name end |
#docker_run_args(args) ⇒ Object
Set additional ‘docker run` arguments to pass when creating containers
300 301 302 |
# File 'lib/vanagon/platform/dsl.rb', line 300 def docker_run_args(args) @platform.docker_run_args = Array(args) end |
#environment(key, value) ⇒ Object
Adds an arbitrary environment variable to a Platform, which will be merged with any environment variables defined by the Project into the rendered Makefile
91 92 93 |
# File 'lib/vanagon/platform/dsl.rb', line 91 def environment(key, value) @platform.environment[key] = value end |
#find(find_cmd) ⇒ Object
Set the path to find for the platform
130 131 132 |
# File 'lib/vanagon/platform/dsl.rb', line 130 def find(find_cmd) @platform.find = find_cmd end |
#install(install_cmd) ⇒ Object
Set the path to the install command
178 179 180 |
# File 'lib/vanagon/platform/dsl.rb', line 178 def install(install_cmd) @platform.install = install_cmd end |
#install_build_dependencies_with(command, suffix = nil) ⇒ Object
Set the command to install any needed build dependencies for the target machine
214 215 216 |
# File 'lib/vanagon/platform/dsl.rb', line 214 def install_build_dependencies_with(command, suffix = nil) @platform.build_dependencies = OpenStruct.new({ :command => command, :suffix => suffix }) end |
#make(make_cmd) ⇒ Object
Set the path to make for the platform
98 99 100 |
# File 'lib/vanagon/platform/dsl.rb', line 98 def make(make_cmd) @platform.make = make_cmd end |
#mktemp(command) ⇒ Object
Set the path and options for the mktemp command be used by default
185 186 187 |
# File 'lib/vanagon/platform/dsl.rb', line 185 def mktemp(command) @platform.mktemp = command end |
#num_cores(num_cores_cmd) ⇒ Object
Sets the command to retrieve the number of cores available on a platform.
199 200 201 |
# File 'lib/vanagon/platform/dsl.rb', line 199 def num_cores(num_cores_cmd) @platform.num_cores = num_cores_cmd end |
#output_dir(directory) ⇒ Object
400 401 402 |
# File 'lib/vanagon/platform/dsl.rb', line 400 def output_dir(directory) @platform.output_dir = directory end |
#package_type(pkg_type) ⇒ Object
Set the type of package we are going to build for this platform
123 124 125 |
# File 'lib/vanagon/platform/dsl.rb', line 123 def package_type(pkg_type) @platform.package_type = pkg_type end |
#patch(patch_cmd) ⇒ Object
Set the path to patch for the platform
192 193 194 |
# File 'lib/vanagon/platform/dsl.rb', line 192 def patch(patch_cmd) @platform.patch = patch_cmd end |
#platform(platform_name, &block) {|_self| ... } ⇒ Object
Primary way of interacting with the DSL. Also a simple factory to get the right platform object.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vanagon/platform/dsl.rb', line 31 def platform(platform_name, &block) @platform = case platform_name when /^aix-/ Vanagon::Platform::RPM::AIX.new(@name) when /^(cisco-wrlinux|el|fedora|redhat|redhatfips)-/ Vanagon::Platform::RPM.new(@name) when /^sles-/ Vanagon::Platform::RPM::SLES.new(@name) when /^(cumulus|debian|huaweios|ubuntu)-/ Vanagon::Platform::DEB.new(@name) when /^eos-/ Vanagon::Platform::RPM::EOS.new(@name) when /^osx-/ Vanagon::Platform::OSX.new(@name) when /^solaris-10/ Vanagon::Platform::Solaris10.new(@name) when /^solaris-11/ Vanagon::Platform::Solaris11.new(@name) when /^windows/ Vanagon::Platform::Windows.new(@name) else fail "Platform not implemented for '#{@name}' yet. Please go do so..." end yield(self) @platform end |
#platform_triple(triple) ⇒ Object
Set the platform_triple for the platform
tools and cross-compilation
389 390 391 |
# File 'lib/vanagon/platform/dsl.rb', line 389 def platform_triple(triple) @platform.platform_triple = triple end |
#provision_with(command) ⇒ Object
Set the command to turn the target machine into a builder for vanagon
206 207 208 |
# File 'lib/vanagon/platform/dsl.rb', line 206 def provision_with(command) @platform.provision_with(command) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
84 85 86 |
# File 'lib/vanagon/platform/dsl.rb', line 84 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('get_') || super end |
#rpmbuild(rpmbuild_cmd) ⇒ Object
Set the path to rpmbuild for the platform
172 173 174 |
# File 'lib/vanagon/platform/dsl.rb', line 172 def rpmbuild(rpmbuild_cmd) @platform.rpmbuild = rpmbuild_cmd end |
#sed(command) ⇒ Object
Set the path to sed for the platform
137 138 139 |
# File 'lib/vanagon/platform/dsl.rb', line 137 def sed(command) @platform.sed = command end |
#servicedir(dir) ⇒ Object
Set the directory where service files or init scripts live for the platform
221 222 223 224 225 226 227 228 |
# File 'lib/vanagon/platform/dsl.rb', line 221 def servicedir(dir) @platform.servicedir = dir # Add to the servicetypes array if we haven't already if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty? @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir) end end |
#servicetype(type, servicedir: nil) ⇒ Object
Set the servicetype for the platform so that services can be installed correctly.
241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/vanagon/platform/dsl.rb', line 241 def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize if servicedir @platform.servicetypes << OpenStruct.new(:servicetype => type, :servicedir => servicedir) else @platform.servicetype = type end # Add to the servicetypes array if we haven't already if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty? @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir) end end |
#setting(name, value) ⇒ Object
444 445 446 |
# File 'lib/vanagon/platform/dsl.rb', line 444 def setting(name, value) @platform.settings[name] = value end |
#settings ⇒ Object
448 449 450 |
# File 'lib/vanagon/platform/dsl.rb', line 448 def settings @platform.settings end |
#shasum(sha1sum_command) ⇒ Object
116 117 118 |
# File 'lib/vanagon/platform/dsl.rb', line 116 def shasum(sha1sum_command) @platform.shasum = sha1sum_command end |
#shell(shell_path) ⇒ Object
Set the path for Make’s SHELL for the platform
105 106 107 |
# File 'lib/vanagon/platform/dsl.rb', line 105 def shell(shell_path) @platform.shell = shell_path end |
#sort(sort_cmd) ⇒ Object
Set the path to sort for the platform
144 145 146 |
# File 'lib/vanagon/platform/dsl.rb', line 144 def sort(sort_cmd) @platform.sort = sort_cmd end |
#source_output_dir(directory) ⇒ Object
404 405 406 |
# File 'lib/vanagon/platform/dsl.rb', line 404 def source_output_dir(directory) @platform.source_output_dir = directory end |
#ssh_port(port = 22) ⇒ Object
Set the port for ssh to use if it’s not 22
367 368 369 |
# File 'lib/vanagon/platform/dsl.rb', line 367 def ssh_port(port = 22) @platform.ssh_port = port end |
#tar(tar_cmd) ⇒ Object
Set the path to tar for the platform
112 113 114 |
# File 'lib/vanagon/platform/dsl.rb', line 112 def tar(tar_cmd) @platform.tar = tar_cmd end |
#target_host(target_host) ⇒ Object
Set the target ip address or hostname to start build
381 382 383 |
# File 'lib/vanagon/platform/dsl.rb', line 381 def target_host(target_host) @platform.target_host = target_host end |
#target_user(user = "root") ⇒ Object
Set the target user to login with. Defaults to root.
374 375 376 |
# File 'lib/vanagon/platform/dsl.rb', line 374 def target_user(user = "root") @platform.target_user = user end |
#use_docker_exec(bool) ⇒ Object
Specify whether to use Docker exec instead of SSH to run commands
This also causes Vanagon to use ‘docker cp` instead of `rsync` when copying files.
311 312 313 |
# File 'lib/vanagon/platform/dsl.rb', line 311 def use_docker_exec(bool) @platform.use_docker_exec = bool end |
#vcloud_name(cloud_name) ⇒ Object
Please use vmpooler_template instead, this will be removed in a future vanagon release.
Set the name of this platform as the vm pooler expects it
278 279 280 281 |
# File 'lib/vanagon/platform/dsl.rb', line 278 def vcloud_name(cloud_name) VanagonLogger.info "vcloud_name is a deprecated platform DSL method, and will be removed in a future vanagon release. Please use vmpooler_template instead." self.vmpooler_template(cloud_name) end |
#vmpooler_template(template_name) ⇒ Object
Set the name of this platform as the vm pooler expects it
270 271 272 |
# File 'lib/vanagon/platform/dsl.rb', line 270 def vmpooler_template(template_name) @platform.vmpooler_template = template_name end |
#yum_repo(definition) ⇒ Object
Please use the add_build_repository DSL method instead. yum_repo will be removed in a future vanagon release.
Helper to setup a yum repository on a target system
422 423 424 425 |
# File 'lib/vanagon/platform/dsl.rb', line 422 def yum_repo(definition) VanagonLogger.info "Please use the add_build_repository DSL method instead. yum_repo will be removed in a future vanagon release." self.add_build_repository(definition) end |
#zypper_repo(definition) ⇒ Object
Please use the add_build_repository DSL method instead. zypper_repo will be removed in a future vanagon release.
Helper to setup a zypper repository on a target system
431 432 433 434 |
# File 'lib/vanagon/platform/dsl.rb', line 431 def zypper_repo(definition) VanagonLogger.info "Please use the add_build_repository DSL method instead. zypper_repo will be removed in a future vanagon release." self.add_build_repository(definition) end |