avodeploy 0.4.2 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,98 +17,94 @@
17
17
  =end
18
18
 
19
19
  module AvoDeploy
20
- module Task
21
- class RemoteTaskExecutionEnvironment < TaskExecutionEnvironment
22
-
23
- attr_accessor :config
24
-
25
- # Creates a connection between the local and the remote system over ssh
26
- def establish_connection
27
- AvoDeploy::Deployment.instance.log.info "connecting to #{get(:user)}@#{get(:host)}..."
28
-
29
- begin
30
- @session = ::Net::SSH.start(get(:host), get(:user))
31
- rescue ::Net::SSH::AuthenticationFailed => e
32
- handle_abort e
33
- end
34
- end
35
-
36
- # Checks, if all utilities are available for the deployment process
37
- # to be executed
38
- #
39
- # @param utils [Array] array with utilities to check
40
- def check_util_availability(utils)
41
- super(utils, 'remotely')
42
- end
43
-
44
- # Executes a command via ssh
45
- #
46
- # @param ssh [Net::SSH::Connection::Session] ssh session
47
- # @param command [String] the command to execute
48
- def ssh_exec!(ssh, command)
49
- stdout_data = ""
50
- stderr_data = ""
51
- exit_code = nil
52
- exit_signal = nil
53
- ssh.open_channel do |channel|
54
- channel.exec(command) do |ch, success|
55
- unless success
56
- abort "FAILED: couldn't execute command (ssh.channel.exec)"
57
- end
58
- channel.on_data do |ch,data|
59
- stdout_data+=data
60
- end
61
-
62
- channel.on_extended_data do |ch,type,data|
63
- stderr_data+=data
64
- end
65
-
66
- channel.on_request("exit-status") do |ch,data|
67
- exit_code = data.read_long
68
- end
69
-
70
- channel.on_request("exit-signal") do |ch, data|
71
- exit_signal = data.read_long
72
- end
73
- end
74
- end
75
- ssh.loop
76
-
77
- result = AvoDeploy::CommandExecutionResult.new
78
- result.stdin = command
79
- result.stdout = stdout_data
80
- result.stderr = stderr_data
81
- result.retval = exit_code
82
-
83
- result
84
- end
85
-
86
- # Executes a command on the remote system
87
- #
88
- # @param cmd [String] the command to execute
89
- # @return [CommandExecutionResult] result of the command exection
90
- def command(cmd)
91
- AvoDeploy::Deployment.instance.log.info "Executing [" + cmd.yellow + "] on remote " + get(:name).to_s.cyan
92
-
93
- result = AvoDeploy::CommandExecutionResult.new
94
-
95
- begin
96
- result = ssh_exec!(@session, cmd)
97
-
98
- if result.stdout.nil? == false && result.stdout.empty? == false
99
- AvoDeploy::Deployment.instance.log.debug "Stdout@#{get(:host)}: ".cyan + result.stdout.green
100
- end
101
-
102
- if result.stderr.nil? == false && result.stderr.empty? == false
103
- AvoDeploy::Deployment.instance.log.debug "Stderr@#{get(:host)}: ".cyan + result.stderr.red
104
- end
105
- rescue Exception => e
106
- handle_abort e
107
- end
108
-
109
- result
110
- end
111
-
112
- end
113
- end
20
+ module Task
21
+ class RemoteTaskExecutionEnvironment < TaskExecutionEnvironment
22
+
23
+ attr_accessor :config
24
+
25
+ # Creates a connection between the local and the remote system over ssh
26
+ def establish_connection
27
+ AvoDeploy::Deployment.instance.log.debug "connecting to #{get(:user)}@#{get(:host)}..."
28
+
29
+ begin
30
+ @session = ::Net::SSH.start(get(:host), get(:user), port: get(:port), timeout: 30)
31
+ rescue ::Net::SSH::AuthenticationFailed => e
32
+ handle_abort e
33
+ end
34
+ end
35
+
36
+ # Checks, if all utilities are available for the deployment process
37
+ # to be executed
38
+ #
39
+ # @param utils [Array] array with utilities to check
40
+ def check_util_availability(utils)
41
+ super(utils, 'remotely')
42
+ end
43
+
44
+ # Executes a command via ssh
45
+ #
46
+ # @param ssh [Net::SSH::Connection::Session] ssh session
47
+ # @param command [String] the command to execute
48
+ def ssh_exec!(ssh, command)
49
+ stdout_data = ""
50
+ stderr_data = ""
51
+ exit_code = nil
52
+
53
+ ssh.open_channel do |channel|
54
+ channel.exec(command) do |ch, success|
55
+ unless success
56
+ abort "FAILED: couldn't execute command (ssh.channel.exec)"
57
+ end
58
+ channel.on_data do |ch, data|
59
+ stdout_data+=data
60
+ end
61
+
62
+ channel.on_extended_data do |ch, type, data|
63
+ stderr_data+=data
64
+ end
65
+
66
+ channel.on_request("exit-status") do |ch, data|
67
+ exit_code = data.read_long
68
+ end
69
+ end
70
+ end
71
+ ssh.loop
72
+
73
+ result = AvoDeploy::CommandExecutionResult.new
74
+ result.stdin = command
75
+ result.stdout = stdout_data
76
+ result.stderr = stderr_data
77
+ result.retval = exit_code
78
+
79
+ result
80
+ end
81
+
82
+ # Executes a command on the remote system
83
+ #
84
+ # @param cmd [String] the command to execute
85
+ # @return [CommandExecutionResult] result of the command exection
86
+ def command(cmd)
87
+ AvoDeploy::Deployment.instance.log.info "Executing [" + cmd.yellow + "] on remote " + get(:name).to_s.cyan
88
+
89
+ result = AvoDeploy::CommandExecutionResult.new
90
+
91
+ begin
92
+ result = ssh_exec!(@session, cmd)
93
+
94
+ if result.stdout.nil? == false && result.stdout.empty? == false
95
+ AvoDeploy::Deployment.instance.log.debug "Stdout@#{get(:host)}: ".cyan + result.stdout.green
96
+ end
97
+
98
+ if result.stderr.nil? == false && result.stderr.empty? == false
99
+ AvoDeploy::Deployment.instance.log.debug "Stderr@#{get(:host)}: ".cyan + result.stderr.red
100
+ end
101
+ rescue Exception => e
102
+ handle_abort e
103
+ end
104
+
105
+ result
106
+ end
107
+
108
+ end
109
+ end
114
110
  end
