blazing 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +183 -0
  4. data/.travis.yml +8 -4
  5. data/CHANGELOG.md +7 -1
  6. data/Gemfile +1 -1
  7. data/Guardfile +6 -7
  8. data/README.md +30 -152
  9. data/Rakefile +5 -6
  10. data/bin/blazing +1 -2
  11. data/blazing.gemspec +17 -26
  12. data/lib/blazing.rb +2 -14
  13. data/lib/blazing/cli.rb +32 -39
  14. data/lib/blazing/commands.rb +18 -26
  15. data/lib/blazing/config.rb +21 -51
  16. data/lib/blazing/dsl.rb +37 -0
  17. data/lib/blazing/hook.rb +15 -11
  18. data/lib/blazing/logger.rb +13 -17
  19. data/lib/blazing/repository.rb +5 -1
  20. data/lib/blazing/shell.rb +5 -5
  21. data/lib/blazing/target.rb +3 -3
  22. data/lib/blazing/templates/config.erb +10 -45
  23. data/lib/blazing/templates/hook/base.erb +0 -3
  24. data/lib/blazing/templates/hook/bundler.erb +4 -3
  25. data/lib/blazing/templates/hook/env-scripts.erb +3 -3
  26. data/lib/blazing/templates/hook/rake.erb +0 -1
  27. data/lib/blazing/templates/hook/rvm.erb +3 -31
  28. data/lib/blazing/templates/hook/setup.erb +1 -1
  29. data/lib/blazing/version.rb +3 -0
  30. data/spec/blazing/cli_spec.rb +1 -11
  31. data/spec/blazing/commands_spec.rb +35 -65
  32. data/spec/blazing/config_spec.rb +22 -102
  33. data/spec/blazing/dsl_spec.rb +60 -0
  34. data/spec/blazing/hook_spec.rb +31 -82
  35. data/spec/blazing/integration/deployment_spec.rb +20 -22
  36. data/spec/blazing/integration/init_spec.rb +2 -4
  37. data/spec/blazing/integration/setup_spec.rb +30 -30
  38. data/spec/blazing/integration/update_spec.rb +35 -35
  39. data/spec/blazing/logger_spec.rb +0 -4
  40. data/spec/blazing/repository_spec.rb +8 -10
  41. data/spec/blazing/shell_spec.rb +2 -4
  42. data/spec/blazing/target_spec.rb +12 -13
  43. data/spec/spec_helper.rb +8 -12
  44. data/spec/support/dummy_config.rb +6 -0
  45. metadata +18 -35
  46. data/lib/blazing/dsl_setter.rb +0 -20
  47. data/lib/blazing/recipe.rb +0 -45
  48. data/lib/blazing/templates/hook/recipes.erb +0 -5
  49. data/spec/blazing/dsl_setter_spec.rb +0 -29
  50. data/spec/blazing/integration/list_spec.rb +0 -20
  51. data/spec/blazing/integration/recipes_spec.rb +0 -29
  52. data/spec/blazing/recipe_spec.rb +0 -42
@@ -1,8 +1,8 @@
1
1
  require 'erb'
2
+ require_relative 'target'
2
3
 
3
4
  module Blazing
4
5
  class Hook
5
-
6
6
  include Blazing::Logger
7
7
 
8
8
  attr_accessor :target
@@ -20,16 +20,21 @@ module Blazing
20
20
  end
21
21
 
22
22
  def rake_command
23
- rake_config = @config.instance_variable_get("@rake") || {}
24
- rails_env = "RAILS_ENV=#{@options[:rails_env]}" if @options[:rails_env]
25
-
26
- if rake_config[:task]
27
- "#{rake_config[:env]} #{rails_env} bundle exec rake #{rake_config[:task]}"
28
- end
23
+ "#{options_as_vars}bundle exec rake #{@config.rake_task}" if @config.rake_task
29
24
  end
30
25
 
31
26
  private
32
27
 
28
+ def options_as_vars
29
+ keys = @options.keys
30
+ options = ''
31
+ keys.each do |key|
32
+ options << "#{key.to_s.upcase}=#{@options[key]} "
33
+ end
34
+
35
+ options
36
+ end
37
+
33
38
  def load_template(template_name)
34
39
  ::ERB.new(File.read(find_template(template_name))).result(binding)
35
40
  end
