Class: Ci::Workloads::WorkloadDefinition
- Inherits:
-
Object
- Object
- Ci::Workloads::WorkloadDefinition
- Defined in:
- lib/ci/workloads/workload_definition.rb
Overview
This class knows how to take a minimal set of attributes and construct a valid CI job yaml definition. It may in future be able to construct the definitions for other ways of running a workload (e.g. CI steps)
Constant Summary collapse
- DEFAULT_TIMEOUT =
2.hours
Instance Attribute Summary collapse
-
#artifacts_paths ⇒ Object
Returns the value of attribute artifacts_paths.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#image ⇒ Object
Returns the value of attribute image.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_variable(name, value) ⇒ Object
-
#initialize {|_self| ... } ⇒ WorkloadDefinition
constructor
A new instance of WorkloadDefinition.
- #to_job_hash ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ WorkloadDefinition
Returns a new instance of WorkloadDefinition.
18 19 20 21 22 23 |
# File 'lib/ci/workloads/workload_definition.rb', line 18 def initialize self.timeout = DEFAULT_TIMEOUT @variables = {} @commands = [] yield self if block_given? end |
Instance Attribute Details
#artifacts_paths ⇒ Object
Returns the value of attribute artifacts_paths.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def artifacts_paths @artifacts_paths end |
#cache ⇒ Object
Returns the value of attribute cache.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def cache @cache end |
#commands ⇒ Object
Returns the value of attribute commands.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def commands @commands end |
#image ⇒ Object
Returns the value of attribute image.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def image @image end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def @tags end |
#timeout ⇒ Object
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def timeout @timeout end |
#variables ⇒ Object
Returns the value of attribute variables.
10 11 12 |
# File 'lib/ci/workloads/workload_definition.rb', line 10 def variables @variables end |
Instance Method Details
#add_variable(name, value) ⇒ Object
25 26 27 |
# File 'lib/ci/workloads/workload_definition.rb', line 25 def add_variable(name, value) self.variables = variables.merge(name => value) end |
#to_job_hash ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ci/workloads/workload_definition.rb', line 29 def to_job_hash raise ArgumentError, "image cannot be empty" unless image.present? raise ArgumentError, "commands cannot be empty" unless commands.any? result = { image: image, stage: 'build', timeout: "#{timeout} seconds", variables: , script: commands } result[:artifacts] = { paths: artifacts_paths } if artifacts_paths.present? result[:cache] = cache if cache.present? result[:tags] = if .present? result end |