capistrano-fanfare 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,54 @@ Or install it yourself as:
20
20
 
21
21
  TODO: Write usage instructions here
22
22
 
23
+ Create a `Capfile` that looks like:
24
+
25
+ load 'deploy'
26
+
27
+ require 'capistrano/fanfare'
28
+
29
+ fanfare_recipe 'defaults'
30
+ fanfare_recipe 'multistage'
31
+ fanfare_recipe 'git_style'
32
+ fanfare_recipe 'bundler'
33
+ fanfare_recipe 'assets'
34
+ fanfare_recipe 'db_seed'
35
+
36
+ fanfare_recipe 'foreman'
37
+ fanfare_recipe 'database_yaml'
38
+
39
+ fanfare_recipe 'colors'
40
+ fanfare_recipe 'ssh'
41
+ fanfare_recipe 'console'
42
+ fanfare_recipe 'campfire'
43
+
44
+ Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
45
+
46
+ load 'config/deploy'
47
+
48
+ Pick and choose your fanfare recipes in `Capfile`--they are designed to work
49
+ independently but also build off each other.
50
+
51
+ Create a `config/deploy.rb` that looks like:
52
+
53
+ set :application, "myappname"
54
+ set :repository, "git@mygitserver.com:myappname.git"
55
+
56
+ set :campfire_options, :account => 'cfireaccount',
57
+ :room => 'Dev room',
58
+ :token => '010010010100101',
59
+ :ssl => true
60
+
61
+ Create a `config/deploy/staging.rb` (assuming the *multistage* recipe) that
62
+ looks like:
63
+
64
+ deploy_server = "myserver.example.com"
65
+
66
+ role :web, deploy_server
67
+ role :app, deploy_server
68
+ role :db, deploy_server, :primary => true
69
+ role :db, deploy_server
70
+
23
71
  ## Contributing
24
72
 
25
73
  1. Fork it
@@ -69,11 +69,18 @@ module Capistrano::Fanfare::Campfire
69
69
  # ========================================================================
70
70
 
71
71
  namespace :campfire do
72
+ desc <<-DESC
73
+ [internal] Posts a message in Campfire before a deploy has started.
74
+ DESC
72
75
  task :pre_deploy do
73
76
  @deploy_start_time = Time.now
74
77
  speak fetch(:campfire_pre_msg)
75
78
  end
76
79
 
80
+ desc <<-DESC
81
+ [internal] Posts a message and plays a clip after a successful
82
+ deployment.
83
+ DESC
77
84
  task :successful_deploy do
78
85
  elapsed = @deploy_start_time ? Time.now - @deploy_start_time : 0
79
86
 
@@ -81,6 +88,10 @@ module Capistrano::Fanfare::Campfire
81
88
  play fetch(:campfire_success_play)
82
89
  end
83
90
 
91
+ desc <<-DESC
92
+ [internal] Posts a message and plays a clip after a failed
93
+ deployment.
94
+ DESC
84
95
  task :rollback_deploy do
85
96
  speak fetch(:campfire_fail_msg)
86
97
  play fetch(:campfire_fail_play)
