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,169 +17,191 @@
17
17
  =end
18
18
 
19
19
  module AvoDeploy
20
- module Task
21
- class TaskManager
22
-
23
- attr_reader :dependencies
24
- attr_reader :chains
25
-
26
- # Initializes the task manager
27
- def initialize
28
- @chains = []
29
- @remote_env = nil
30
- @local_env = nil
31
- end
32
-
33
- # Adds a task to the task manager
34
- #
35
- # @param name [Symbol] task name
36
- # @param options [Hash] task options
37
- # @param block [Block] code of the task
38
- def add_task(name, options, &block)
39
- position = :after
40
- standalone = true
41
-
42
- if options.has_key?(:before)
43
- position = :before
44
- end
45
-
46
- key = name
47
-
48
- if options.has_key?(:before)
49
- key = options[:before]
50
- standalone = false
51
- elsif options.has_key?(:after)
52
- key = options[:after]
53
- standalone = false
54
- end
55
-
56
- if standalone == false
57
- idx = find_chain_index_containing(key)
58
-
59
- @chains[idx].delete(name)
60
- @chains[idx].insert_at(position, key, [ name, Task.from_task_block(name, options, &block) ])
61
-
62
- else
63
- chain = {}
64
- chain[name] = Task.from_task_block(name, options, &block)
65
- @chains << chain
66
- end
67
- end
68
-
69
- # Finds a task by its name
70
- #
71
- # @param name [Symbol] name of the task
72
- # @return [Task] the task if found
73
- def task_by_name(name)
74
- name = name.to_sym if name.is_a?(String)
75
-
76
- cidx = find_chain_index_containing(name)
77
- @chains[cidx][name]
78
- end
79
-
80
- # Finds the chain containing a specifc task
81
- #
82
- # @param name [Symbol] task name
83
- # @param [Integer] chain index
84
- def find_chain_index_containing(name)
85
- @chains.each_with_index do |chain, idx|
86
- if chain.has_key?(name)
87
- return idx
88
- end
89
- end
90
-
91
- raise RuntimeError, "could not find a chain containing task #{name}"
92
- end
93
-
94
- # Invokes a task without dependencies
95
- #
96
- # @param task_name [Symbol] the task name
97
- def invoke_task_oneshot(task_name)
98
- task_name = task_name.to_sym if task_name.is_a?(String)
99
-
100
- cidx = find_chain_index_containing(task_name)
101
-
102
- begin
103
- invoke_task(@chains[cidx][task_name])
104
- rescue Exception => e
105
- AvoDeploy::Deployment.instance.handle_abort(e)
106
- end
107
- end
108
-
109
- # Invokes the task chain, that contains the requested task
110
- #
111
- # @param task_name [Symbol] the task name
112
- def invoke_task_chain_containing(task_name)
113
- task_name = task_name.to_sym if task_name.is_a?(String)
114
-
115
- cidx = find_chain_index_containing(task_name)
116
-
117
- begin
118
- @chains[cidx].each_pair do |name, task|
119
- invoke_task(task)
120
- end
121
- rescue Exception => e
122
- AvoDeploy::Deployment.instance.handle_abort(e)
123
- end
124
- end
125
-
126
- # Executes a task for all defined targets
127
- #
128
- # @param task [Task] the task to start
129
- # @param env [RemoteTaskExecutionEnvironment] the environment
130
- def execute_for_each_target(task, env)
131
- raise ArgumentError, 'task must be a task' unless task.kind_of?(Task)
132
- raise ArgumentError, 'env must be a RemoteTaskExecutionEnvironment' unless env.kind_of?(RemoteTaskExecutionEnvironment)
133
-
134
- avo = AvoDeploy::Deployment.instance
135
-
136
- avo.config.targets.each_pair do |key, target|
137
- avo.log.info "invoking task #{task.name} for target #{target.name}..."
138
-
139
- env.config.merge!(target.config)
140
-
141
- env.establish_connection
142
-
143
- task.invoke(env)
144
- end
145
- end
146
-
147
- # Invokes a task
148
- #
149
- # @param task [Task] the task
150
- def invoke_task(task)
151
- raise ArgumentError, 'task must be a task' unless task.kind_of?(Task)
152
-
153
- avo = AvoDeploy::Deployment.instance
154
- env = nil
155
-
156
- if task.scope == :remote
157
- if @remote_env.nil?
158
- @remote_env = RemoteTaskExecutionEnvironment.new(avo.config.config)
159
- end
160
-
161
- env = @remote_env
162
- elsif task.scope == :local
163
- if @local_env.nil?
164
- @local_env = LocalTaskExecutionEnvironment.new(avo.config.config)
165
- end
166
-
167
- env = @local_env
168
- else
169
- raise RuntimeError, 'scope must either be remote or local'
170
- end
171
-
172
- scm_provider = AvoDeploy::ScmProvider::ScmProvider.new(env, avo.config.get(:scm))
173
- env.scm_provider = scm_provider
174
-
175
- # if remote task -> execute for each target
176
- if task.scope == :remote
177
- execute_for_each_target(task, env)
178
- else
179
- task.invoke(env)
180
- end
181
- end
182
-
183
- end
184
- end
20
+ module Task
21
+ class TaskManager
22
+
23
+ attr_reader :dependencies
24
+ attr_reader :chains
25
+
26
+ # Initializes the task manager
27
+ def initialize
28
+ @chains = []
29
+ @remote_env = nil
30
+ @local_env = nil
31
+ end
32
+
33
+ # Adds a task to the task manager
34
+ #
35
+ # @param name [Symbol] task name
36
+ # @param options [Hash] task options
37
+ # @param block [Block] code of the task
38
+ def add_task(name, options, &block)
39
+ position = :after
40
+ standalone = true
41
+
42
+ if options.has_key?(:before)
43
+ position = :before
44
+ end
45
+
46
+ key = name
47
+
48
+ if options.has_key?(:before)
49
+ key = options[:before]
50
+ standalone = false
51
+ elsif options.has_key?(:after)
52
+ key = options[:after]
53
+ standalone = false
54
+ end
55
+
56
+ if standalone == false
57
+ idx = find_chain_index_containing(key)
58
+
59
+ @chains[idx].delete(name)
60
+ @chains[idx].insert_at(position, key, [name, Task.from_task_block(name, options, &block)])
61
+
62
+ else
63
+ chain = {}
64
+ chain[name] = Task.from_task_block(name, options, &block)
65
+ @chains << chain
66
+ end
67
+ end
68
+
69
+ # Finds a task by its name
70
+ #
71
+ # @param name [Symbol] name of the task
72
+ # @return [Task] the task if found
73
+ def task_by_name(name)
74
+ name = name.to_sym if name.is_a?(String)
75
+
76
+ cidx = find_chain_index_containing(name)
77
+ @chains[cidx][name]
78
+ end
79
+
80
+ # Finds the chain containing a specifc task
81
+ #
82
+ # @param name [Symbol] task name
83
+ # @param [Integer] chain index
84
+ def find_chain_index_containing(name)
85
+ @chains.each_with_index do |chain, idx|
86
+ if chain.has_key?(name)
87
+ return idx
88
+ end
89
+ end
90
+
91
+ raise RuntimeError, "could not find a chain containing task #{name}"
92
+ end
93
+
94
+ # Invokes a task without dependencies
95
+ #
96
+ # @param task_name [Symbol] the task name
97
+ # @param options [Hash] a hash contining additional options
98
+ def invoke_task_oneshot(task_name, options = {})
99
+ task_name = task_name.to_sym if task_name.is_a?(String)
100
+
101
+ cidx = find_chain_index_containing(task_name)
102
+
103
+ begin
104
+ invoke_task(@chains[cidx][task_name], options)
105
+ rescue Exception => e
106
+ AvoDeploy::Deployment.instance.handle_abort(e)
107
+ end
108
+ end
109
+
110
+ # Invokes the task chain, that contains the requested task
111
+ #
112
+ # @param task_name [Symbol] the task name
113
+ # @param options [Hash] a hash contining additional options
114
+ def invoke_task_chain_containing(task_name, options = {})
115
+ task_name = task_name.to_sym if task_name.is_a?(String)
116
+
117
+ cidx = find_chain_index_containing(task_name)
118
+
119
+ begin
120
+ @chains[cidx].each_pair do |name, task|
121
+ invoke_task(task, options)
122
+ end
123
+ rescue Exception => e
124
+ AvoDeploy::Deployment.instance.handle_abort(e)
125
+ end
126
+ end
127
+
128
+ # Executes a task for all defined targets
129
+ #
130
+ # @param task [Task] the task to start
131
+ # @param env [RemoteTaskExecutionEnvironment] the environment
132
+ def execute_for_each_target(task, env)
133
+ raise ArgumentError, 'task must be a task' unless task.kind_of?(Task)
134
+ raise ArgumentError, 'env must be a RemoteTaskExecutionEnvironment' unless env.kind_of?(RemoteTaskExecutionEnvironment)
135
+
136
+ avo = AvoDeploy::Deployment.instance
137
+
138
+ avo.config.targets.each_pair do |key, target|
139
+ # 'only' check
140
+ next if task.remote_only.nil? == false && ((task.remote_only.is_a?(Array) && task.remote_only.include?(target.name) == false) || (task.remote_only.is_a?(Symbol) && task.remote_only != target.name))
141
+
142
+ # 'except' check
143
+ next if task.remote_except.nil? == false && ((task.remote_except.is_a?(Array) && task.remote_except.include?(target.name)) || (task.remote_except.is_a?(Symbol) && task.remote_except == target.name))
144
+
145
+ avo.log.debug "invoking task #{task.name} for target #{target.name}..."
146
+
147
+ env.config.merge!(target.config)
148
+ env.establish_connection
149
+
150
+ task.invoke(env)
151
+ end
152
+ end
153
+
154
+ # Invokes a task
155
+ #
156
+ # @param task [Task] the task
157
+ # @param options [Hash] a hash contining additional options
158
+ def invoke_task(task, options = {})
159
+ raise ArgumentError, 'task must be a task' unless task.kind_of?(Task)
160
+
161
+ avo = AvoDeploy::Deployment.instance
162
+ env = nil
163
+
164
+ if task.scope == :remote
165
+ if @remote_env.nil?
166
+ @remote_env = RemoteTaskExecutionEnvironment.new(avo.config.config)
167
+ end
168
+
169
+ env = @remote_env
170
+ elsif task.scope == :local
171
+ if @local_env.nil?
172
+ @local_env = LocalTaskExecutionEnvironment.new(avo.config.config)
173
+ end
174
+
175
+ env = @local_env
176
+ else
177
+ raise RuntimeError, 'scope must either be remote or local'
178
+ end
179
+
180
+ # @todo this does not belong here
181
+ env.scm = nil
182
+
183
+ if avo.config.get(:scm) == :git
184
+ env.scm = AvoDeploy::ScmProvider::GitScmProvider.new(env)
185
+ elsif avo.config.get(:scm) == :bzr
186
+ env.scm = AvoDeploy::ScmProvider::BzrScmProvider.new(env)
187
+ end
188
+
189
+ if env.scm.nil?
190
+ raise RuntimeError, 'No ScmProvider was instantiated'
191
+ end
192
+
193
+ if options.empty? == false
194
+ env.options = options
195
+ end
196
+
197
+ # if remote task -> execute for each target
198
+ if task.scope == :remote
199
+ execute_for_each_target(task, env)
200
+ else
201
+ task.invoke(env)
202
+ end
203
+ end
204
+
205
+ end
206
+ end
185
207
  end
