avodeploy 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +14 -0
  3. data/README.md +8 -5
  4. data/avodeploy.gemspec +3 -4
  5. data/bin/avo +14 -12
  6. data/lib/avodeploy.rb +29 -0
  7. data/lib/{avocado → avodeploy}/bootstrap.rb +24 -30
  8. data/lib/{avocado → avodeploy}/command_execution_result.rb +1 -1
  9. data/lib/{avocado → avodeploy}/config.rb +8 -4
  10. data/lib/{avocado → avodeploy}/core_ext/hash_insert_at.rb +0 -0
  11. data/lib/{avocado → avodeploy}/core_ext/string_colors.rb +0 -0
  12. data/lib/{avocado → avodeploy}/deployment.rb +3 -3
  13. data/lib/{avocado → avodeploy}/multi_io.rb +1 -1
  14. data/lib/avodeploy/scm_provider/git_scm_provider.rb +73 -0
  15. data/lib/avodeploy/scm_provider/scm_provider.rb +70 -0
  16. data/lib/{avocado → avodeploy}/skel/manifest_template.rb.erb +1 -1
  17. data/lib/{avocado → avodeploy}/strategy/base.rb +1 -1
  18. data/lib/avodeploy/strategy/local_copy.rb +101 -0
  19. data/lib/{avocado → avodeploy}/target.rb +3 -1
  20. data/lib/avodeploy/task/local_task_execution_environment.rb +127 -0
  21. data/lib/avodeploy/task/remote_task_execution_environment.rb +114 -0
  22. data/lib/avodeploy/task/task.rb +76 -0
  23. data/lib/{avocado → avodeploy}/task/task_dependency.rb +8 -6
  24. data/lib/avodeploy/task/task_execution_environment.rb +88 -0
  25. data/lib/avodeploy/task/task_manager.rb +185 -0
  26. data/lib/{avocado → avodeploy}/version.rb +2 -2
  27. metadata +27 -40
  28. data/lib/avocado/Gemfile +0 -9
  29. data/lib/avocado/scm_provider/git_scm_provider.rb +0 -71
  30. data/lib/avocado/scm_provider/scm_provider.rb +0 -68
  31. data/lib/avocado/strategy/local_copy.rb +0 -99
  32. data/lib/avocado/task/local_task_execution_environment.rb +0 -127
  33. data/lib/avocado/task/remote_task_execution_environment.rb +0 -112
  34. data/lib/avocado/task/task.rb +0 -84
  35. data/lib/avocado/task/task_execution_environment.rb +0 -86
  36. data/lib/avocado/task/task_manager.rb +0 -183
@@ -0,0 +1,76 @@
1
+ =begin
2
+ AVOCADO
3
+ The flexible and easy to use deployment framework for web applications
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License Version 2
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+ =end
18
+
19
+ module AvoDeploy
20
+ module Task
21
+ class Task
22
+
23
+ attr_accessor :name
24
+ attr_accessor :scope
25
+ attr_accessor :visibility
26
+ attr_accessor :block
27
+ attr_accessor :desc
28
+
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
37
+
38
+ instance.name = name
39
+ instance.block = block
40
+
41
+ instance.scope = :local
42
+
43
+ if options.has_key?(:scope) && options[:scope] == :remote
44
+ instance.scope = :remote
45
+ end
46
+
47
+ instance.visibility = :public
48
+
49
+ if options.has_key?(:visibility) && options[:visibility] == :private
50
+ instance.visibility = :private
51
+ end
52
+
53
+ if options.has_key?(:desc)
54
+ instance.desc = options[:desc]
55
+ end
56
+
57
+ instance
58
+ end
59
+
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)
66
+
67
+ avo = AvoDeploy::Deployment.instance
68
+
69
+ avo.log.debug "Running task #{@name}"
70
+
71
+ env.instance_eval(&@block)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -16,10 +16,12 @@
16
16
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
  =end
18
18
 
19
- module Avocado
20
- class TaskDependency
21
- attr_accessor :task_name
22
- attr_accessor :dependent_task_name
23
- attr_accessor :type
24
- end
19
+ module AvoDeploy
20
+ module Task
21
+ class TaskDependency
22
+ attr_accessor :task_name
23
+ attr_accessor :dependent_task_name
24
+ attr_accessor :type
25
+ end
26
+ end
25
27
  end
