blazing 0.2.7 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +17 -0
- data/Guardfile +2 -4
- data/README.md +131 -44
- data/bin/blazing +2 -34
- data/blazing.gemspec +4 -2
- data/lib/blazing.rb +9 -1
- data/lib/blazing/cli.rb +65 -0
- data/lib/blazing/config.rb +13 -9
- data/lib/blazing/recipe.rb +4 -15
- data/lib/blazing/runner.rb +56 -36
- data/lib/blazing/shell.rb +1 -1
- data/lib/blazing/target.rb +41 -4
- data/lib/blazing/templates/config.erb +43 -17
- data/lib/blazing/templates/hook.erb +3 -3
- data/lib/blazing/version.rb +5 -1
- data/spec/blazing/config_spec.rb +4 -33
- data/spec/blazing/integration/init_spec.rb +1 -1
- data/spec/blazing/integration/{recipes_list_spec.rb → list_spec.rb} +2 -4
- data/spec/blazing/integration/{recipes_run_spec.rb → recipes_spec.rb} +8 -6
- data/spec/blazing/integration/setup_spec.rb +41 -0
- data/spec/blazing/integration/update_spec.rb +44 -49
- data/spec/blazing/recipe_spec.rb +2 -21
- data/spec/blazing/target_spec.rb +24 -0
- data/spec/spec_helper.rb +29 -10
- metadata +57 -32
- data/spec/blazing/integration/setup_remote_spec.rb +0 -32
data/lib/blazing/recipe.rb
CHANGED
@@ -21,6 +21,7 @@ class Blazing::Recipe
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def list
|
24
|
+
load_recipes!
|
24
25
|
descendants = []
|
25
26
|
ObjectSpace.each_object(Class) do |k|
|
26
27
|
descendants.unshift k if k < self
|
@@ -28,21 +29,9 @@ class Blazing::Recipe
|
|
28
29
|
descendants
|
29
30
|
end
|
30
31
|
|
31
|
-
def load_recipes
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def parse_gemfile(gemfile = 'Gemfile')
|
36
|
-
open(gemfile).grep(/blazing-/).map { |l| l.match(/blazing-(\w+)/)[0] }
|
37
|
-
end
|
38
|
-
|
39
|
-
def load_recipe_gems(gems)
|
40
|
-
gems.each do |gem|
|
41
|
-
gem_lib_path = $:.find { |p| p.include? gem }
|
42
|
-
recipes_path = File.join(gem_lib_path, gem, 'recipes')
|
43
|
-
recipes = Dir.entries(recipes_path).delete_if { |r| r == '.' || r == '..' }
|
44
|
-
recipes.each { |recipe| require File.join(gem, 'recipes', recipe) }
|
45
|
-
end
|
32
|
+
def load_recipes!
|
33
|
+
gems = $:.select{|p| p.match /blazing-\w+(|-\d\.\d\.\d)\/lib/}.map { |r| r.scan(/blazing-\w+/)[0] }
|
34
|
+
gems.each { |gem| require gem }
|
46
35
|
end
|
47
36
|
|
48
37
|
end
|
data/lib/blazing/runner.rb
CHANGED
@@ -1,59 +1,79 @@
|
|
1
1
|
require 'erb'
|
2
|
-
require '
|
2
|
+
require 'blazing/config'
|
3
3
|
|
4
4
|
class Blazing::Runner
|
5
5
|
|
6
6
|
include Blazing::Logger
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
10
|
-
@config = config
|
11
|
-
@target = @config.targets.find { |t| t.name.to_s == target } || @config.default_target
|
12
|
-
end
|
8
|
+
def initialize(target_name, options)
|
9
|
+
prepare_config(target_name, options)
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
#
|
13
|
+
# Parse config and set up options
|
14
|
+
#
|
15
|
+
def prepare_config(target_name, options = {})
|
16
|
+
@config ||= Blazing::Config.parse(options[:file])
|
17
|
+
@targets = []
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
if target_name == 'all'
|
20
|
+
@targets = @config.targets
|
21
|
+
else
|
22
|
+
@targets << (@config.targets.find { |t| t.name.to_s == target_name.to_s } || @config.default_target)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
configuration_file = ERB.new(File.read("#{Blazing::TEMPLATE_ROOT}/config.erb")).result
|
25
|
+
@targets.compact!
|
27
26
|
|
28
|
-
|
29
|
-
f.puts configuration_file
|
30
|
-
end
|
27
|
+
error 'no target given or found' if @targets.empty?
|
31
28
|
end
|
32
29
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
def setup
|
31
|
+
return if @targets.empty?
|
32
|
+
|
33
|
+
@targets.each do |target|
|
34
|
+
target.setup
|
38
35
|
end
|
36
|
+
update
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
@
|
43
|
-
update_command
|
44
|
-
end
|
39
|
+
def update
|
40
|
+
return if @targets.empty?
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
@targets.each do |t|
|
43
|
+
t.setup_git_remote
|
44
|
+
t.apply_hook
|
45
|
+
end
|
49
46
|
end
|
50
47
|
|
51
|
-
def
|
52
|
-
@config.recipes.each { |recipe| recipe.run
|
48
|
+
def recipes
|
49
|
+
@config.recipes.each { |recipe| recipe.run }
|
53
50
|
end
|
54
51
|
|
55
|
-
|
56
|
-
Blazing::Recipe.list.each { |r| puts r.to_s.demodulize.underscore }
|
57
|
-
end
|
52
|
+
class << self
|
58
53
|
|
54
|
+
include Blazing::Logger
|
55
|
+
|
56
|
+
#
|
57
|
+
# Bootstrap blazing by creating config file
|
58
|
+
#
|
59
|
+
def init
|
60
|
+
info "Creating an example config file in #{Blazing::DEFAULT_CONFIG_LOCATION}"
|
61
|
+
info "Customize it to your needs"
|
62
|
+
|
63
|
+
Dir.mkdir 'config' unless File.exists? 'config'
|
64
|
+
configuration_file = ERB.new(File.read("#{Blazing::TEMPLATE_ROOT}/config.erb")).result
|
65
|
+
|
66
|
+
File.open(Blazing::DEFAULT_CONFIG_LOCATION,"wb") do |f|
|
67
|
+
f.puts configuration_file
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# List available blazing recipes
|
73
|
+
#
|
74
|
+
def list
|
75
|
+
Blazing::Recipe.list.each { |r| puts r.to_s.demodulize.underscore }
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
59
79
|
end
|
data/lib/blazing/shell.rb
CHANGED
data/lib/blazing/target.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'blazing/shell'
|
2
|
+
require 'grit'
|
2
3
|
|
3
4
|
class Blazing::Target
|
4
5
|
|
@@ -12,11 +13,18 @@ class Blazing::Target
|
|
12
13
|
@config = config
|
13
14
|
@options = options
|
14
15
|
@shell = Blazing::Shell.new
|
16
|
+
@target = self
|
15
17
|
end
|
16
18
|
|
17
19
|
def setup
|
18
20
|
info "Setting up repository for #{name} in #{location}"
|
19
|
-
|
21
|
+
|
22
|
+
# TODO: Handle case where user is empty
|
23
|
+
if host
|
24
|
+
@shell.run "ssh #{user}@#{host} '#{init_repository} && #{setup_repository}'"
|
25
|
+
else
|
26
|
+
@shell.run "#{init_repository} && #{setup_repository}"
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
def apply_hook
|
@@ -29,11 +37,25 @@ class Blazing::Target
|
|
29
37
|
|
30
38
|
debug "Copying hook for #{name} to #{location}"
|
31
39
|
copy_hook
|
32
|
-
|
40
|
+
if host
|
41
|
+
@shell.run "ssh #{user}@#{host} #{make_hook_executable}"
|
42
|
+
else
|
43
|
+
@shell.run "#{make_hook_executable}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_git_remote
|
48
|
+
repository = Grit::Repo.new(Dir.pwd)
|
49
|
+
info "Adding new remote #{name} pointing to #{location}"
|
50
|
+
repository.config["remote.#{name}.url"] = location
|
33
51
|
end
|
34
52
|
|
35
53
|
def path
|
36
|
-
|
54
|
+
if host
|
55
|
+
@location.match(/:(.*)$/)[1]
|
56
|
+
else
|
57
|
+
@location
|
58
|
+
end
|
37
59
|
end
|
38
60
|
|
39
61
|
def host
|
@@ -57,10 +79,16 @@ class Blazing::Target
|
|
57
79
|
|
58
80
|
def copy_hook
|
59
81
|
debug "Making hook executable"
|
60
|
-
|
82
|
+
# TODO: handle missing user?
|
83
|
+
if host
|
84
|
+
@shell.run "scp #{Blazing::TMP_HOOK} #{user}@#{host}:#{path}/.git/hooks/post-receive"
|
85
|
+
else
|
86
|
+
@shell.run "cp #{Blazing::TMP_HOOK} #{path}/.git/hooks/post-receive"
|
87
|
+
end
|
61
88
|
end
|
62
89
|
|
63
90
|
def make_hook_executable
|
91
|
+
debug "Making hook executable"
|
64
92
|
"chmod +x #{path}/.git/hooks/post-receive"
|
65
93
|
end
|
66
94
|
|
@@ -68,4 +96,13 @@ class Blazing::Target
|
|
68
96
|
"cd #{path} && git config receive.denyCurrentBranch ignore"
|
69
97
|
end
|
70
98
|
|
99
|
+
def rake_command
|
100
|
+
rake_config = @config.instance_variable_get("@rake") || {}
|
101
|
+
rails_env = "RAILS_ENV=#{@options[:rails_env]}" if @options[:rails_env]
|
102
|
+
|
103
|
+
if rake_config[:task]
|
104
|
+
"#{rake_config[:env]} #{rails_env} bundle exec rake #{rake_config[:task]}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
71
108
|
end
|
@@ -1,35 +1,61 @@
|
|
1
1
|
#
|
2
2
|
# Blazing Configuration File
|
3
3
|
#
|
4
|
-
|
4
|
+
# Sample target definition:
|
5
|
+
#
|
6
|
+
# target <target_name>, <target_location>, [options]
|
5
7
|
#
|
6
|
-
#
|
8
|
+
# The options provided in the target definition will override any
|
9
|
+
# options provided in the recipe call.
|
7
10
|
#
|
8
|
-
#
|
11
|
+
# Options recognized by blazing core:
|
12
|
+
# rails_env: used when calling the rake task after deployment
|
13
|
+
|
14
|
+
target :staging, 'screenconcept@ruby:/var/www/vischer.ruby.screenconcept.ch',
|
15
|
+
:recipe_specific_option => 'foo', :rails_env => 'production'
|
9
16
|
|
17
|
+
|
18
|
+
# Sample rvm setup:
|
10
19
|
#
|
11
|
-
#
|
20
|
+
# rvm <rvm-string>
|
12
21
|
#
|
13
|
-
#
|
14
|
-
#
|
22
|
+
# Setting the rvm string will make sure that the correct rvm ruby and
|
23
|
+
# gemset is used before the post-receive hook does anything at all.
|
24
|
+
# Use :rvmrc as rvm string if you want blazing to use the rvm
|
25
|
+
# environment specified in your project's .rvmrc file.
|
26
|
+
|
27
|
+
rvm 'ruby-1.9.3@some-gemset'
|
28
|
+
|
15
29
|
|
30
|
+
# Sample config for custom rvm location:
|
16
31
|
#
|
17
|
-
#
|
32
|
+
# rvm_scripts <path_to_rvm_scripts>
|
18
33
|
#
|
19
|
-
#
|
20
|
-
# rvm
|
34
|
+
# If you have installed rvm to a custom location, use this method to
|
35
|
+
# specify where the rvm scripts are located.
|
36
|
+
|
37
|
+
rvm_scripts '/opt/rvm/scripts/rvm'
|
21
38
|
|
22
|
-
# Or use the rvmrc
|
23
|
-
# rvm :rvmrc
|
24
|
-
#
|
25
39
|
|
40
|
+
# Sample recipe setup:
|
26
41
|
#
|
27
|
-
#
|
28
|
-
# Recipes are run in the order they are specified
|
42
|
+
# recipe <recipe_name>, [options]
|
29
43
|
#
|
30
|
-
# recipe
|
44
|
+
# The given recipe will be called with the provided options. Refer to each
|
45
|
+
# recipe's documentation for available options. Options provided here
|
46
|
+
# may be overridden by target specific options.
|
47
|
+
# Recipes will be executed in the order they are defined!yy
|
48
|
+
|
49
|
+
recipe :precompile_assets, :recipe_specific_option => 'bar'
|
31
50
|
|
51
|
+
|
52
|
+
# Sample rake file config:
|
32
53
|
#
|
33
|
-
#
|
54
|
+
# rake <task>, [environment variables]
|
34
55
|
#
|
35
|
-
# rake
|
56
|
+
# The provided rake task will be run after all recipes have run.
|
57
|
+
# Note: you can only call a single rake task. If you need to run several
|
58
|
+
# tasks just create one task that wrapps all the others.
|
59
|
+
|
60
|
+
rake :post_deploy, 'RAILS_ENV=production'
|
61
|
+
|
@@ -66,7 +66,7 @@ bundle --deployment --quiet --without development test
|
|
66
66
|
bundle exec blazing recipes:run <%= name.to_s %>
|
67
67
|
<% end %>
|
68
68
|
|
69
|
-
<% if @
|
70
|
-
echo "------> [blazing] running
|
71
|
-
|
69
|
+
<% if @target.rake_command %>
|
70
|
+
echo "------> [blazing] running <%= @target.rake_command %>"
|
71
|
+
<%= @target.rake_command %>
|
72
72
|
<% end %>
|
data/lib/blazing/version.rb
CHANGED
data/spec/blazing/config_spec.rb
CHANGED
@@ -31,23 +31,6 @@ describe Blazing::Config do
|
|
31
31
|
config.default_target.name.should be :sometarget
|
32
32
|
end
|
33
33
|
|
34
|
-
context 'when more than 1 target defined in config' do
|
35
|
-
|
36
|
-
it 'raises an error when none is default' do
|
37
|
-
config = Blazing::Config.new
|
38
|
-
config.target :sometarget, 'somewhere'
|
39
|
-
config.target :someothertarget, 'somewhere'
|
40
|
-
lambda { config.default_target }.should raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns the target object with :default => true option if more than 1 target present' do
|
44
|
-
config = Blazing::Config.new
|
45
|
-
config.target :sometarget, 'somewhere', :default => true
|
46
|
-
config.target :someothertarget, 'somewhere'
|
47
|
-
config.default_target.name.should be :sometarget
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
34
|
end
|
52
35
|
|
53
36
|
describe 'DSL' do
|
@@ -72,18 +55,6 @@ describe Blazing::Config do
|
|
72
55
|
end
|
73
56
|
end
|
74
57
|
|
75
|
-
describe 'repository' do
|
76
|
-
it 'assigns the repository if a value is given' do
|
77
|
-
@config.repository('somewhere')
|
78
|
-
@config.instance_variable_get("@repository").should == 'somewhere'
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'returns the repository string if no value is given' do
|
82
|
-
@config.repository('somewhere')
|
83
|
-
@config.repository.should == 'somewhere'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
58
|
describe 'recipe' do
|
88
59
|
|
89
60
|
before :each do
|
@@ -117,12 +88,12 @@ describe Blazing::Config do
|
|
117
88
|
|
118
89
|
it 'takes the name of the rake task as argument' do
|
119
90
|
@config.rake :post_deploy
|
120
|
-
@config.instance_variable_get('@rake').should
|
91
|
+
@config.instance_variable_get('@rake').should == { :task => :post_deploy }
|
121
92
|
end
|
122
93
|
|
123
|
-
it '
|
124
|
-
@config.rake :post_deploy
|
125
|
-
@config.rake.should
|
94
|
+
it 'accepts environment variables to pass along to rake' do
|
95
|
+
@config.rake :post_deploy, 'RAILS_ENV=production'
|
96
|
+
@config.instance_variable_get('@rake').should == { :task => :post_deploy, :env => 'RAILS_ENV=production' }
|
126
97
|
end
|
127
98
|
|
128
99
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'blazing/config'
|
3
|
-
require 'blazing/runner'
|
4
2
|
|
5
|
-
describe 'blazing
|
3
|
+
describe 'blazing list' do
|
6
4
|
|
7
5
|
before :each do
|
8
6
|
setup_sandbox
|
@@ -15,7 +13,7 @@ describe 'blazing init' do
|
|
15
13
|
it 'prints a list of the available recipes' do
|
16
14
|
class Blazing::Recipe::Dummy < Blazing::Recipe
|
17
15
|
end
|
18
|
-
capture(:stdout) { Blazing::Runner.
|
16
|
+
capture(:stdout) { Blazing::Runner.list }.should == "dummy\n"
|
19
17
|
end
|
20
18
|
|
21
19
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'blazing/config'
|
3
|
-
require 'blazing/runner'
|
4
2
|
|
5
|
-
describe 'blazing
|
3
|
+
describe 'blazing recipes' do
|
6
4
|
|
7
5
|
before :each do
|
8
6
|
setup_sandbox
|
9
7
|
class Blazing::Recipe::Dummy < Blazing::Recipe
|
8
|
+
def run
|
9
|
+
puts 'dummy recipe was run'
|
10
|
+
end
|
10
11
|
end
|
11
12
|
@dummy_recipe = Blazing::Recipe::Dummy.new
|
12
13
|
@config = Blazing::Config.new
|
13
14
|
@config.target :production, @production_url
|
14
15
|
@config.instance_variable_set('@recipes', [@dummy_recipe])
|
15
|
-
@
|
16
|
+
@cli = Blazing::CLI.new
|
17
|
+
Blazing::Config.stub(:parse).and_return @config
|
16
18
|
end
|
17
19
|
|
18
20
|
after :each do
|
@@ -20,8 +22,8 @@ describe 'blazing init' do
|
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'runs the configured recipes' do
|
23
|
-
@
|
24
|
-
|
25
|
+
output = capture(:stdout) { @cli.recipes(:production) }
|
26
|
+
output.should == "dummy recipe was run\n"
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|