@@ -0,0 +1,73 @@
1
+ require 'capistrano'
2
+
3
+ module Capistrano::Fanfare::Console
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+ def _cset(name, *args, &block)
7
+ unless exists?(name)
8
+ set(name, *args, &block)
9
+ end
10
+ end
11
+
12
+ on :load do
13
+ if find_task("foreman:start")
14
+ _cset :console_env_cmd, "foreman run"
15
+ elsif find_task("bundle:install")
16
+ _cset :console_env_cmd, "bundle exec"
17
+ end
18
+ end
19
+
20
+
21
+ # =========================================================================
22
+ # These are the tasks that are available to help with deploying web apps.
23
+ # You can have cap give you a summary of them with `cap -T'.
24
+ # =========================================================================
25
+
26
+ ##
27
+ # Gratiously found in the moonshine codebase and iterated on:
28
+ # https://github.com/railsmachine/moonshine
29
+
30
+ desc <<-DESC
31
+ Runs a rails/rack console on the first application server.
32
+ DESC
33
+ task :console, :roles => :app, :except => {:no_symlink => true} do
34
+ rack_env = fetch(:rails_env, nil) || fetch(:rack_env, nil) || "production"
35
+ env_cmd = fetch(:console_env_cmd, "")
36
+ input = ''
37
+
38
+ console_test = [
39
+ "if [ -f #{current_path}/script/console ] ; then echo rails2",
40
+ "; elif [ -f #{current_path}/script/rails ] ; then echo rails3",
41
+ "; elif [ -f #{current_path}/config.ru -a -f #{current_path}/Gemfile ]",
42
+ "&& grep 'gem.*racksh' #{current_path}/Gemfile >/dev/null",
43
+ "; then echo racksh",
44
+ "; else echo unknown ; fi"
45
+ ].join(' ')
46
+
47
+ case capture(console_test).strip
48
+ when "rails2"
49
+ command = "cd #{current_path} && #{env_cmd} ./script/console #{rack_env}"
50
+ prompt = /^(>|\?)>/
51
+ when "rails3"
52
+ command = "cd #{current_path} && #{env_cmd} rails console #{rack_env}"
53
+ prompt = /:\d{3}:\d+(\*|>)/
54
+ when "racksh"
55
+ command = "cd #{current_path} && #{env_cmd} racksh #{rack_env}"
56
+ prompt = /:\d{3}:\d+(\*|>)/
57
+ else
58
+ raise "A suitable rails/rack console could not be found."
59
+ end
60
+
61
+ run command do |channel, stream, data|
62
+ next if data.chomp == input.chomp || data.chomp == ''
63
+ print data
64
+ channel.send_data(input = $stdin.gets) if data =~ prompt
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ if Capistrano::Configuration.instance
72
+ Capistrano::Fanfare::Console.load_into(Capistrano::Configuration.instance)
73
+ end
@@ -0,0 +1,37 @@
1
+ require 'capistrano'
2
+
3
+ module Capistrano::Fanfare::DbSeed
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ # =========================================================================
8
+ # These are the tasks that are available to help with deploying web apps.
9
+ # You can have cap give you a summary of them with `cap -T'.
10
+ # =========================================================================
11
+
12
+ namespace :db do
13
+
14
+ desc <<-DESC
15
+ Runs the rake db:seed task.
16
+
17
+ You can set the rails environment and full path to rake by setting some \
18
+ overriding variables. The defaults are:
19
+
20
+ set :rake, "rake"
21
+ set :rails_env, "production"
22
+
23
+ [WARNING] This command is probably not safe to run multiple times.
24
+ DESC
25
+ task :seed, :roles => :db, :only => { :primary => true } do
26
+ rails_env = fetch(:rails_env, nil) || fetch(:rack_env, nil) || "production"
27
+
28
+ run %{cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} db:seed}
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ if Capistrano::Configuration.instance
36
+ Capistrano::Fanfare::DbSeed.load_into(Capistrano::Configuration.instance)
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Fanfare
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -0,0 +1,136 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/capistrano'
3
+ require 'capistrano/fanfare'
4
+ require 'capistrano/fanfare/console'
5
+ require 'capistrano/fanfare/bundler'
6
+ require 'capistrano/fanfare/foreman'
7
+
8
+ describe Capistrano::Fanfare::Console do
9
+ before do
10
+ @config = Capistrano::Configuration.new
11
+ Capistrano::Fanfare::Console.load_into(@config)
12
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
13
+ end
14
+
15
+ describe "for variables" do
16
+ it "sets :console_env_cmd to 'foreman run' if foreman recipe is loaded" do
17
+ Capistrano::Fanfare::Foreman.load_into(@config)
18
+ @config.trigger(:load)
19
+
20
+ @config.fetch(:console_env_cmd).must_equal "foreman run"
21
+ end
22
+
23
+ it "sets :console_env_cmd to 'bundle exec' if foreman recipe is loaded" do
24
+ Capistrano::Fanfare::Bundler.load_into(@config)
25
+ @config.trigger(:load)
26
+
27
+ @config.fetch(:console_env_cmd).must_equal "bundle exec"
28
+ end
29
+ end
30
+
31
+ describe "for :console task" do
32
+ before do
33
+ @config.set :current_path, "/app/current"
34
+ end
35
+
36
+ let(:console_test) do
37
+ [ "if [ -f /app/current/script/console ] ; then echo rails2",
38
+ "; elif [ -f /app/current/script/rails ] ; then echo rails3",
39
+ "; elif [ -f /app/current/config.ru -a -f /app/current/Gemfile ]",
40
+ "&& grep 'gem.*racksh' /app/current/Gemfile >/dev/null",
41
+ "; then echo racksh",
42
+ "; else echo unknown ; fi"
43
+ ].join(' ')
44
+ end
45
+
46
+ it "runs a rails 2.x console if script/console is detected" do
47
+ @config.captures_responses[console_test] = "rails2\n"
48
+ @config.find_and_execute_task("console")
49
+
50
+ @config.must_have_run "cd /app/current && ./script/console production"
51
+ end
52
+
53
+ it "runs a rails 2.x console with 'forman run'" do
54
+ Capistrano::Fanfare::Bundler.load_into(@config)
55
+ Capistrano::Fanfare::Foreman.load_into(@config)
56
+ @config.trigger(:load)
57
+ @config.captures_responses[console_test] = "rails2\n"
58
+ @config.find_and_execute_task("console")
59
+
60
+ @config.must_have_run(
61
+ "cd /app/current && foreman run ./script/console production")
62
+ end
63
+
64
+ it "runs a rails 2.x console with 'bundle exec'" do
65
+ Capistrano::Fanfare::Bundler.load_into(@config)
66
+ @config.trigger(:load)
67
+ @config.captures_responses[console_test] = "rails2\n"
68
+ @config.find_and_execute_task("console")
69
+
70
+ @config.must_have_run(
71
+ "cd /app/current && bundle exec ./script/console production")
72
+ end
73
+
74
+ it "runs a rails 3.x console if script/rails is detected" do
75
+ @config.captures_responses[console_test] = "rails3\n"
76
+ @config.find_and_execute_task("console")
77
+
78
+ @config.must_have_run "cd /app/current && rails console production"
79
+ end
80
+
81
+ it "runs a rails 3.x console with 'foreman run'" do
82
+ Capistrano::Fanfare::Bundler.load_into(@config)
83
+ Capistrano::Fanfare::Foreman.load_into(@config)
84
+ @config.trigger(:load)
85
+ @config.captures_responses[console_test] = "rails3\n"
86
+ @config.find_and_execute_task("console")
87
+
88
+ @config.must_have_run(
89
+ "cd /app/current && foreman run rails console production")
90
+ end
91
+
92
+ it "runs a rails 3.x console with 'bundle exec'" do
93
+ Capistrano::Fanfare::Bundler.load_into(@config)
94
+ @config.trigger(:load)
95
+ @config.captures_responses[console_test] = "rails3\n"
96
+ @config.find_and_execute_task("console")
97
+
98
+ @config.must_have_run(
99
+ "cd /app/current && bundle exec rails console production")
100
+ end
101
+
102
+ it "runs racksh if the racksh gem is detected in the Gemfile" do
103
+ @config.captures_responses[console_test] = "racksh\n"
104
+ @config.find_and_execute_task("console")
105
+
106
+ @config.must_have_run "cd /app/current && racksh production"
107
+ end
108
+
109
+ it "runs racksh with 'foreman run'" do
110
+ Capistrano::Fanfare::Bundler.load_into(@config)
111
+ Capistrano::Fanfare::Foreman.load_into(@config)
112
+ @config.trigger(:load)
113
+ @config.captures_responses[console_test] = "racksh\n"
114
+ @config.find_and_execute_task("console")
115
+
116
+ @config.must_have_run(
117
+ "cd /app/current && foreman run racksh production")
118
+ end
119
+
120
+ it "runs racksh with 'bundle exec'" do
121
+ Capistrano::Fanfare::Bundler.load_into(@config)
122
+ @config.trigger(:load)
123
+ @config.captures_responses[console_test] = "racksh\n"
124
+ @config.find_and_execute_task("console")
125
+
126
+ @config.must_have_run(
127
+ "cd /app/current && bundle exec racksh production")
128
+ end
129
+
130
+ it "raises an exception if no suitable console if found" do
131
+ @config.captures_responses[console_test] = "unknown\n"
132
+
133
+ proc { @config.find_and_execute_task("console") }.must_raise RuntimeError
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/capistrano'
3
+ require 'capistrano/fanfare'
4
+ require 'capistrano/fanfare/db_seed'
5
+
6
+ describe Capistrano::Fanfare::DbSeed do
7
+ before do
8
+ @config = Capistrano::Configuration.new
9
+ Capistrano::Fanfare::DbSeed.load_into(@config)
10
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
11
+ end
12
+
13
+ describe "for namespace :db" do
14
+ describe "for :seed task" do
15
+ it "runs the db:seed rake task" do
16
+ @config.set :current_path, "/a/current"
17
+ @config.set :rake, "bin/rake"
18
+ @config.find_and_execute_task("db:seed")
19
+
20
+ @config.must_have_run(
21
+ "cd /a/current && bin/rake RAILS_ENV=production db:seed")
22
+ end
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-fanfare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-25 00:00:00.000000000 Z
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &70106299506720 !ruby/object:Gem::Requirement
16
+ requirement: &70156962133920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.10.0.pre
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70106299506720
24
+ version_requirements: *70156962133920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capistrano_colors
27
- requirement: &70106299506160 !ruby/object:Gem::Requirement
27
+ requirement: &70156962133340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70106299506160
35
+ version_requirements: *70156962133340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sushi
38
- requirement: &70106299505620 !ruby/object:Gem::Requirement
38
+ requirement: &70156962132820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.0.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70106299505620
46
+ version_requirements: *70156962132820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &70106299505060 !ruby/object:Gem::Requirement
49
+ requirement: &70156962132240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.10.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70106299505060
57
+ version_requirements: *70156962132240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitest-capistrano
60
- requirement: &70106299504560 !ruby/object:Gem::Requirement
60
+ requirement: &70156962131740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70106299504560
68
+ version_requirements: *70156962131740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
- requirement: &70106299503980 !ruby/object:Gem::Requirement
71
+ requirement: &70156962131180 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0.3'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70106299503980
79
+ version_requirements: *70156962131180
80
80
  description: Capistrano recipes (with full test suite) for fanfare application deployment