@@ -17,60 +17,71 @@
17
17
  =end
18
18
 
19
19
  module AvoDeploy
20
- module Task
21
- class Task
20
+ module Task
21
+ class Task
22
22
 
23
- attr_accessor :name
24
- attr_accessor :scope
25
- attr_accessor :visibility
26
- attr_accessor :block
27
- attr_accessor :desc
23
+ attr_accessor :name
24
+ attr_accessor :scope
25
+ attr_accessor :visibility
26
+ attr_accessor :block
27
+ attr_accessor :desc
28
+ attr_accessor :remote_only
29
+ attr_accessor :remote_except
28
30
 
29
- # Creates a new task from a task block in the deployment configuration process
30
- #
31
- # @param name [Symbol] name of the task
32
- # @param options [Hash] command options
33
- # @param block [Block] code block of the task
34
- # @return [Task] the task instance
35
- def self.from_task_block(name, options, &block)
36
- instance = self.new
31
+ # Creates a new task from a task block in the deployment configuration process
32
+ #
33
+ # @param name [Symbol] name of the task
34
+ # @param options [Hash] command options
35
+ # @param block [Block] code block of the task
36
+ # @return [Task] the task instance
37
+ def self.from_task_block(name, options, &block)
38
+ instance = self.new
37
39
 
38
- instance.name = name
39
- instance.block = block
40
+ instance.name = name
41
+ instance.block = block
40
42
 
41
- instance.scope = :local
43
+ instance.scope = :local
42
44
 
43
- if options.has_key?(:scope) && options[:scope] == :remote
44
- instance.scope = :remote
45
- end
45
+ if options.has_key?(:scope) && options[:scope] == :remote
46
+ instance.scope = :remote
47
+ end
46
48
 
47
- instance.visibility = :public
49
+ instance.visibility = :public
48
50
 
49
- if options.has_key?(:visibility) && options[:visibility] == :private
50
- instance.visibility = :private
51
- end
51
+ if options.has_key?(:visibility) && options[:visibility] == :private
52
+ instance.visibility = :private
53
+ end
52
54
 
53
- if options.has_key?(:desc)
54
- instance.desc = options[:desc]
55
- end
55
+ if options.has_key?(:desc)
56
+ instance.desc = options[:desc]
57
+ end
56
58
 
57
- instance
58
- end
59
+ if options.has_key?(:only)
60
+ instance.remote_only = options[:only]
61
+ end
59
62
 
60
- # Runs the code of a task
61
- #
62
- # @param env [TaskExecutionEnvironment] the environment to invoke the task in
63
- # @return [mixed] result of the code block
64
- def invoke(env)
65
- raise ArgumentError 'env must be a valid TaskExecutionEnvironment' unless env.kind_of?(TaskExecutionEnvironment)
63
+ if options.has_key?(:except)
64
+ instance.remote_except = options[:except]
65
+ end
66
66
 
67
- avo = AvoDeploy::Deployment.instance
67
+ instance
68
+ end
68
69
 
69
- avo.log.debug "Running task #{@name}"
70
+ # Runs the code of a task
71
+ #
72
+ # @param env [TaskExecutionEnvironment] the environment to invoke the task in
73
+ # @param options [Hash] a hash contining additional options
74
+ # @return [mixed] result of the code block
75
+ def invoke(env, options = {})
76
+ raise ArgumentError 'env must be a valid TaskExecutionEnvironment' unless env.kind_of?(TaskExecutionEnvironment)
70
77
 
71
- env.instance_eval(&@block)
72
- end
78
+ avo = AvoDeploy::Deployment.instance
73
79
 