@@ -55,7 +60,7 @@ module Blazing
55
60
  end
56
61
 
57
62
  def write(hook)
58
- File.open(Blazing::TMP_HOOK, "wb") do |f|
63
+ File.open(Blazing::TMP_HOOK, 'wb') do |f|
59
64
  f.puts hook
60
65
  end
61
66
  end
@@ -69,7 +74,7 @@ module Blazing
69
74
  end
70
75
 
71
76
  def copy_hook
72
- debug "Making hook executable"
77
+ debug 'Making hook executable'
73
78
  # TODO: handle missing user?
74
79
  if @target.host
75
80
  @shell.run "scp #{Blazing::TMP_HOOK} #{@target.user}@#{@target.host}:#{@target.path}/.git/hooks/post-receive"
@@ -79,9 +84,8 @@ module Blazing
79
84
  end
80
85
 
81
86
  def make_hook_executable
82
- debug "Making hook executable"
87
+ debug 'Making hook executable'
83
88
  "chmod +x #{@target.path}/.git/hooks/post-receive"
84
89
  end
85
90
  end
86
91
  end
87
-
@@ -2,38 +2,34 @@ require 'logging'
2
2
 
3
3
  module Blazing
4
4
  module Logger
5
-
6
5
  # include Logging.globally
7
6
 
8
7
  # here we setup a color scheme called 'bright'
9
- Logging.color_scheme( 'bright',
10
- :levels => {
11
- :debug => :green,
12
- :info => :green,
13
- :warn => :yellow,
14
- :error => [:white, :on_red],
15
- :fatal => [:white, :on_red]
16
- }
17
- )
8
+ Logging.color_scheme('bright',
9
+ levels: {
10
+ debug: :green,
11
+ info: :green,
12
+ warn: :yellow,
13
+ error: [:white, :on_red],
14
+ fatal: [:white, :on_red]
15
+ }
16
+ )
18
17
 
