jw-heroku-rails 0.4.6

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.
@@ -0,0 +1,232 @@
1
+ require 'heroku-rails'
2
+
3
+ HEROKU_CONFIG_FILE = File.join(HerokuRails::Config.root, 'config', 'heroku.yml')
4
+ HEROKU_CONFIG = HerokuRails::Config.new(HEROKU_CONFIG_FILE)
5
+ HEROKU_RUNNER = HerokuRails::Runner.new(HEROKU_CONFIG)
6
+
7
+ # create all the the environment specific tasks
8
+ (HEROKU_CONFIG.apps).each do |heroku_env, app_name|
9
+ desc "Select #{heroku_env} Heroku app for later commands"
10
+ task heroku_env do
11
+
12
+ # callback switch_environment
13
+ @heroku_app = {:env => heroku_env, :app_name => app_name}
14
+ Rake::Task["heroku:switch_environment"].reenable
15
+ Rake::Task["heroku:switch_environment"].invoke
16
+
17
+ HEROKU_RUNNER.add_environment(heroku_env)
18
+ end
19
+ end
20
+
21
+ desc 'Select all Heroku apps for later command'
22
+ task :all do
23
+ HEROKU_RUNNER.all_environments
24
+ end
25
+
26
+ namespace :heroku do
27
+ def system_with_echo(*args)
28
+ HEROKU_RUNNER.system_with_echo(*args)
29
+ end
30
+
31
+ desc 'Add git remotes for all apps in this project'
32
+ task :remotes => :all do
33
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
34
+ system_with_echo("git remote add #{heroku_env} #{repo}")
35
+ end
36
+ end
37
+
38
+ desc 'Lists configured apps'
39
+ task :apps => :all do
40
+ puts "\n"
41
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
42
+ puts "#{heroku_env} maps to the Heroku app #{app_name} located at:"
43
+ puts " #{repo}"
44
+ puts
45
+ end
46
+ end
47
+
48
+ desc "Get remote server information on the heroku app"
49
+ task :info do
50
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
51
+ system_with_echo "heroku info --app #{app_name}"
52
+ puts "\n"
53
+ end
54
+ end
55
+
56
+ desc "Get config settings on the heroku app"
57
+ task :config do
58
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
59
+ system_with_echo "heroku config --app #{app_name}"
60
+ puts "\n"
61
+ end
62
+ end
63
+
64
+ namespace :maintenance do
65
+ desc "turn on maintenance page for the heroku app"
66
+ task :on do
67
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
68
+ system_with_echo "heroku maintenance:on --app #{app_name}"
69
+ puts "\n"
70
+ end
71
+ end
72
+
73
+ desc "turn off maintenance page for the heroku app"
74
+ task :off do
75
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
76
+ system_with_echo "heroku maintenance:off --app #{app_name}"
77
+ puts "\n"
78
+ end
79
+ end
80
+ end
81
+
82
+ desc "Deploys, migrates and restarts latest code"
83
+ task :deploy => "heroku:before_deploy" do
84
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
85
+ puts "\n\nDeploying to #{app_name}..."
86
+ # set the current heroku_app so that callbacks can read the data
87
+ @heroku_app = {:env => heroku_env, :app_name => app_name, :repo => repo}
88
+ Rake::Task["heroku:before_each_deploy"].reenable
89
+ Rake::Task["heroku:before_each_deploy"].invoke(app_name)
90
+
91
+ rake_cmd = HEROKU_CONFIG.rake_cmd(heroku_env)
92
+
93
+ branch = `git branch`.scan(/^\* (.*)\n/).flatten.first.to_s
94
+ if branch.present?
95
+ @git_push_arguments ||= []
96
+ system_with_echo "git push #{repo} #{@git_push_arguments.join(' ')} #{branch}:master && #{rake_cmd} --app #{app_name} db:migrate && heroku restart --app #{app_name}"
97
+ else
98
+ puts "Unable to determine the current git branch, please checkout the branch you'd like to deploy"
99
+ exit(1)
100
+ end
101
+ Rake::Task["heroku:after_each_deploy"].reenable
102
+ Rake::Task["heroku:after_each_deploy"].invoke(app_name)
103
+ puts "\n"
104
+ end
105
+ Rake::Task["heroku:after_deploy"].invoke
106
+ end
107
+
108
+ # Callback before all deploys
109
+ task :before_deploy do
110
+ end
111
+
112
+ # Callback after all deploys
113
+ task :after_deploy do
114
+ end
115
+
116
+ # Callback before each deploy
117
+ task :before_each_deploy, [:app_name] do |t,args|
118
+ end
119
+
120
+ # Callback after each deploy
121
+ task :after_each_deploy, [:app_name] do |t,args|
122
+ end
123
+
124
+ # Callback for when we switch environment
125
+ task :switch_environment do
126
+ end
127
+
128
+ desc "Force deploys, migrates and restarts latest code"
129
+ task :force_deploy do
130
+ @git_push_arguments ||= []
131
+ @git_push_arguments << '--force'
132
+ Rake::Task["heroku:deploy"].execute
133
+ end
134
+
135
+ desc "Captures a bundle on Heroku"
136
+ task :capture do
137
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
138
+ system_with_echo "heroku bundles:capture --app #{app_name}"
139
+ end
140
+ end
141
+
142
+ desc "Opens a remote console"
143
+ task :console do
144
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
145
+ system_with_echo "heroku console --app #{app_name}"
146
+ end
147
+ end
148
+
149
+ desc "Shows the Heroku logs"
150
+ task :logs do
151
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
152
+ system_with_echo "heroku logs --app #{app_name}"
153
+ end
154
+ end
155
+
156
+ desc "Restarts remote servers"
157
+ task :restart do
158
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
159
+ system_with_echo "heroku restart --app #{app_name}"
160
+ end
161
+ end
162
+
163
+ namespace :setup do
164
+
165
+ desc "Creates the apps on Heroku"
166
+ task :apps do
167
+ HEROKU_RUNNER.setup_apps
168
+ end
169
+
170
+ desc "Setup the Heroku stacks from heroku.yml config"
171
+ task :stacks do
172
+ HEROKU_RUNNER.setup_stacks
173
+ end
174
+
175
+ desc "Setup the Heroku collaborators from heroku.yml config"
176
+ task :collaborators do
177
+ HEROKU_RUNNER.setup_collaborators
178
+ end
179
+
180
+ desc "Setup the Heroku environment config variables from heroku.yml config"
181
+ task :config do
182
+ HEROKU_RUNNER.setup_config
183
+ end
184
+
185
+ desc "Setup the Heroku addons from heroku.yml config"
186
+ task :addons do
187
+ HEROKU_RUNNER.setup_addons
188
+ end
189
+
190
+ desc "Setup the Heroku domains from heroku.yml config"
191
+ task :domains do
192
+ HEROKU_RUNNER.setup_domains
193
+ end
194
+ end
195
+
196
+ desc "Setup Heroku deploy environment from heroku.yml config"
197
+ task :setup => [
198
+ "heroku:setup:apps",
199
+ "heroku:setup:stacks",
200
+ "heroku:setup:collaborators",
201
+ "heroku:setup:config",
202
+ "heroku:setup:addons",
203
+ "heroku:setup:domains",
204
+ ]
205
+
206
+ namespace :db do
207
+ desc "Migrates and restarts remote servers"
208
+ task :migrate do
209
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
210
+ rake_cmd = HEROKU_CONFIG.rake_cmd(heroku_env)
211
+ system_with_echo "#{rake_cmd} --app #{app_name} db:migrate && heroku restart --app #{app_name}"
212
+ end
213
+ end
214
+
215
+ desc "Pulls the database from heroku and stores it into db/dumps/"
216
+ task :pull do
217
+ HEROKU_RUNNER.each_heroku_app do |heroku_env, app_name, repo|
218
+ system_with_echo "heroku pgdumps:capture --app #{app_name}"
219
+ dump = `heroku pgdumps --app #{app_name}`.split("\n").last.split(" ").first
220
+ system_with_echo "mkdir -p #{HerokuRails::Config.root}/db/dumps"
221
+ file = "#{HerokuRails::Config.root}/db/dumps/#{dump}.sql.gz"
222
+ url = `heroku pgdumps:url --app #{app_name} #{dump}`.chomp
223
+ system_with_echo "wget", url, "-O", file
224
+
225
+ # TODO: these are a bit distructive...
226
+ # system_with_echo "rake db:drop db:create"
227
+ # system_with_echo "gunzip -c #{file} | #{HerokuRails::Config.root}/script/dbconsole"
228
+ # system_with_echo "rake jobs:clear"
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,48 @@
1
+ apps:
2
+ production: awesomeapp
3
+ staging: awesomeapp-staging
4
+
5
+ stacks:
6
+ all: bamboo-mri-1.9.2
7
+ staging: bamboo-ree-1.8.7
8
+
9
+ config:
10
+ all:
11
+ BUNDLE_WITHOUT: "test:development"
12
+ CONFIG_VAR1: "config1"
13
+ CONFIG_VAR2: "config2"
14
+
15
+ production:
16
+ CONFIG_VAR1: "config1-production"
17
+
18
+ staging:
19
+ CONFIG_VAR1: "config1-staging"
20
+ STAGING_CONFIG: "special-staging"
21
+
22
+ collaborators:
23
+ all:
24
+ - "all-user1@somedomain.com"
25
+ - "all-user2@somedomain.com"
26
+ - "all-user2@somedomain.com"
27
+ staging:
28
+ - "staging-user@somedomain.com"
29
+ production:
30
+ - "production-user@somedomain.com"
31
+
32
+ domains:
33
+ staging:
34
+ - "staging.awesomeapp.com"
35
+ production:
36
+ - "awesomeapp.com"
37
+ - "www.awesomeapp.com"
38
+
39
+ addons:
40
+ all:
41
+ # add any other addons here
42
+ - custom_domains:basic
43
+ - newrelic:bronze
44
+
45
+ production:
46
+ # list production env specific addons here
47
+ - ssl:piggyback
48
+ - cron:daily
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ module HerokuRails
4
+ describe Config do
5
+ before(:each) do
6
+ @config = Config.new(config_path("heroku-config.yml"))
7
+ end
8
+
9
+ it "should read the configuration file" do
10
+ @config.settings.should_not be_empty
11
+ end
12
+
13
+ describe "#apps" do
14
+ it "should return the list of apps defined" do
15
+ @config.apps.should have(2).apps
16
+ @config.apps.should include("production" => "awesomeapp")
17
+ @config.apps.should include("staging" => "awesomeapp-staging")
18
+ end
19
+ end
20
+
21
+ describe "#app_names" do
22
+ it "should return the list of apps defined" do
23
+ @config.app_names.should have(2).names
24
+ @config.app_names.should include("awesomeapp")
25
+ @config.app_names.should include("awesomeapp-staging")
26
+ end
27
+ end
28
+
29
+ describe "#app_environments" do
30
+ it "should return a list of the environments defined" do
31
+ @config.app_environments.should have(2).environments
32
+ @config.app_environments.should include("production")
33
+ @config.app_environments.should include("staging")
34
+ end
35
+ end
36
+
37
+ describe "#stack" do
38
+ it "should return the associated stack for an environment" do
39
+ @config.stack("staging").should == "bamboo-ree-1.8.7"
40
+ end
41
+
42
+ it "should default to the all setting if not explicitly defined" do
43
+ @config.stack("production").should == "bamboo-mri-1.9.2"
44
+ end
45
+ end
46
+
47
+ describe "#config" do
48
+ context "staging environment" do
49
+ before(:each) do
50
+ @config = @config.config("staging")
51
+ end
52
+ it "should include configs defined in 'staging'" do
53
+ @config["STAGING_CONFIG"].should == "special-staging"
54
+ end
55
+
56
+ it "should include configs defined in 'all'" do
57
+ @config["BUNDLE_WITHOUT"].should == "test:development"
58
+ end
59
+
60
+ it "should use configs defined in 'staging' ahead of configs defined in 'all'" do
61
+ @config["CONFIG_VAR1"].should == "config1-staging"
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#collaborators" do
67
+ context "staging environment" do
68
+ before(:each) do
69
+ @collaborators = @config.collaborators('staging')
70
+ end
71
+
72
+ it "should include the collaborators defined in 'all'" do
73
+ @collaborators.should include('all-user1@somedomain.com')
74
+ @collaborators.should include('all-user2@somedomain.com')
75
+ @collaborators.should have(3).collaborators
76
+ end
77
+
78
+ it "should include collaborators defined in 'staging'" do
79
+ @collaborators.should include('staging-user@somedomain.com')
80
+ end
81
+
82
+ it "should not include collaborators defined in 'production'" do
83
+ @collaborators.should_not include('production-user@somedomain.com')
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "#domains" do
89
+ context "staging environment" do
90
+ before(:each) do
91
+ @domains = @config.domains('staging')
92
+ end
93
+
94
+ it "should include the domains defined in 'staging'" do
95
+ @domains.should include('staging.awesomeapp.com')
96
+ end
97
+
98
+ it "should not include the domains defined in 'production'" do
99
+ @domains.should_not include('awesomeapp.com')
100
+ @domains.should_not include('www.awesomeapp.com')
101
+ end
102
+ end
103
+
104
+ context "production environment" do
105
+ it "should include the domains defined in 'production'" do
106
+ @domains = @config.domains('production')
107
+ @domains.should include('awesomeapp.com')
108
+ @domains.should include('www.awesomeapp.com')
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "#addons" do
114
+ context "staging environment" do
115
+ before(:each) do
116
+ @addons = @config.addons('staging')
117
+ end
118
+
119
+ it "should include addons defined in 'all'" do
120
+ @addons.should include('custom_domains:basic')
121
+ @addons.should include('newrelic:bronze')
122
+ end
123
+
124
+ it "should not include addons defined in 'production'" do
125
+ @addons.should_not include('ssl:piggyback')
126
+ end
127
+ end
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1 @@
1
+ # needz moar test!
@@ -0,0 +1,18 @@
1
+ require 'heroku-rails'
2
+ require 'bundler/setup'
3
+
4
+
5
+ RSpec.configure do |c|
6
+ # setup fixtures path
7
+ c.before(:all) do
8
+ @fixture_path = Pathname.new(File.join(File.dirname(__FILE__), "/fixtures"))
9
+ raise "Fixture folder not found: #{@fixture_path}" unless @fixture_path.directory?
10
+ end
11
+
12
+ # returns the file path of a fixture setting file
13
+ def config_path(filename)
14
+ @fixture_path.join(filename)
15
+ end
16
+
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jw-heroku-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Whitmire
9
+ - Elijah Miller
10
+ - Glenn Roberts
11
+ - Jacques Crocker
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2013-03-18 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: heroku-api
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 0.3.8
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.8
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.9.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ version: 0.9.2
65
+ description: Manage multiple Heroku instances/apps for a single Rails app using Rake.
66
+ It's the Capistrano for Heroku, without the suck.
67
+ email: jeff@jwhitmire.com
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files:
71
+ - LICENSE
72
+ - README.md
73
+ - TODO
74
+ - CHANGELOG
75
+ files:
76
+ - lib/generators/heroku/config_generator.rb
77
+ - lib/generators/templates/heroku.rake
78
+ - lib/generators/templates/heroku.yml
79
+ - lib/heroku/rails/tasks.rb
80
+ - lib/heroku-rails/config.rb
81
+ - lib/heroku-rails/railtie.rb
82
+ - lib/heroku-rails/runner.rb
83
+ - lib/heroku-rails.rb
84
+ - spec/fixtures/heroku-config.yml
85
+ - spec/heroku/rails/heroku_config_spec.rb
86
+ - spec/heroku/rails/heroku_runner_spec.rb
87
+ - spec/spec_helper.rb
88
+ - heroku-rails.gemspec
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - CHANGELOG
92
+ - LICENSE
93
+ - Rakefile
94
+ - README.md
95
+ - TODO
96
+ homepage: http://github.com/jwhitmire/heroku-rails
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --charset=UTF-8
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -2821336418249926558
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -2821336418249926558
121
+ requirements: []
122
+ rubyforge_project: none
123
+ rubygems_version: 1.8.25
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Deployment and configuration tools for Heroku/Rails
127
+ test_files:
128
+ - spec/fixtures/heroku-config.yml
129
+ - spec/heroku/rails/heroku_config_spec.rb
130
+ - spec/heroku/rails/heroku_runner_spec.rb
131
+ - spec/spec_helper.rb