trooper 0.6.0 → 0.6.1
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.
- data/LICENSE +1 -1
- data/README.md +5 -5
- data/Rakefile +1 -0
- data/lib/trooper.rb +4 -0
- data/lib/trooper/action.rb +46 -3
- data/lib/trooper/actions/clone_repository_action.rb +4 -15
- data/lib/trooper/actions/default_action.rb +37 -0
- data/lib/trooper/actions/install_gems_action.rb +4 -15
- data/lib/trooper/actions/migrate_database_action.rb +5 -15
- data/lib/trooper/actions/prepare_prerequisite_action.rb +4 -17
- data/lib/trooper/actions/restart_server_action.rb +4 -15
- data/lib/trooper/actions/rollback_migrate_action.rb +6 -16
- data/lib/trooper/actions/setup_database_action.rb +6 -16
- data/lib/trooper/actions/setup_trooper_action.rb +4 -17
- data/lib/trooper/actions/update_repository_action.rb +4 -15
- data/lib/trooper/strategy.rb +8 -2
- data/lib/trooper/template/troopfile.rb +2 -2
- data/lib/trooper/version.rb +1 -1
- metadata +6 -5
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Trooper [](http://travis-ci.org/madwire/trooper)
|
1
|
+
# Trooper [](http://travis-ci.org/madwire/trooper) [](https://codeclimate.com/github/madwire/trooper)
|
2
2
|
|
3
3
|
Trooper is designed to give you the flexibility to deploy your code to any server in any way you like.
|
4
4
|
You design your deployment strategy to best fit your application and its needs.
|
@@ -6,7 +6,7 @@ Trooper comes with some built in actions that you can use in your own strategies
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
1. Super easy! `gem install trooper` or add it to your Gemfile `gem "trooper", "~> 0.6.
|
9
|
+
1. Super easy! `gem install trooper` or add it to your Gemfile `gem "trooper", "~> 0.6.1"`
|
10
10
|
2. Pop into your terminal and run `=> trooper init`
|
11
11
|
3. Start building you deployment strategy :)
|
12
12
|
|
@@ -38,7 +38,7 @@ A Strategy is collection of actions to be executed in sequence, A Strategy can c
|
|
38
38
|
strategies and have prerequisites.
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
strategy :
|
41
|
+
strategy :my_strategy_name, "A Description of what the strategy does" do
|
42
42
|
actions :clone_repository, :install_gems, :migrate_database
|
43
43
|
end
|
44
44
|
```
|
@@ -69,7 +69,7 @@ env :stage do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
action :restart do
|
72
|
+
action :restart, 'Restarting the server' do
|
73
73
|
run 'touch tmp/restert.txt'
|
74
74
|
run "echo 'Restarted'"
|
75
75
|
end
|
@@ -98,7 +98,7 @@ end
|
|
98
98
|
|
99
99
|
## LICENSE
|
100
100
|
|
101
|
-
Copyright
|
101
|
+
Copyright 2012 Richard Adams
|
102
102
|
|
103
103
|
Permission is hereby granted, free of charge, to any person obtaining
|
104
104
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -37,6 +37,7 @@ require 'rspec/core/rake_task'
|
|
37
37
|
|
38
38
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
39
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
|
+
#spec.rspec_opts = '--order random' need to fix some test to make this randow :( bad tests!
|
40
41
|
end
|
41
42
|
|
42
43
|
desc 'Default: Run all specs.'
|
data/lib/trooper.rb
CHANGED
data/lib/trooper/action.rb
CHANGED
@@ -17,6 +17,7 @@ module Trooper
|
|
17
17
|
# description - A description of action to be used in the cli output.
|
18
18
|
# options - The Hash options used to refine the selection (default: {}):
|
19
19
|
# :local - A boolean of whether this action should be run locally (optional).
|
20
|
+
# :on - A symbol(:first_host, :last_host) to determine if to run on the first or last host (optional).
|
20
21
|
# block - A block containing the tasks to run in this action.
|
21
22
|
#
|
22
23
|
# Examples
|
@@ -26,7 +27,7 @@ module Trooper
|
|
26
27
|
# Returns a new action object.
|
27
28
|
def initialize(name, description, options = {}, &block)
|
28
29
|
@name, @description, @options, @config = name, description, options, {}
|
29
|
-
@commands, @block = [], block
|
30
|
+
@call_count, @commands, @block = 0, [], block
|
30
31
|
end
|
31
32
|
|
32
33
|
# Public: Eval's the block passed on initialize.
|
@@ -40,8 +41,16 @@ module Trooper
|
|
40
41
|
# Returns an array of commands(strings).
|
41
42
|
def call(configuration)
|
42
43
|
@config = configuration
|
43
|
-
|
44
|
-
|
44
|
+
@call_count += 1
|
45
|
+
|
46
|
+
if continue_call?
|
47
|
+
reset_commands!
|
48
|
+
|
49
|
+
build_commands
|
50
|
+
commands
|
51
|
+
else
|
52
|
+
reset_commands!
|
53
|
+
end
|
45
54
|
end
|
46
55
|
alias :execute :call
|
47
56
|
|
@@ -100,12 +109,46 @@ module Trooper
|
|
100
109
|
commands << command if command != ''
|
101
110
|
end
|
102
111
|
|
112
|
+
# Public: Resets Action commands to blank.
|
113
|
+
#
|
114
|
+
# Examples
|
115
|
+
#
|
116
|
+
# @action.reset_commands! # => []
|
117
|
+
#
|
118
|
+
# Returns a blank array.
|
119
|
+
def reset_commands!
|
120
|
+
self.commands = []
|
121
|
+
end
|
122
|
+
|
103
123
|
def method_missing(method_sym, *arguments, &block) # :nodoc:
|
104
124
|
config[method_sym] || super
|
105
125
|
end
|
106
126
|
|
107
127
|
private
|
108
128
|
|
129
|
+
# builds commands array from block passed on init
|
130
|
+
def build_commands
|
131
|
+
eval_block(&block)
|
132
|
+
end
|
133
|
+
|
134
|
+
# determines whether to continue calling, to build the commands array
|
135
|
+
def continue_call?
|
136
|
+
if options && options[:on]
|
137
|
+
|
138
|
+
case options[:on]
|
139
|
+
when :first_host
|
140
|
+
@call_count == 1
|
141
|
+
when :last_host
|
142
|
+
config[:hosts] && @call_count == config[:hosts].count
|
143
|
+
else
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
147
|
+
else
|
148
|
+
true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
109
152
|
def eval_block(&block) # :nodoc:
|
110
153
|
if block_given?
|
111
154
|
if block.arity == 1
|
@@ -1,22 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class CloneRepositoryAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :clone_repository
|
10
|
-
@description = "Cloning repository as 'application'"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
6
|
+
class CloneRepositoryAction < DefaultAction
|
7
|
+
name :clone_repository
|
8
|
+
description "Cloning repository as 'application'"
|
20
9
|
|
21
10
|
private
|
22
11
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'trooper/action'
|
2
|
+
|
3
|
+
module Trooper
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
class DefaultAction < Action
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :config
|
10
|
+
|
11
|
+
%w(name description options).each do |method|
|
12
|
+
define_method(method) do |value|
|
13
|
+
self.config = {} unless self.config
|
14
|
+
self.config[method.to_sym] = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(config = {})
|
20
|
+
@name = self.class.config[:name]
|
21
|
+
@description = self.class.config[:description]
|
22
|
+
@options = self.class.config[:options] || {}
|
23
|
+
@config = config
|
24
|
+
@call_count = 0
|
25
|
+
@commands = []
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def build_commands
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -1,22 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class InstallGemsAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :install_gems
|
10
|
-
@description = "Installing Gems with Bundler"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
6
|
+
class InstallGemsAction < DefaultAction
|
7
|
+
name :install_gems
|
8
|
+
description "Installing Gems with Bundler"
|
20
9
|
|
21
10
|
private
|
22
11
|
|
@@ -1,22 +1,12 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class MigrateDatabaseAction <
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@description = "Migrating database"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
6
|
+
class MigrateDatabaseAction < DefaultAction
|
7
|
+
name :migrate_database
|
8
|
+
description "Migrating database"
|
9
|
+
options :on => :first_host
|
20
10
|
|
21
11
|
private
|
22
12
|
|
@@ -1,24 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class PreparePrerequisiteAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :prepare_prerequisite
|
10
|
-
@description = "Preparing Prerequisites"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
@commands = []
|
18
|
-
|
19
|
-
build_commands
|
20
|
-
commands
|
21
|
-
end
|
6
|
+
class PreparePrerequisiteAction < DefaultAction
|
7
|
+
name :prepare_prerequisite
|
8
|
+
description "Preparing Prerequisites"
|
22
9
|
|
23
10
|
private
|
24
11
|
|
@@ -1,22 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class RestartServerAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :restart_server
|
10
|
-
@description = "Restart server"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
6
|
+
class RestartServerAction < DefaultAction
|
7
|
+
name :restart_server
|
8
|
+
description "Restart server"
|
20
9
|
|
21
10
|
private
|
22
11
|
|
@@ -1,23 +1,13 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class RollbackMigrateAction <
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
20
|
-
|
6
|
+
class RollbackMigrateAction < DefaultAction
|
7
|
+
name :rollback_migrate
|
8
|
+
description "Rollback database"
|
9
|
+
options :on => :first_host
|
10
|
+
|
21
11
|
private
|
22
12
|
|
23
13
|
def build_commands
|
@@ -1,23 +1,13 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class SetupDatabaseAction <
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
20
|
-
|
6
|
+
class SetupDatabaseAction < DefaultAction
|
7
|
+
name :setup_database
|
8
|
+
description "Setting up database"
|
9
|
+
options :on => :first_host
|
10
|
+
|
21
11
|
private
|
22
12
|
|
23
13
|
def build_commands
|
@@ -1,24 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class SetupTrooperAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :setup_trooper
|
10
|
-
@description = "Setup Trooper"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
@commands = []
|
18
|
-
|
19
|
-
build_commands
|
20
|
-
commands
|
21
|
-
end
|
6
|
+
class SetupTrooperAction < DefaultAction
|
7
|
+
name :setup_trooper
|
8
|
+
description "Setup Trooper"
|
22
9
|
|
23
10
|
private
|
24
11
|
|
@@ -1,22 +1,11 @@
|
|
1
|
-
require 'trooper/
|
1
|
+
require 'trooper/actions/default_action'
|
2
2
|
|
3
3
|
module Trooper
|
4
4
|
module Actions
|
5
5
|
|
6
|
-
class UpdateRepositoryAction <
|
7
|
-
|
8
|
-
|
9
|
-
@name = :update_repository
|
10
|
-
@description = "Updating repository"
|
11
|
-
@config = config
|
12
|
-
@commands = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(configuration)
|
16
|
-
@config = configuration
|
17
|
-
build_commands
|
18
|
-
commands
|
19
|
-
end
|
6
|
+
class UpdateRepositoryAction < DefaultAction
|
7
|
+
name :update_repository
|
8
|
+
description "Updating repository"
|
20
9
|
|
21
10
|
private
|
22
11
|
|
data/lib/trooper/strategy.rb
CHANGED
@@ -73,6 +73,9 @@ module Trooper
|
|
73
73
|
if Arsenal.strategies[strategy_name]
|
74
74
|
Arsenal.strategies[strategy_name].list(config).each do |action|
|
75
75
|
# strategy_name, type, name
|
76
|
+
if action[1] == :local_action
|
77
|
+
raise InvalidActionError, 'Cant use prerequisite strategies that have local actions'
|
78
|
+
end
|
76
79
|
@prereq_run_list << [action[0], :prerequisite, action[2]]
|
77
80
|
end
|
78
81
|
end
|
@@ -102,6 +105,9 @@ module Trooper
|
|
102
105
|
#
|
103
106
|
# name - The name of the action.
|
104
107
|
# description - A description of action to be used in the cli output.
|
108
|
+
# options - The Hash options used to refine the selection (default: {}):
|
109
|
+
# :local - A boolean of whether this action should be run locally (optional).
|
110
|
+
# :on - A symbol(:first_host, :last_host) to determine if to run on the first or last host (optional).
|
105
111
|
# block - A block containing the tasks to run in this action.
|
106
112
|
#
|
107
113
|
# Examples
|
@@ -109,10 +115,10 @@ module Trooper
|
|
109
115
|
# @strategy.action(:my_action, 'Does great things') { run 'touch file' }
|
110
116
|
#
|
111
117
|
# Returns an Action object.
|
112
|
-
def action(name, description = "No Description", &block)
|
118
|
+
def action(name, description = "No Description", options = {}, &block)
|
113
119
|
action_name = "#{self.name}_#{name}".to_sym
|
114
120
|
|
115
|
-
action = Trooper::Action.new action_name, description, &block
|
121
|
+
action = Trooper::Action.new action_name, description, options, &block
|
116
122
|
Arsenal.actions.add action
|
117
123
|
actions action_name
|
118
124
|
|
@@ -47,7 +47,7 @@ end
|
|
47
47
|
# end
|
48
48
|
# end
|
49
49
|
|
50
|
-
# action :my_action do
|
50
|
+
# action :my_action, 'Does Something', :on => :first_host do
|
51
51
|
# #some action
|
52
52
|
# end
|
53
53
|
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
# prerequisites :bootstrap
|
56
56
|
# actions :update_repository, :install_gems # use some built in actions
|
57
57
|
# #define my own action
|
58
|
-
# action :my_other_action, 'Only avaliable in this strategy scope' do
|
58
|
+
# action :my_other_action, 'Only avaliable in this strategy scope', :local => true do
|
59
59
|
# rake 'sometask'
|
60
60
|
# end
|
61
61
|
# call :restart
|
data/lib/trooper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trooper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- bin/trooper
|
167
167
|
- lib/trooper/action.rb
|
168
168
|
- lib/trooper/actions/clone_repository_action.rb
|
169
|
+
- lib/trooper/actions/default_action.rb
|
169
170
|
- lib/trooper/actions/install_gems_action.rb
|
170
171
|
- lib/trooper/actions/migrate_database_action.rb
|
171
172
|
- lib/trooper/actions/prepare_prerequisite_action.rb
|
@@ -209,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
210
|
version: '0'
|
210
211
|
segments:
|
211
212
|
- 0
|
212
|
-
hash:
|
213
|
+
hash: 3446711087193426780
|
213
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
215
|
none: false
|
215
216
|
requirements:
|
@@ -218,10 +219,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
219
|
version: '0'
|
219
220
|
segments:
|
220
221
|
- 0
|
221
|
-
hash:
|
222
|
+
hash: 3446711087193426780
|
222
223
|
requirements: []
|
223
224
|
rubyforge_project:
|
224
|
-
rubygems_version: 1.8.
|
225
|
+
rubygems_version: 1.8.24
|
225
226
|
signing_key:
|
226
227
|
specification_version: 3
|
227
228
|
summary: Deploy like a 'Trooper'
|