@@ -0,0 +1,88 @@
1
+ =begin
2
+ AVOCADO
3
+ The flexible and easy to use deployment framework for web applications
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License Version 2
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+ =end
18
+
19
+ module AvoDeploy
20
+ module Task
21
+ class TaskExecutionEnvironment
22
+
23
+ # Initialized the environment
24
+ #
25
+ # @param config [Hash] deployment configuration
26
+ def initialize(config)
27
+ # @todo check
28
+ @config = config
29
+ end
30
+
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
37
+
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}"
47
+
48
+ raise RuntimeError, msg
49
+ end
50
+ end
51
+ rescue Exception => e
52
+ handle_abort e
53
+ end
54
+ end
55
+
56
+ # Returns the logger instance
57
+ #
58
+ # @return [Logger] log instance
59
+ def log
60
+ AvoDeploy::Deployment.instance.log
61
+ end
62
+
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
70
+
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
78
+
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
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,185 @@
1
+ =begin
2
+ AVOCADO
3
+ The flexible and easy to use deployment framework for web applications
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License Version 2
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+ =end
18
+
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
185
+ end
@@ -16,6 +16,6 @@
16
16
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
  =end
18
18
 
19
- module Avocado
20
- VERSION = "0.4"
19
+ module AvoDeploy
20
+ VERSION = "0.4.1"
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'
4
+ version: 0.4.1
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-12 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,33 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: awesome_print
42
+ name: terminal-table
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 1.2.0
47
+ version: 1.4.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.2.0
55
- - !ruby/object:Gem::Dependency
56
- name: terminal-table
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: 1.4.5
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: net-ssh
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -116,33 +102,34 @@ executables:
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
105
+ - CHANGELOG
119
106
  - Gemfile
120
107
  - LICENSE
121
108
  - README.md
122
109
  - Rakefile
123
110
  - avodeploy.gemspec
124
111
  - bin/avo
125
- - lib/avocado/Gemfile
126
- - lib/avocado/bootstrap.rb
127
- - lib/avocado/command_execution_result.rb
128
- - lib/avocado/config.rb
129
- - lib/avocado/core_ext/hash_insert_at.rb
130
- - lib/avocado/core_ext/string_colors.rb
131
- - lib/avocado/deployment.rb
132
- - lib/avocado/multi_io.rb
133
- - lib/avocado/scm_provider/git_scm_provider.rb
134
- - lib/avocado/scm_provider/scm_provider.rb
135
- - lib/avocado/skel/manifest_template.rb.erb
136
- - lib/avocado/strategy/base.rb
137
- - lib/avocado/strategy/local_copy.rb
138
- - lib/avocado/target.rb
139
- - lib/avocado/task/local_task_execution_environment.rb
140
- - lib/avocado/task/remote_task_execution_environment.rb
141
- - lib/avocado/task/task.rb
142
- - lib/avocado/task/task_dependency.rb
143
- - lib/avocado/task/task_execution_environment.rb
144
- - lib/avocado/task/task_manager.rb
145
- - lib/avocado/version.rb
112
+ - lib/avodeploy.rb
113
+ - lib/avodeploy/bootstrap.rb
114
+ - lib/avodeploy/command_execution_result.rb
115
+ - lib/avodeploy/config.rb
116
+ - lib/avodeploy/core_ext/hash_insert_at.rb
117
+ - lib/avodeploy/core_ext/string_colors.rb
118
+ - lib/avodeploy/deployment.rb
119
+ - lib/avodeploy/multi_io.rb
120
+ - lib/avodeploy/scm_provider/git_scm_provider.rb
121
+ - lib/avodeploy/scm_provider/scm_provider.rb
122
+ - lib/avodeploy/skel/manifest_template.rb.erb
123
+ - lib/avodeploy/strategy/base.rb
124
+ - lib/avodeploy/strategy/local_copy.rb
125
+ - lib/avodeploy/target.rb
126
+ - lib/avodeploy/task/local_task_execution_environment.rb
127
+ - lib/avodeploy/task/remote_task_execution_environment.rb
128
+ - lib/avodeploy/task/task.rb
129
+ - lib/avodeploy/task/task_dependency.rb
130
+ - lib/avodeploy/task/task_execution_environment.rb
131
+ - lib/avodeploy/task/task_manager.rb
132
+ - lib/avodeploy/version.rb
146
133
  homepage: http://dprandzioch.github.io/avocado/
147
134
  licenses:
148
135
  - GPLv2