Class: Kdeploy::Pipeline
- Inherits:
-
Object
- Object
- Kdeploy::Pipeline
- Defined in:
- lib/kdeploy/pipeline.rb
Overview
Pipeline class for managing deployment tasks and hosts
Instance Attribute Summary collapse
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#add_host(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) ⇒ Host
Add host to pipeline.
-
#add_hosts(hosts_config) ⇒ Object
Add multiple hosts from hash.
-
#add_task(name, hosts: nil, **options) ⇒ Task
Add task to pipeline.
-
#execute ⇒ Hash
Execute all tasks in pipeline.
-
#get_variable(key) ⇒ Object
Get global variable.
-
#hosts_with_role(role) ⇒ Array<Host>
Get hosts by role.
-
#initialize(name = 'default') ⇒ Pipeline
constructor
A new instance of Pipeline.
-
#set_variable(key, value) ⇒ Object
Set global variable.
-
#summary ⇒ Hash
Get pipeline summary.
-
#valid? ⇒ Boolean
Check if pipeline is valid.
-
#validate ⇒ Array<String>
Validate pipeline configuration.
Constructor Details
#initialize(name = 'default') ⇒ Pipeline
Returns a new instance of Pipeline.
8 9 10 11 12 13 |
# File 'lib/kdeploy/pipeline.rb', line 8 def initialize(name = 'default') @name = name @hosts = [] @tasks = [] @variables = {} end |
Instance Attribute Details
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/kdeploy/pipeline.rb', line 6 def hosts @hosts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/kdeploy/pipeline.rb', line 6 def name @name end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
6 7 8 |
# File 'lib/kdeploy/pipeline.rb', line 6 def tasks @tasks end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
6 7 8 |
# File 'lib/kdeploy/pipeline.rb', line 6 def variables @variables end |
Instance Method Details
#add_host(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) ⇒ Host
Add host to pipeline
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kdeploy/pipeline.rb', line 23 def add_host(hostname, user: nil, port: nil, ssh_options: {}, roles: [], vars: {}) host = Host.new( hostname, user: user, port: port, ssh_options: , roles: roles, vars: vars ) @hosts << host unless @hosts.include?(host) host end |
#add_hosts(hosts_config) ⇒ Object
Add multiple hosts from hash
38 39 40 41 42 43 |
# File 'lib/kdeploy/pipeline.rb', line 38 def add_hosts(hosts_config) hosts_config.each do |hostname, config| config ||= {} add_host_from_config(hostname, config) end end |
#add_task(name, hosts: nil, **options) ⇒ Task
Add task to pipeline
57 58 59 60 61 62 |
# File 'lib/kdeploy/pipeline.rb', line 57 def add_task(name, hosts: nil, **) target_hosts = hosts || @hosts task = create_task(name, target_hosts, ) @tasks << task task end |
#execute ⇒ Hash
Execute all tasks in pipeline
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kdeploy/pipeline.rb', line 80 def execute return empty_execution_result if @tasks.empty? log_pipeline_start start_time = Time.now results = execute_tasks duration = Time.now - start_time success_count = count_successful_tasks(results) log_pipeline_completion(duration, success_count) build_execution_result(results, duration, success_count) end |
#get_variable(key) ⇒ Object
Get global variable
74 75 76 |
# File 'lib/kdeploy/pipeline.rb', line 74 def get_variable(key) @variables[key.to_s] || @variables[key.to_sym] end |
#hosts_with_role(role) ⇒ Array<Host>
Get hosts by role
48 49 50 |
# File 'lib/kdeploy/pipeline.rb', line 48 def hosts_with_role(role) @hosts.select { |host| host.has_role?(role) } end |
#set_variable(key, value) ⇒ Object
Set global variable
67 68 69 |
# File 'lib/kdeploy/pipeline.rb', line 67 def set_variable(key, value) @variables[key.to_s] = value end |
#summary ⇒ Hash
Get pipeline summary
95 96 97 98 99 100 101 102 103 |
# File 'lib/kdeploy/pipeline.rb', line 95 def summary { name: @name, hosts_count: @hosts.size, tasks_count: @tasks.size, hosts: @hosts.map(&:hostname), tasks: @tasks.map(&:name) } end |
#valid? ⇒ Boolean
Check if pipeline is valid
117 118 119 |
# File 'lib/kdeploy/pipeline.rb', line 117 def valid? validate.empty? end |
#validate ⇒ Array<String>
Validate pipeline configuration
107 108 109 110 111 112 113 |
# File 'lib/kdeploy/pipeline.rb', line 107 def validate errors = [] errors.concat(validate_pipeline_structure) errors.concat(validate_hosts) errors.concat(validate_tasks) errors end |