@@ -17,5 +17,5 @@
17
17
  =end
18
18
 
19
19
  module AvoDeploy
20
- VERSION = "0.4.2"
20
+ VERSION = '0.5'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avodeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Prandzioch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: 0.19.1
97
97
  description: ''
98
98
  email:
99
- - dprandzioch@me.com
99
+ - kontakt@davidprandzioch.de
100
100
  executables:
101
101
  - avo
102
102
  extensions: []
@@ -118,11 +118,13 @@ files:
118
118
  - lib/avodeploy/core_ext/string_colors.rb
119
119
  - lib/avodeploy/deployment.rb
120
120
  - lib/avodeploy/multi_io.rb
121
+ - lib/avodeploy/scm_provider/bzr_scm_provider.rb
121
122
  - lib/avodeploy/scm_provider/git_scm_provider.rb
122
123
  - lib/avodeploy/scm_provider/scm_provider.rb
123
124
  - lib/avodeploy/skel/manifest_template.rb.erb
124
125
  - lib/avodeploy/strategy/base.rb
125
126
  - lib/avodeploy/strategy/local_copy.rb
127
+ - lib/avodeploy/strategy/local_copy_partial.rb
126
128
  - lib/avodeploy/target.rb
127
129
  - lib/avodeploy/task/local_task_execution_environment.rb
128
130
  - lib/avodeploy/task/remote_task_execution_environment.rb
@@ -143,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
145
  requirements:
144
146
  - - '>='
145
147
  - !ruby/object:Gem::Version
146
- version: '0'
148
+ version: 2.0.0
147
149
  required_rubygems_version: !ruby/object:Gem::Requirement
148
150
  requirements:
149
151
  - - '>='
@@ -151,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
153
  version: '0'
152
154
  requirements: []
153
155
  rubyforge_project:
154
- rubygems_version: 2.1.11
156
+ rubygems_version: 2.0.14
155
157
  signing_key:
156
158
  specification_version: 4
157
159
  summary: Avocado is a flexible deployment framework for web applications.