74
- end
75
- end
80
+ avo.log.debug "Running task #{@name}"
81
+
82
+ env.instance_eval(&@block)
83
+ end
84
+
85
+ end
86
+ end
76
87
  end
@@ -18,10 +18,10 @@
18
18
 
19
19
  module AvoDeploy
20
20
  module Task
21
- class TaskDependency
22
- attr_accessor :task_name
23
- attr_accessor :dependent_task_name
24
- attr_accessor :type
25
- end
21
+ class TaskDependency
22
+ attr_accessor :task_name
23
+ attr_accessor :dependent_task_name
24
+ attr_accessor :type
25
+ end
26
26
  end
27
27
  end
@@ -17,72 +17,83 @@
17
17
  =end
18
18
 
19
19
  module AvoDeploy
20
- module Task
21
- class TaskExecutionEnvironment
20
+ module Task
21
+ class TaskExecutionEnvironment
22
22
 
23
- # Initialized the environment
24
- #
25
- # @param config [Hash] deployment configuration
26
- def initialize(config)
27
- # @todo check
28
- @config = config
29
- end
23
+ attr_accessor :scm
24
+ attr_accessor :options
30
25
 
31
- # Assigns the scm provider
32
- #
33
- # @param scm_provider [ScmProvider] the scm provider to assign
34
- def scm_provider=(scm_provider)
35
- @scm = scm_provider
36
- end
26
+ # Initialized the environment
27
+ #
28
+ # @param config [Hash] deployment configuration
29
+ def initialize(config)
30
+ # @todo check
31
+ @config = config
32
+ end
37
33
 
38
- # Checks, if all utilities are available for the deployment process
39
- # to be executed
40
- #
41
- # @param utils [Array] array with utilities to check
42
- def check_util_availability(utils, system_name)
43
- begin
44
- utils.each do |util|
45
- if command("command -v #{util} >/dev/null 2>&1 || exit 1;").retval == 1
46
- msg = "command line utility '#{util}' is not installed #{system_name}"
34
+ # Runs a task without dependencies
35
+ #
36
+ # @param task_name [Symbol] task name to execute
37
+ # @return [Object] the task result
38
+ def run_nodeps(task_name)
39
+ AvoDeploy::Deployment.instance.task_manager.invoke_task_oneshot(task_name)
40
+ end
47
41
 
48
- raise RuntimeError, msg
49
- end
50
- end
51
- rescue Exception => e
52
- handle_abort e
53
- end
54
- end
42
+ # Runs a task chain
43
+ #
44
+ # @param task_name [Symbol] task name to invoke
45
+ def run(task_name)
46
+ AvoDeploy::Deployment.instance.task_manager.invoke_task_chain_containing(task_name)
47
+ end
55
48
 
56
- # Returns the logger instance
57
- #
58
- # @return [Logger] log instance
59
- def log
60
- AvoDeploy::Deployment.instance.log
61
- end
49
+ # Checks, if all utilities are available for the deployment process
50
+ # to be executed
51
+ #
52
+ # @param utils [Array] array with utilities to check
53
+ def check_util_availability(utils, system_name)
54
+ begin
55
+ utils.each do |util|
56
+ if command("command -v #{util} >/dev/null 2>&1 || exit 1;").retval == 1
57
+ msg = "command line utility '#{util}' is not installed #{system_name}"
62
58
 
63
- # Sets a configuration item
64
- #
65
- # @param key [Symbol] configuration key
66
- # @param value [mixed] configuration value
67
- def set(key, value)
68
- @config[key] = value
69
- end
59
+ raise RuntimeError, msg
60
+ end
61
+ end
62
+ rescue Exception => e
63
+ handle_abort e
64
+ end
65
+ end
70
66
 
71
- # Returns a configuration item if set
72
- #
73
- # @param key [Symbol] configuration key
74
- # @return [mixed] configuration value
75
- def get(key)
76
- @config[key]
77
- end
67
+ # Returns the logger instance
68
+ #
69
+ # @return [Logger] log instance
70
+ def log
71
+ AvoDeploy::Deployment.instance.log
72
+ end
78
73
 
79
- # Shorthand for exception handling
80
- #
81
- # @param e [Exception] the exception to handle
82
- def handle_abort(e)
83
- AvoDeploy::Deployment.instance.handle_abort(e)
84
- end
74
+ # Sets a configuration item
75
+ #
76
+ # @param key [Symbol] configuration key
77
+ # @param value [mixed] configuration value
78
+ def set(key, value)
79
+ @config[key] = value
80
+ end
85
81
 
86
- end
87
- end
82
+ # Returns a configuration item if set
83
+ #
84
+ # @param key [Symbol] configuration key
85
+ # @return [mixed] configuration value
86
+ def get(key)
87
+ @config[key]
88
+ end
89
+
90
+ # Shorthand for exception handling
91
+ #
92
+ # @param e [Exception] the exception to handle
93
+ def handle_abort(e)
94
+ AvoDeploy::Deployment.instance.handle_abort(e)
95
+ end
96
+
97
+ end
98
+ end
88
99
  end