19
18
  Logging.appenders.stdout(
20
19
  'stdout',
21
- :layout => Logging.layouts.pattern(
22
- :pattern => ' ------> [blazing] %-5l: %m\n',
23
- :color_scheme => 'bright'
20
+ layout: Logging.layouts.pattern(
21
+ pattern: ' ------> [blazing] %-5l: %m\n',
22
+ color_scheme: 'bright'
24
23
  )
25
24
  )
26
25
 
27
26
  Logging.logger.root.appenders = 'stdout'
28
27
  Logging.logger.root.level = :info
29
- Logging.consolidate :root
30
28
 
31
- %w[debug info warn error fatal].each do |level|
29
+ %w(debug info warn error fatal).each do |level|
32
30
  define_method level do |message|
33
31
  Logging.logger[self].send(level, message)
34
32
  end
35
33
  end
36
-
37
34
  end
38
35
  end
39
-
@@ -1,8 +1,12 @@
1
+ #
2
+ # Handles local repository settings
3
+ #
1
4
  require 'grit'
5
+ require_relative './shell'
6
+ require_relative './logger'
2
7
 
3
8
  module Blazing
4
9
  class Repository
5
-
6
10
  include Blazing::Logger
7
11
 
8
12
  def initialize(target)
@@ -1,7 +1,7 @@
1
- class Blazing::Shell
2
-
3
- def run(command)
4
- `#{command}`
1
+ module Blazing
2
+ class Shell
3
+ def run(command)
4
+ `#{command}`
5
+ end
5
6
  end
6
-
7
7
  end
@@ -1,7 +1,8 @@
1
- module Blazing
1
+ require_relative 'repository'
2
+ require_relative 'hook'
2
3
 
4
+ module Blazing
3
5
  class Target
4
-
5
6
  include Blazing::Logger
6
7
 
7
8
  attr_accessor :name, :location, :options, :config
@@ -49,4 +50,3 @@ module Blazing
49
50
  end
50
51
  end
51
52
  end
52
-
@@ -12,59 +12,24 @@
12
12
  # rails_env: used when calling the rake task after deployment
13
13
 
14
14
  target :staging, 'user@server:/var/www/someproject.com',
15
- :recipe_specific_option => 'foo', :rails_env => 'production'
15
+ :rails_env => 'production'
16
16
 
17
-
18
- # Sample rvm setup:
17
+ # Sample rvm/rbenv/chruby/other setup:
19
18
  #
20
- # rvm <rvm-string>
19
+ # env_sript <your rvm setup scripts>
21
20
  #
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
-
29
-
30
- # Sample config for custom rvm location:
31
- #
32
- # rvm_scripts <path_to_rvm_scripts>
33
- #
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'
38
-
39
- # Sample rbenv/chruby/other setup:
40
- #
41
- # env_scripts <path_to_version_manager_script>
42
- #
43
- # If you need to source a file for your non-rvm version manager to
44
- # you can do that with env_scripts. You should also remove the
45
- # rvm/rvm_scripts options above.
46
-
47
- env_scripts '/etc/profile.d/rbenv.sh'
48
-
49
- # Sample recipe setup:
50
- #
51
- # recipe <recipe_name>, [options]
52
- #
53
- # The given recipe will be called with the provided options. Refer to each
54
- # recipe's documentation for available options. Options provided here
55
- # may be overridden by target specific options.
56
- # Recipes will be executed in the order they are defined!yy
57
-
58
- recipe :precompile_assets, :recipe_specific_option => 'bar'
59
-
21
+ # Setting an env_script path makes sure it is sourced before the hook
22
+ # does anything at all. That way you can setup any environment things
23
+ # you need to. Most commonly this will be sourcing rvm and setting a
24
+ # ruby, or doing something with rbenv or chruby.
25
+ env_script '/etc/profile.d/rbenv.sh'
60
26
 
61
27
  # Sample rake file config:
62
28
  #
63
29
  # rake <task>, [environment variables]
64
30
  #
65
- # The provided rake task will be run after all recipes have run.
31
+ # The provided rake task will be run after blazing has done its stuff.
66
32
  # Note: you can only call a single rake task. If you need to run several
67
33
  # tasks just create one task that wrapps all the others.
68
34
 
69
- rake :post_deploy, 'RAILS_ENV=production'
70
-
35
+ rake :post_deploy
@@ -1,8 +1,5 @@
1
1
  <%= load_template 'hook/setup' %>
2
2
  <%= load_template 'hook/git-reset' %>
3
3
  <%= load_template 'hook/env-scripts' %>
4
- <%= load_template 'hook/rvm' %>
5
4
  <%= load_template 'hook/bundler' %>
6
- <%= load_template 'hook/recipes' %>
7
5
  <%= load_template 'hook/rake' %>
8
-
@@ -1,3 +1,4 @@
1
- echo "------> [blazing] Bundling gems"
2
- bundle --deployment --quiet --without development test
3
-
1
+ if [ -f "Gemfile" ] ; then
2
+ echo "------> [blazing] Bundling gems"
3
+ bundle --deployment --quiet --without development test
4
+ fi
@@ -1,6 +1,6 @@
1
- <% if @config.env_scripts %>
1
+ <% if @config.env_script %>
2
2
 
3
- source <%= @config.env_scripts %>
4
- echo "------> [blazing] Loading environment scripts from custom location"
3
+ source <%= @config.env_script %>
4
+ echo "------> [blazing] Sourcing environment script"
5
5
 
6
6
  <% end %>
@@ -2,4 +2,3 @@
2
2
  echo "------> [blazing] running <%= rake_command %>"
3
3
  <%= rake_command %>
4
4
  <% end %>
5
-
@@ -1,35 +1,7 @@
1
- <% if @config.rvm %>
1
+ <% if @config.rvm? %>
2
2
 
3
- #
4
- # Normal RVM installation
5
- #
6
- <% unless @config.rvm_scripts %>
7
- # Load RVM into a shell session *as a function*
8
- if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
9
-
10
- # First try to load from a user install
11
- source "$HOME/.rvm/scripts/rvm"
12
-
13
- elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
14
-
15
- # Then try to load from a root install
16
- source "/usr/local/rvm/scripts/rvm"
17
-
18
- else
19
- echo '------> [blazing] ERROR: RVM was enabled in config but no RVM installation was not found\n'
20
- fi
21
- <% end %>
22
-
23
- #
24
- # Apply rvm env
25
- #
26
- <% if @config.rvm == :rvmrc %>
27
- echo "------> [blazing] Loading rvm from .rvmrc"
28
- source .rvmrc
29
- <% else %>
30
- echo "------> [blazing] Loading rvm string: <%= @config.rvm %>"
31
- rvm use <%= @config.rvm %>
32
- <% end %>
3
+ echo "------> [blazing] Loading rvm from .rvmrc"
4
+ source .rvmrc
33
5
 
34
6
  <% end %>
35
7
 
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  echo "------"
4
4
  echo "------ [blazing] ENTERING POST RECEIVE HOOK FOR: <%= @target.name %>"
@@ -0,0 +1,3 @@
1
+ module Blazing
2
+ VERSION = '0.5.0'
3
+ end
@@ -1,9 +1,8 @@
1
1
  require 'spec_helper'
2
+ require 'blazing/cli'
2
3
 
3
4
  module Blazing
4
-
5
5
  describe CLI do
6
-
7
6
  let(:cli) { CLI.new }
8
7
  it 'has an init method' do
9
8
  cli.respond_to? :init
@@ -17,17 +16,8 @@ module Blazing
17
16
  cli.respond_to? :update
18
17
  end
19
18
 
20
- it 'has a recipes method' do
21
- cli.respond_to? :recipes
22
- end
23
-
24
- it 'has a list method' do
25
- cli.respond_to? :list
26
- end
27
-
28
19
  it 'has a help method' do
29
20
  cli.respond_to? :help
30
21
  end
31
22
  end
32
23
  end
33
-
@@ -1,24 +1,18 @@
1
1
  require 'spec_helper'
2
- require 'blazing/commands'
2
+ require_relative '../../lib/blazing/commands'
3
+ require_relative '../../lib/blazing/config'
3
4
 
4
5
  module Blazing
5
-
6
6
  describe Commands do
7
-
8
7
  let(:config_instance) { Blazing::Config.new }
9
8
 
10
- let(:target_a) { double('target_a', :name => 'target_a', :update => nil, :setup => nil) }
11
- let(:target_b) { double('target_b', :name => 'target_b', :update => nil, :setup => nil) }
9
+ let(:target_a) { double('target_a', name: 'target_a', update: nil, setup: nil) }
10
+ let(:target_b) { double('target_b', name: 'target_b', update: nil, setup: nil) }
12
11
  let(:targets) { [target_a, target_b] }
13
12
 
14
- let(:recipe_a) { double('recipe_a', :name => 'recipe_a', :run => nil) }
15
- let(:recipe_b) { double('recipe_b', :name => 'recipe_b', :run => nil) }
16
- let(:recipes) { [recipe_a, recipe_b] }
17
-
18
13
  let(:config) do
19
14
  config = config_instance
20
15
  config.targets = targets
21
- config.recipes = recipes
22
16
 
23
17
  config
24
18
  end
@@ -27,118 +21,94 @@ module Blazing
27
21
  let(:commands_instance) { commands.new }
28
22
 
29
23
  before :each do
30
- Config.stub(:parse).and_return(config)
24
+ allow(Config).to receive(:parse).and_return config
31
25
  end
32
26
 
33
27
  describe '.new' do
34
28
  it 'reads the config file when the command requires it' do
35
- Config.should_receive(:parse).and_return(config)
36
- commands.new(:command => :setup)
29
+ expect(Config).to receive(:parse).and_return config
30
+ commands.new(command: :setup)
37
31
  end
38
32
 
39
33
  it 'does not read the config file when the command does not need it' do
40
- Config.should_not_receive(:parse)
41
- commands.new(:command => :init)
34
+ expect(Config).not_to receive(:parse)
35
+ commands.new(command: :init)
42
36
  end
43
37
  end
44
38
 
45
39
  describe '#run' do
46
40
  it 'creates an instance of itself' do
47
- commands_instance.stub!(:dummy_command)
48
- commands.should_receive(:new).with({ :command => :dummy_command }).and_return(commands_instance)
41
+ allow(commands_instance).to receive :dummy_command
42
+ expect(commands).to receive(:new).with(command: :dummy_command).and_return(commands_instance)
49
43
  commands.run(:dummy_command)
50
44
  end
51
45
 
52
46
  it 'runs the specified command' do
53
- commands_instance.should_receive(:dummy_command)
54
- commands.stub(:new).with({ :command => :dummy_command }).and_return(commands_instance)
47
+ expect(commands_instance).to receive(:dummy_command)
48
+ allow(commands).to receive(:new).with(command: :dummy_command).and_return(commands_instance)
55
49
  commands.run(:dummy_command)
56
50
  end
57
-
58
- it 'raises an exception if the command does not exist' do
59
- pending 'Implement after reading exceptional Ruby ;-)'
60
- end
61
51
  end
62
52
 
63
53
  describe '#init' do
64
54
  it 'creates a config directory if it does not exist' do
65
- Dir.should_receive(:mkdir).with('config')
66
- File.stub(:exists?).and_return(false)
67
- File.stub(:open)
55
+ expect(Dir).to receive(:mkdir).with('config')
56
+ allow(File).to receive(:exist?).and_return(false)
57
+ allow(File).to receive(:open)
68
58
  commands.run(:init)
69
59
  end
70
60
 
71
61
  it 'creates a config file' do
72
62
  file = double('file').as_null_object
73
- File.should_receive(:open).with("config/blazing.rb", "wb").and_yield(file)
63
+ expect(File).to receive(:open).with('config/blazing.rb', 'wb').and_yield(file)
74
64
  commands.run(:init)
75
65
  end
76
66
  end
77
67
 
78
68
  describe '#setup' do
79
69
  it 'runs the setup method on the specified target' do
80
- target_a.should_receive(:setup)
81
- target_b.should_not_receive(:setup)
82
- commands.run(:setup, :target_name => target_a.name)
70
+ expect(target_a).to receive(:setup)
71
+ expect(target_b).not_to receive(:setup)
72
+ commands.run(:setup, target_name: target_a.name)
83
73
  end
84
74
 
85
75
  it 'does nothing when no target is specified' do
86
- target_a.should_not_receive(:setup)
87
- target_b.should_not_receive(:setup)
76
+ expect(target_a).not_to receive(:setup)
77
+ expect(target_b).not_to receive(:setup)
88
78
  commands.run(:setup)
89
79
  end
90
80
 
91
81
  it 'runs setup on all targets if "all" is specified' do
92
- target_a.should_receive(:setup)
93
- target_b.should_receive(:setup)
94
- commands.run(:setup, :target_name => 'all')
82
+ expect(target_a).to receive(:setup)
83
+ expect(target_b).to receive(:setup)
84
+ commands.run(:setup, target_name: 'all')
95
85
  end
96
86
 
97
87
  it 'runs the update command' do
98
- commands_instance.should_receive(:update)
99
- commands.stub(:new).and_return(commands_instance)
88
+ expect(commands_instance).to receive(:update)
89
+ allow(commands).to receive(:new).and_return(commands_instance)
100
90
  commands.run(:setup)
101
91
  end
102
92
  end
103
93
 
104
94
  describe '#update' do
105
95
  it 'runs the update method on the specified target' do
106
- target_a.should_receive(:update)
107
- target_b.should_not_receive(:update)
108
- commands.run(:update, :target_name => target_a.name)
96
+ expect(target_a).to receive(:update)
97
+ expect(target_b).not_to receive(:update)
98
+ commands.run(:update, target_name: target_a.name)
109
99
  end
110
100
 
111
101
  it 'does nothing when no target is specified' do
112
- target_a.should_not_receive(:update)
113
- target_b.should_not_receive(:update)
102
+ expect(target_a).not_to receive(:update)
103
+ expect(target_b).not_to receive(:update)
114
104
  commands.run(:update)
115
105
  end
116
106
 
117
107
  it 'runs update on all targets if "all" is specified' do
118
- target_a.should_receive(:update)
119
- target_b.should_receive(:update)
120
- commands.run(:update, :target_name => 'all')
121
- end
122
- end
123
-
124
- describe '#recipes' do
125
- it 'runs each recipe' do
126
- recipes.each { |r| r.should_receive(:run) }
127
- commands.run(:recipes)
128
- end
129
-
130
- it 'passes in target_name' do
131
- recipes.each { |r| r.should_receive(:run).with({:target_name => :testing}) }
132
- commands.run(:recipes, :target_name => :testing)
133
- end
134
- end
135
-
136
- describe '#list' do
137
- it 'lists each recipe' do
138
- Blazing::Recipe.should_receive(:pretty_list)
139
- commands.run(:list)
108
+ expect(target_a).to receive(:update)
109
+ expect(target_b).to receive(:update)
110
+ commands.run(:update, target_name: 'all')
140
111
  end
141
112
  end
142
113
  end
143
114
  end
144
-