blazing 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +26 -20
- data/CHANGELOG.md +28 -8
- data/Gemfile +0 -1
- data/Guardfile +10 -2
- data/README.md +3 -3
- data/blazing.gemspec +8 -5
- data/lib/blazing/cli.rb +6 -7
- data/lib/blazing/commands.rb +72 -0
- data/lib/blazing/config.rb +5 -0
- data/lib/blazing/hook.rb +85 -0
- data/lib/blazing/logger.rb +1 -0
- data/lib/blazing/recipe.rb +5 -0
- data/lib/blazing/repository.rb +53 -0
- data/lib/blazing/target.rb +35 -91
- data/lib/blazing/templates/config.erb +1 -1
- data/lib/blazing/templates/hook/base.erb +7 -0
- data/lib/blazing/templates/hook/bundler.erb +3 -0
- data/lib/blazing/templates/hook/git-reset.erb +10 -0
- data/lib/blazing/templates/hook/rake.erb +5 -0
- data/lib/blazing/templates/hook/recipes.erb +5 -0
- data/lib/blazing/templates/{hook.erb → hook/rvm.erb} +0 -29
- data/lib/blazing/templates/hook/setup.erb +9 -0
- data/lib/blazing.rb +3 -2
- data/spec/blazing/cli_spec.rb +33 -0
- data/spec/blazing/commands_spec.rb +134 -0
- data/spec/blazing/dsl_setter_spec.rb +29 -0
- data/spec/blazing/hook_spec.rb +148 -0
- data/spec/blazing/integration/deployment_spec.rb +32 -0
- data/spec/blazing/integration/init_spec.rb +3 -4
- data/spec/blazing/integration/list_spec.rb +4 -3
- data/spec/blazing/integration/recipes_spec.rb +2 -2
- data/spec/blazing/integration/setup_spec.rb +2 -2
- data/spec/blazing/integration/update_spec.rb +1 -3
- data/spec/blazing/logger_spec.rb +34 -0
- data/spec/blazing/recipe_spec.rb +1 -1
- data/spec/blazing/repository_spec.rb +41 -0
- data/spec/blazing/shell_spec.rb +19 -0
- data/spec/blazing/target_spec.rb +0 -25
- metadata +66 -35
- data/.rspec +0 -2
- data/lib/blazing/runner.rb +0 -79
- data/lib/blazing/version.rb +0 -7
- data/spec/blazing/runner_spec.rb +0 -24
data/.rvmrc
CHANGED
@@ -4,22 +4,35 @@
|
|
4
4
|
# development environment upon cd'ing into the directory
|
5
5
|
|
6
6
|
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="ruby-1.9.
|
7
|
+
environment_id="ruby-1.9.3-p0@blazing"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
8
13
|
|
9
14
|
#
|
10
15
|
# First we attempt to load the desired environment directly from the environment
|
11
|
-
# file. This is very fast and
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
12
17
|
# CLI and selector. If you want feedback on which environment was used then
|
13
18
|
# insert the word 'use' after --create as this triggers verbose mode.
|
14
19
|
#
|
15
20
|
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
17
23
|
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
24
|
|
19
|
-
[[ -s "
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
20
29
|
else
|
21
30
|
# If the environment file has not yet been created, use the RVM CLI to select.
|
22
|
-
rvm --create "$environment_id"
|
31
|
+
if ! rvm --create "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
return 1
|
35
|
+
fi
|
23
36
|
fi
|
24
37
|
|
25
38
|
#
|
@@ -28,22 +41,15 @@ fi
|
|
28
41
|
# necessary.
|
29
42
|
#
|
30
43
|
# filename=".gems"
|
31
|
-
# if [[ -s "$filename" ]]
|
44
|
+
# if [[ -s "$filename" ]]
|
45
|
+
# then
|
32
46
|
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
33
47
|
# fi
|
34
48
|
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
41
|
-
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
42
|
-
# gem install bundler
|
43
|
-
# fi
|
44
|
-
#
|
45
|
-
# # Bundle while reducing excess noise.
|
46
|
-
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
47
|
-
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
48
|
-
#
|
49
|
+
# If you use bundler, this might be useful to you:
|
50
|
+
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
+
# then
|
52
|
+
# bundle install
|
53
|
+
# fi
|
54
|
+
|
49
55
|
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
## 0.2.11 - July 11, 2012
|
4
|
+
|
5
|
+
* add pimpmychangelog and pimp changelog
|
6
|
+
* fix git/bundler related issue ([#60][])
|
7
|
+
* deprecate `:default` option for target
|
8
|
+
* pull hook out of target
|
9
|
+
* refactor and improve specs
|
10
|
+
* use `Blazing::Commands` in favor of `Blazing::Runner`
|
11
|
+
* other misc refactorings
|
12
|
+
|
3
13
|
## 0.2.10 - February 7, 2012
|
4
14
|
|
5
15
|
* Fix post-receive hook (use new syntax)
|
@@ -17,9 +27,9 @@
|
|
17
27
|
* update and improve readme and sample configuration
|
18
28
|
* deprecate `repository` DSL method
|
19
29
|
* allow environment variables to be defined in config when setting the
|
20
|
-
rake task (#58)
|
30
|
+
rake task ([#58][])
|
21
31
|
* allow the RAILS_ENV to be specified for a target (will be used when
|
22
|
-
calling rake) (#58)
|
32
|
+
calling rake) ([#58][])
|
23
33
|
|
24
34
|
## 0.2.7 - November 24, 2011
|
25
35
|
|
@@ -37,7 +47,7 @@
|
|
37
47
|
## 0.2.4 - November 9, 2011
|
38
48
|
|
39
49
|
* Fix logger, so the formatting does not get carried over to apps using
|
40
|
-
blazing. (#55)
|
50
|
+
blazing. ([#55][])
|
41
51
|
|
42
52
|
## 0.2.3 - November 1, 2011
|
43
53
|
|
@@ -65,20 +75,30 @@
|
|
65
75
|
|
66
76
|
## 0.1.2 - October 25, 2011
|
67
77
|
|
68
|
-
* setup initializes an empty repository, so first push will work (#47)
|
78
|
+
* setup initializes an empty repository, so first push will work ([#47][])
|
69
79
|
|
70
|
-
* simplified cli workflow (#45):
|
80
|
+
* simplified cli workflow ([#45][]):
|
71
81
|
* update runs update and setup:local
|
72
82
|
* setup:remote renamed to setup
|
73
83
|
* setup:remote also runs update
|
74
84
|
|
75
85
|
## 0.1.1 - October 25, 2011
|
76
86
|
|
77
|
-
* [BUG]: fix #48: dont bundle test and dev gems, do it quietly
|
78
|
-
* [BUG]: fix #44: accept target as argument
|
79
|
-
* [BUG]: fix #41: recipe gem loading issues resolved
|
87
|
+
* [BUG]: fix [#48][]: dont bundle test and dev gems, do it quietly
|
88
|
+
* [BUG]: fix [#44][]: accept target as argument
|
89
|
+
* [BUG]: fix [#41][]: recipe gem loading issues resolved
|
80
90
|
* remove documentation of external recipes
|
81
91
|
|
82
92
|
## 0.1.0 - October 24, 2011
|
83
93
|
|
84
94
|
[@effkay]: https://github.com/effkay
|
95
|
+
<!--- The following link definition list is generated by PimpMyChangelog --->
|
96
|
+
[#41]: https://github.com/effkay/blazing/issues/41
|
97
|
+
[#44]: https://github.com/effkay/blazing/issues/44
|
98
|
+
[#45]: https://github.com/effkay/blazing/issues/45
|
99
|
+
[#47]: https://github.com/effkay/blazing/issues/47
|
100
|
+
[#48]: https://github.com/effkay/blazing/issues/48
|
101
|
+
[#55]: https://github.com/effkay/blazing/issues/55
|
102
|
+
[#58]: https://github.com/effkay/blazing/issues/58
|
103
|
+
[#60]: https://github.com/effkay/blazing/issues/60
|
104
|
+
[@effkay]: https://github.com/effkay
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
guard :
|
1
|
+
guard :rspec, :version => 2, :cli => "--colour --fail-fast --format nested" do
|
2
|
+
|
3
|
+
# Generated: by guard-rspec
|
4
|
+
watch(%r{^spec/.+_spec\.rb})
|
5
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
6
|
+
watch('spec/spec_helper.rb') { "spec" }
|
7
|
+
|
8
|
+
# Not Generated
|
2
9
|
watch('spec/spec_helper.rb') { %w(spec/spec_helper spec) }
|
3
10
|
watch(%r{^spec/.+_spec\.rb})
|
4
11
|
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
5
12
|
watch(%r{^lib/blazing/(.+)\.rb}) { |m| "spec/blazing/#{m[1]}_spec.rb" }
|
6
13
|
watch('spec/spec_helper.rb') { "spec" }
|
7
14
|
watch(%r{^lib/blazing/templates/(.+)}) { "spec" }
|
8
|
-
watch('lib/blazing/
|
15
|
+
watch('lib/blazing/cli.rb') { "spec/blazing/integration/*" }
|
16
|
+
watch('lib/blazing/commands.rb') { "spec/blazing/integration/*" }
|
9
17
|
end
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Not everyone can or wants to deploy on heroku. But now you can have the same (we
|
|
10
10
|
Quickstart
|
11
11
|
----------
|
12
12
|
|
13
|
-
`blazing init`, edit your
|
13
|
+
`blazing init`, edit your blazing config, run `blazing setup [target]` to deploy your post-receive hook and you're set. Deploy with `git push <target> <branch>`.
|
14
14
|
|
15
15
|
Features
|
16
16
|
--------
|
@@ -77,7 +77,7 @@ List available recipes
|
|
77
77
|
|
78
78
|
Run the configured recipes (used on deployment target, can be used to test recipes localy)
|
79
79
|
|
80
|
-
The `setup` and `update` commands also take 'all' as an option. This .
|
80
|
+
The `setup` and `update` commands also take 'all' as an option. This will perform the action on all your defined targets.
|
81
81
|
|
82
82
|
#### Configuration (blazing DSL)
|
83
83
|
|
@@ -92,7 +92,7 @@ The `setup` and `update` commands also take 'all' as an option. This .
|
|
92
92
|
# Options recognized by blazing core:
|
93
93
|
# rails_env: used when calling the rake task after deployment
|
94
94
|
|
95
|
-
target :staging, '
|
95
|
+
target :staging, 'user@server:/var/www/someproject.com',
|
96
96
|
:recipe_specific_option => 'foo', :rails_env => 'production'
|
97
97
|
|
98
98
|
|
data/blazing.gemspec
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "blazing/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = "blazing"
|
7
|
-
|
6
|
+
|
7
|
+
#
|
8
|
+
# TODO: Remove Config.repository in 0.3
|
9
|
+
#
|
10
|
+
s.version = '0.2.11'
|
11
|
+
|
8
12
|
s.authors = ["Felipe Kaufmann"]
|
9
13
|
s.email = ["felipekaufmann@gmail.com"]
|
10
14
|
s.homepage = "https://github.com/effkay/blazing"
|
11
15
|
s.summary = %q{git push deployment helper}
|
12
16
|
s.description = %q{painless git push deployments for everyone}
|
13
|
-
|
14
17
|
s.rubyforge_project = "blazing"
|
15
|
-
|
16
18
|
s.files = `git ls-files`.split("\n")
|
17
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -25,10 +27,11 @@ Gem::Specification.new do |s|
|
|
25
27
|
s.add_development_dependency('rake','~> 0.9.2')
|
26
28
|
s.add_development_dependency('rspec')
|
27
29
|
s.add_development_dependency('guard')
|
28
|
-
s.add_development_dependency('guard-
|
30
|
+
s.add_development_dependency('guard-rspec')
|
29
31
|
s.add_development_dependency('ruby_gntp')
|
30
32
|
s.add_development_dependency('rb-fsevent')
|
31
33
|
s.add_development_dependency('pry')
|
34
|
+
s.add_development_dependency('pimpmychangelog')
|
32
35
|
|
33
36
|
s.add_dependency('grit')
|
34
37
|
s.add_dependency('logging')
|
data/lib/blazing/cli.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'blazing/
|
2
|
+
require 'blazing/commands'
|
3
3
|
|
4
4
|
module Blazing
|
5
5
|
class CLI < Thor
|
@@ -12,7 +12,7 @@ module Blazing
|
|
12
12
|
# Bootstrap blazing by creating a sample config file
|
13
13
|
#
|
14
14
|
def init
|
15
|
-
Blazing::
|
15
|
+
Blazing::Commands.run(:init)
|
16
16
|
end
|
17
17
|
|
18
18
|
desc 'setup [TARGET]', 'Setup local and remote repository/repositories for deployment'
|
@@ -26,7 +26,7 @@ module Blazing
|
|
26
26
|
# Setup a target to be deployed with blazing
|
27
27
|
#
|
28
28
|
def setup(target_name = nil)
|
29
|
-
Blazing::
|
29
|
+
Blazing::Commands.run(:setup, :target_name => target_name, :options => options)
|
30
30
|
end
|
31
31
|
|
32
32
|
desc 'update [TARGET]', 'Re-Generate and uplaod hook based on current configuration'
|
@@ -40,7 +40,7 @@ module Blazing
|
|
40
40
|
# Update the target hook so it matches the settings in the config
|
41
41
|
#
|
42
42
|
def update(target_name = nil)
|
43
|
-
Blazing::
|
43
|
+
Blazing::Commands.run(:update, :target_name => target_name, :options => options)
|
44
44
|
end
|
45
45
|
|
46
46
|
desc 'recipes [TARGET]', 'Run the recipes for the given target'
|
@@ -49,7 +49,7 @@ module Blazing
|
|
49
49
|
# Run the configured blazing recipes (used on remote machien)
|
50
50
|
#
|
51
51
|
def recipes(target_name)
|
52
|
-
Blazing::
|
52
|
+
Blazing::Commands.run(:recipes, :target_name => target_name, :options => options)
|
53
53
|
end
|
54
54
|
|
55
55
|
desc 'list', 'List available recipes'
|
@@ -58,8 +58,7 @@ module Blazing
|
|
58
58
|
# List the available blazing recipes
|
59
59
|
#
|
60
60
|
def list
|
61
|
-
Blazing::
|
61
|
+
Blazing::Commands.run(:list)
|
62
62
|
end
|
63
|
-
|
64
63
|
end
|
65
64
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Blazing
|
2
|
+
class Commands
|
3
|
+
|
4
|
+
include Logger
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def run(command, options = {})
|
8
|
+
self.new(options).send(command)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
warn 'The :default Target option has been deprecated and will be ignored' if options.has_key?(:default)
|
14
|
+
|
15
|
+
@target_name = options[:target_name]
|
16
|
+
@config_file = options[:file]
|
17
|
+
|
18
|
+
@config ||= Config.parse(@config_file)
|
19
|
+
@targets = determine_targets
|
20
|
+
|
21
|
+
error 'no target given or found' if @targets.empty?
|
22
|
+
|
23
|
+
# TODO: better exception handling, like this?
|
24
|
+
#raise RuntimeError if @targets.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def init
|
28
|
+
info "Creating an example config file in #{Blazing::DEFAULT_CONFIG_LOCATION}"
|
29
|
+
info "Customize it to your needs"
|
30
|
+
create_config_directory
|
31
|
+
write_config_file
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
@targets.each { |target| target.setup }
|
36
|
+
update
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
@targets.each { |target| target.update }
|
41
|
+
end
|
42
|
+
|
43
|
+
def recipes
|
44
|
+
@config.recipes.each { |recipe| recipe.run }
|
45
|
+
end
|
46
|
+
|
47
|
+
def list
|
48
|
+
Blazing::Recipe.pretty_list
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def create_config_directory
|
54
|
+
Dir.mkdir 'config' unless File.exists? 'config'
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_config_file
|
58
|
+
config = ERB.new(File.read("#{Blazing::TEMPLATE_ROOT}/config.erb")).result
|
59
|
+
File.open(Blazing::DEFAULT_CONFIG_LOCATION,"wb") { |f| f.puts config }
|
60
|
+
end
|
61
|
+
|
62
|
+
def determine_targets
|
63
|
+
if @target_name == 'all'
|
64
|
+
@config.targets
|
65
|
+
else
|
66
|
+
targets = []
|
67
|
+
targets << @config.find_target(@target_name)
|
68
|
+
targets.compact
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/blazing/config.rb
CHANGED
data/lib/blazing/hook.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module Blazing
|
2
|
+
class Hook
|
3
|
+
|
4
|
+
include Blazing::Logger
|
5
|
+
|
6
|
+
attr_accessor :target
|
7
|
+
|
8
|
+
def initialize(target)
|
9
|
+
@target = target
|
10
|
+
@config = target.config
|
11
|
+
@options = target.options
|
12
|
+
@shell = Blazing::Shell.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
prepare_hook
|
17
|
+
deploy_hook
|
18
|
+
end
|
19
|
+
|
20
|
+
def rake_command
|
21
|
+
rake_config = @config.instance_variable_get("@rake") || {}
|
22
|
+
rails_env = "RAILS_ENV=#{@options[:rails_env]}" if @options[:rails_env]
|
23
|
+
|
24
|
+
if rake_config[:task]
|
25
|
+
"#{rake_config[:env]} #{rails_env} bundle exec rake #{rake_config[:task]}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def load_template(template_name)
|
32
|
+
ERB.new(File.read(find_template(template_name))).result(binding)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_template(template_name)
|
36
|
+
"#{Blazing::TEMPLATE_ROOT}/#{template_name}.erb"
|
37
|
+
end
|
38
|
+
|
39
|
+
def prepare_hook
|
40
|
+
info "Generating and uploading post-receive hook for #{@target.name}"
|
41
|
+
hook = generate_hook
|
42
|
+
write hook
|
43
|
+
end
|
44
|
+
|
45
|
+
def deploy_hook
|
46
|
+
debug "Copying hook for #{@target.name} to #{@target.location}"
|
47
|
+
copy_hook
|
48
|
+
set_hook_permissions
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_hook
|
52
|
+
load_template 'hook/base'
|
53
|
+
end
|
54
|
+
|
55
|
+
def write(hook)
|
56
|
+
File.open(Blazing::TMP_HOOK, "wb") do |f|
|
57
|
+
f.puts hook
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_hook_permissions
|
62
|
+
if @target.host
|
63
|
+
@shell.run "ssh #{@target.user}@#{@target.host} #{make_hook_executable}"
|
64
|
+
else
|
65
|
+
@shell.run "#{make_hook_executable}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def copy_hook
|
70
|
+
debug "Making hook executable"
|
71
|
+
# TODO: handle missing user?
|
72
|
+
if @target.host
|
73
|
+
@shell.run "scp #{Blazing::TMP_HOOK} #{@target.user}@#{@target.host}:#{@target.path}/.git/hooks/post-receive"
|
74
|
+
else
|
75
|
+
@shell.run "cp #{Blazing::TMP_HOOK} #{@target.path}/.git/hooks/post-receive"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def make_hook_executable
|
80
|
+
debug "Making hook executable"
|
81
|
+
"chmod +x #{@target.path}/.git/hooks/post-receive"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
data/lib/blazing/logger.rb
CHANGED
data/lib/blazing/recipe.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'blazing/logger'
|
1
2
|
require 'active_support/inflector'
|
2
3
|
|
3
4
|
class Blazing::Recipe
|
@@ -34,5 +35,9 @@ class Blazing::Recipe
|
|
34
35
|
gems.each { |gem| require gem }
|
35
36
|
end
|
36
37
|
|
38
|
+
def pretty_list
|
39
|
+
list.each { |r| puts r.to_s.demodulize.underscore }
|
40
|
+
end
|
41
|
+
|
37
42
|
end
|
38
43
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'grit'
|
2
|
+
|
3
|
+
module Blazing
|
4
|
+
class Repository
|
5
|
+
|
6
|
+
include Blazing::Logger
|
7
|
+
|
8
|
+
def initialize(target)
|
9
|
+
@target = target
|
10
|
+
@shell = Blazing::Shell.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
# TODO: Handle case where user is empty
|
15
|
+
if @target.host
|
16
|
+
@shell.run "ssh #{@target.user}@#{@target.host} '#{init_repository} && #{setup_repository}'"
|
17
|
+
else
|
18
|
+
@shell.run "#{init_repository} && #{setup_repository}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_git_remote
|
23
|
+
info "Adding new remote #{@target.name} pointing to #{@target.location}"
|
24
|
+
set_git_remote!
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
#
|
30
|
+
# Initialize an empty repository
|
31
|
+
#
|
32
|
+
def init_repository
|
33
|
+
# Instead of git init with a path, so it does not fail on older
|
34
|
+
# git versions (https://github.com/effkay/blazing/issues/53)
|
35
|
+
"mkdir #{@target.path}; cd #{@target.path} && git init"
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Allow pushing to currently checked out branch
|
40
|
+
#
|
41
|
+
def setup_repository
|
42
|
+
"cd #{@target.path} && git config receive.denyCurrentBranch ignore"
|
43
|
+
end
|
44
|
+
|
45
|
+
def grit_repository_object
|
46
|
+
@grit_object ||= Grit::Repo.new(Dir.pwd)
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_git_remote!
|
50
|
+
grit_repository_object.config["remote.#{@target.name}.url"] = @target.location
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/blazing/target.rb
CHANGED
@@ -1,108 +1,52 @@
|
|
1
|
-
|
2
|
-
require 'grit'
|
1
|
+
module Blazing
|
3
2
|
|
4
|
-
class
|
3
|
+
class Target
|
5
4
|
|
6
|
-
|
5
|
+
include Blazing::Logger
|
7
6
|
|
8
|
-
|
7
|
+
attr_accessor :name, :location, :options, :config
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@target = self
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
info "Setting up repository for #{name} in #{location}"
|
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}"
|
9
|
+
def initialize(name, location, config, options = {})
|
10
|
+
@name = name
|
11
|
+
@location = location
|
12
|
+
@config = config
|
13
|
+
@options = options
|
14
|
+
@target = self
|
27
15
|
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def apply_hook
|
31
|
-
info "Generating and uploading post-receive hook for #{name}"
|
32
|
-
hook = ERB.new(File.read("#{Blazing::TEMPLATE_ROOT}/hook.erb")).result(binding)
|
33
16
|
|
34
|
-
|
35
|
-
|
17
|
+
#
|
18
|
+
# Set up Repositories and Hook
|
19
|
+
#
|
20
|
+
def setup
|
21
|
+
info "Setting up repository for #{name} in #{location}"
|
22
|
+
Repository.new(self).setup
|
36
23
|
end
|
37
24
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
25
|
+
#
|
26
|
+
# Update git remote and hook
|
27
|
+
#
|
28
|
+
def update
|
29
|
+
Repository.new(self).add_git_remote
|
30
|
+
Hook.new(self).setup
|
44
31
|
end
|
45
|
-
end
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def path
|
54
|
-
if host
|
55
|
-
@location.match(/:(.*)$/)[1]
|
56
|
-
else
|
57
|
-
@location
|
33
|
+
def path
|
34
|
+
if host
|
35
|
+
@location.match(/:(.*)$/)[1]
|
36
|
+
else
|
37
|
+
@location
|
38
|
+
end
|
58
39
|
end
|
59
|
-
end
|
60
40
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def user
|
67
|
-
user = @location.match(/(.*)@/)
|
68
|
-
user[1] unless user.nil?
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Initialize an empty repository, so we can push to it
|
73
|
-
#
|
74
|
-
def init_repository
|
75
|
-
# Instead of git init with a path, so it does not fail on older
|
76
|
-
# git versions (https://github.com/effkay/blazing/issues/53)
|
77
|
-
"mkdir #{path}; cd #{path} && git init"
|
78
|
-
end
|
79
|
-
|
80
|
-
def copy_hook
|
81
|
-
debug "Making hook executable"
|
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"
|
41
|
+
def host
|
42
|
+
host = @location.match(/@(.*):/)
|
43
|
+
host[1] unless host.nil?
|
87
44
|
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def make_hook_executable
|
91
|
-
debug "Making hook executable"
|
92
|
-
"chmod +x #{path}/.git/hooks/post-receive"
|
93
|
-
end
|
94
45
|
|
95
|
-
|
96
|
-
|
97
|
-
|
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]}"
|
46
|
+
def user
|
47
|
+
user = @location.match(/(.*)@/)
|
48
|
+
user[1] unless user.nil?
|
105
49
|
end
|
106
50
|
end
|
107
|
-
|
108
51
|
end
|
52
|
+
|
@@ -11,7 +11,7 @@
|
|
11
11
|
# Options recognized by blazing core:
|
12
12
|
# rails_env: used when calling the rake task after deployment
|
13
13
|
|
14
|
-
target :staging, '
|
14
|
+
target :staging, 'user@server:/var/www/someproject.com',
|
15
15
|
:recipe_specific_option => 'foo', :rails_env => 'production'
|
16
16
|
|
17
17
|
|