81
81
  framework
82
82
  email:
@@ -97,7 +97,9 @@ files:
97
97
  - lib/capistrano/fanfare/bundler.rb
98
98
  - lib/capistrano/fanfare/campfire.rb
99
99
  - lib/capistrano/fanfare/colors.rb
100
+ - lib/capistrano/fanfare/console.rb
100
101
  - lib/capistrano/fanfare/database_yaml.rb
102
+ - lib/capistrano/fanfare/db_seed.rb
101
103
  - lib/capistrano/fanfare/defaults.rb
102
104
  - lib/capistrano/fanfare/foreman.rb
103
105
  - lib/capistrano/fanfare/foreman/strategy.rb
@@ -112,7 +114,9 @@ files:
112
114
  - spec/bundler_spec.rb
113
115
  - spec/campfire_spec.rb
114
116
  - spec/colors_spec.rb
117
+ - spec/console_spec.rb
115
118
  - spec/database_yaml_spec.rb
119
+ - spec/db_seed_spec.rb
116
120
  - spec/defaults_spec.rb
117
121
  - spec/fixtures/Procfile
118
122
  - spec/fixtures/fanfare/bark.rb
@@ -138,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
142
  version: '0'
139
143
  segments:
140
144
  - 0
141
- hash: 1649157397655448049
145
+ hash: -2785244211495022277
142
146
  required_rubygems_version: !ruby/object:Gem::Requirement
143
147
  none: false
144
148
  requirements:
@@ -147,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
151
  version: '0'
148
152
  segments:
149
153
  - 0
150
- hash: 1649157397655448049
154
+ hash: -2785244211495022277
151
155
  requirements: []
152
156
  rubyforge_project:
153
157
  rubygems_version: 1.8.10
@@ -160,7 +164,9 @@ test_files:
160
164
  - spec/bundler_spec.rb
161
165
  - spec/campfire_spec.rb
162
166
  - spec/colors_spec.rb
167
+ - spec/console_spec.rb
163
168
  - spec/database_yaml_spec.rb
169
+ - spec/db_seed_spec.rb
164
170
  - spec/defaults_spec.rb
165
171
  - spec/fixtures/Procfile
166
172
  - spec/fixtures/fanfare/bark.rb