glennr-heroku_san 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ doc
2
+ pkg
3
+ Thumbs.db
4
+ *.gemspec
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.0.1. Initial release.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Elijah Miller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,84 @@
1
+ = Heroku San
2
+
3
+ Helpful rake tasks for Heroku.
4
+
5
+ == Install
6
+
7
+ To install as a gem, add the following to config/environment.rb:
8
+
9
+ config.gem 'heroku_san'
10
+
11
+ Rake tasks are not automatically loaded from gems, so you’ll need to add the following to your Rakefile:
12
+
13
+ begin
14
+ require 'heroku_san/tasks'
15
+ rescue LoadError
16
+ STDERR.puts "Run `rake gems:install` to install heroku_san"
17
+ end
18
+
19
+ To install as a plugin:
20
+
21
+ script/plugin install git://github.com/glennr/heroku_san.git
22
+
23
+ == Configure
24
+
25
+ In config/heroku.yml you will need add the Heroku apps that you would like to attach to this project. Here is an example of an app called 'awesomeapp' with three Heroku apps attached.
26
+
27
+ apps:
28
+ # shorthand: heroku app
29
+ production: awesomeapp
30
+ staging: awesomeapp-staging
31
+ demo: awesomeapp-demo
32
+
33
+ == Usage
34
+
35
+ After configuring your Heroku apps you can use a rake tasks to control the
36
+ apps.
37
+
38
+ rake production deploy
39
+
40
+ A rake task with the shorthand name of each app is now available and adds that
41
+ server to the list that subsequent commands will execute on. Because this list
42
+ is additive, you can easily select which servers to run a command on
43
+
44
+ rake demo staging restart
45
+
46
+ A special rake task 'all' is created that causes any further commands to
47
+ execute on all heroku apps.
48
+
49
+ Manipulate collaborators on all this project's apps (prompts for email
50
+ address):
51
+
52
+ rake all heroku:share
53
+ rake all heroku:unshare
54
+
55
+ Need to add remotes for each app?
56
+
57
+ rake all heroku:remotes
58
+
59
+ A full list of tasks provided:
60
+
61
+ rake all # Select all Heroku apps for later command
62
+ rake console # Opens a remote console
63
+ rake deploy # Deploys, migrates and restarts latest code.
64
+ rake capture # Captures a bundle on Heroku
65
+ rake heroku:apps # Lists configured apps
66
+ rake heroku:create_config # Creates an example configuration file
67
+ rake heroku:gems # Generate the Heroku gems manifest from gem dependencies
68
+ rake heroku:remotes # Add git remotes for all apps in this project
69
+ rake heroku:rack_env # Add proper RACK_ENV to each application
70
+ rake heroku:share # Adds a collaborator
71
+ rake heroku:unshare # Removes a collaborator
72
+ rake migrate # Migrates and restarts remote servers
73
+ rake restart # Restarts remote servers
74
+
75
+ Frequently used tasks are not namespaced, everything else lives under heroku.
76
+
77
+ == Contributors
78
+
79
+ Glenn Roberts (glenn.roberts@siyelo.com)
80
+
81
+ == License
82
+
83
+ Homepage:: http://github.com/fastestforward/heroku_san
84
+ License:: Copyright (c) 2009 Elijah Miller <mailto:elijah.miller@gmail.com>, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "glennr-heroku_san"
7
+ gem.summary = %Q{A bunch of useful Rake tasks for managing your Heroku apps}
8
+ gem.description = %Q{Manage multiple Heroku instances/apps for a single Rails app using Rake}
9
+ gem.email = "glenn.roberts@siyelo.com"
10
+ gem.homepage = "http://github.com/glennr/heroku_san"
11
+ gem.authors = ["Elijah Miller", "Glenn Roberts"]
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
16
+ end
17
+
18
+ desc 'Default: build gem.'
19
+ task :default => :build
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - refactor config/helpers out of tasks.rb into own file(s)
2
+ -
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/install.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Install hook code here
2
+ system('rake heroku:create_config')
@@ -0,0 +1,198 @@
1
+ HEROKU_CONFIG_FILE = File.join(RAILS_ROOT, 'config', 'heroku.yml')
2
+
3
+ HEROKU_SETTINGS =
4
+ if File.exists?(HEROKU_CONFIG_FILE)
5
+ YAML.load_file(HEROKU_CONFIG_FILE)
6
+ else
7
+ {}
8
+ end
9
+
10
+ (HEROKU_SETTINGS['apps'] || []).each do |name, app|
11
+ desc "Select #{name} Heroku app for later commands"
12
+ task name do
13
+ @heroku_apps ||= []
14
+ @heroku_apps << name
15
+ end
16
+ end
17
+
18
+ desc 'Select all Heroku apps for later command'
19
+ task :all do
20
+ @heroku_apps = HEROKU_SETTINGS['apps'].keys
21
+ end
22
+
23
+ namespace :heroku do
24
+ desc "Generate the Heroku gems manifest from gem dependencies"
25
+ task :gems do
26
+ RAILS_ENV='production'
27
+ Rake::Task[:environment].invoke
28
+ list = []
29
+ if (RAILS_GEM_VERSION rescue false)
30
+ list << "rails --version #{RAILS_GEM_VERSION}\n"
31
+ else
32
+ list << "rails\n"
33
+ end
34
+ list << Rails.configuration.gems.reject{|g| g.frozen? && !g.framework_gem?}.map do |gem|
35
+ command, *options = gem.send(:install_command)
36
+ options.join(" ") + "\n"
37
+ end
38
+ File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f|
39
+ f.write(list)
40
+ end
41
+ puts ".gems has been updated with your application's gem dependencies."
42
+ end
43
+
44
+ desc 'Add git remotes for all apps in this project'
45
+ task :remotes do
46
+ each_heroku_app do |name, app, repo|
47
+ system("git remote add #{name} #{repo}")
48
+ end
49
+ end
50
+
51
+ desc 'Adds a collaborator'
52
+ task :share do
53
+ print "Email address of collaborator to add: "
54
+ $stdout.flush
55
+ email = $stdin.gets
56
+ each_heroku_app do |name, app, repo|
57
+ system_with_echo "heroku sharing:add --app #{app} #{email}"
58
+ end
59
+ end
60
+
61
+ desc 'Adds a collaborator'
62
+ task :unshare do
63
+ print "Email address of collaborator to remove: "
64
+ $stdout.flush
65
+ email = $stdin.gets
66
+ each_heroku_app do |name, app, repo|
67
+ system_with_echo "heroku sharing:remove --app #{app} #{email}"
68
+ end
69
+ end
70
+
71
+ desc 'Lists configured apps'
72
+ task :apps => :all do
73
+ each_heroku_app do |name, app, repo|
74
+ puts "#{name} is shorthand for the Heroku app #{app} located at:"
75
+ puts " #{repo}"
76
+ puts
77
+ end
78
+ end
79
+
80
+ desc 'Add proper RACK_ENV to each application'
81
+ task :rack_env => :all do
82
+ each_heroku_app do |name, app, repo|
83
+ command = "heroku config --app #{app}"
84
+ puts command
85
+ config = Hash[`#{command}`.scan(/^(.+?)\s*=>\s*(.+)$/)]
86
+ if config['RACK_ENV'] != name
87
+ system_with_echo "heroku config:add --app #{app} RACK_ENV=#{name}"
88
+ end
89
+ end
90
+ end
91
+
92
+ desc 'Creates an example configuration file'
93
+ task :create_config do
94
+ example = File.join(File.dirname(__FILE__), '..', 'templates', 'heroku.example.yml')
95
+ if File.exists?(HEROKU_CONFIG_FILE)
96
+ puts "config/heroku.yml already exists"
97
+ else
98
+ puts "Copied example config to config/heroku.yml"
99
+ FileUtils.cp(example, HEROKU_CONFIG_FILE)
100
+ system_with_echo("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
101
+ end
102
+ end
103
+ end
104
+
105
+ desc "Deploys, migrates and restarts latest code on Heroku"
106
+ task :deploy do
107
+ each_heroku_app do |name, app, repo|
108
+ branch = `git branch`.scan(/^\* (.*)\n/).to_s
109
+ if branch.present?
110
+ @git_push_arguments ||= []
111
+ system_with_echo "git push #{repo} #{@git_push_arguments.join(' ')} #{branch}:master && heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
112
+ else
113
+ puts "Unable to determine the current git branch, please checkout the branch you'd like to deploy"
114
+ exit(1)
115
+ end
116
+ end
117
+ end
118
+
119
+ desc "Force deploys, migrates and restarts latest code on Heroku"
120
+ task :force_deploy do
121
+ @git_push_arguments ||= []
122
+ @git_push_arguments << '--force'
123
+ Rake::Task[:deploy].execute
124
+ end
125
+
126
+ desc "Captures a bundle on Heroku"
127
+ task :capture do
128
+ each_heroku_app do |name, app, repo|
129
+ system_with_echo "heroku bundles:capture --app #{app}"
130
+ end
131
+ end
132
+
133
+ desc "Opens a remote heroku console"
134
+ task :console do
135
+ each_heroku_app do |name, app, repo|
136
+ system_with_echo "heroku console --app #{app}"
137
+ end
138
+ end
139
+
140
+ desc "Restarts remote heroku servers"
141
+ task :restart do
142
+ each_heroku_app do |name, app, repo|
143
+ system_with_echo "heroku restart --app #{app}"
144
+ end
145
+ end
146
+
147
+ desc "Migrates and restarts remote heroku servers"
148
+ task :migrate do
149
+ each_heroku_app do |name, app, repo|
150
+ system_with_echo "heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
151
+ end
152
+ end
153
+
154
+ namespace :db do
155
+ task :pull do
156
+ each_heroku_app do |name, app, repo|
157
+ system_with_echo "heroku pgdumps:capture --app #{app}"
158
+ dump = `heroku pgdumps --app #{app}`.split("\n").last.split(" ").first
159
+ system_with_echo "mkdir -p #{RAILS_ROOT}/db/dumps"
160
+ file = "#{RAILS_ROOT}/db/dumps/#{dump}.sql.gz"
161
+ url = `heroku pgdumps:url --app #{app} #{dump}`.chomp
162
+ system_with_echo "wget", url, "-O", file
163
+ system_with_echo "rake db:drop db:create"
164
+ system_with_echo "gunzip -c #{file} | #{RAILS_ROOT}/script/dbconsole"
165
+ system_with_echo "rake jobs:clear"
166
+ end
167
+ end
168
+ end
169
+
170
+ def system_with_echo(*args)
171
+ puts args.join(' ')
172
+ system(*args)
173
+ end
174
+
175
+ def each_heroku_app
176
+ if @heroku_apps.blank? && HEROKU_SETTINGS['apps'].size == 1
177
+ app = HEROKU_SETTINGS['apps'].keys.first
178
+ puts "Defaulting to #{app} app since only one app is defined"
179
+ @heroku_apps = [app]
180
+ end
181
+ if @heroku_apps.present?
182
+ @heroku_apps.each do |name|
183
+ app = HEROKU_SETTINGS['apps'][name]
184
+ yield(name, app, "git@heroku.com:#{app}.git")
185
+ end
186
+ puts
187
+ else
188
+ puts "You must first specify at least one Heroku app:
189
+ rake <app> [<app>] <command>
190
+ rake production restart
191
+ rake demo staging deploy"
192
+
193
+ puts "\nYou can use also command all Heroku apps for this project:
194
+ rake all heroku:share"
195
+
196
+ exit(1)
197
+ end
198
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'heroku_san', 'tasks'))
@@ -0,0 +1,5 @@
1
+ apps:
2
+ # shorthand: heroku app
3
+ production: awesomeapp
4
+ staging: awesomeapp-staging
5
+ demo: awesomeapp-demo
data/rails/init.rb ADDED
File without changes
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glennr-heroku_san
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Elijah Miller
14
+ - Glenn Roberts
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-07-12 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Manage multiple Heroku instances/apps for a single Rails app using Rake
24
+ email: glenn.roberts@siyelo.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - LICENSE
31
+ - README.rdoc
32
+ - TODO
33
+ files:
34
+ - .gitignore
35
+ - CHANGELOG
36
+ - LICENSE
37
+ - README.rdoc
38
+ - Rakefile
39
+ - TODO
40
+ - VERSION
41
+ - init.rb
42
+ - install.rb
43
+ - lib/heroku_san/tasks.rb
44
+ - lib/tasks/heroku.rake
45
+ - lib/templates/heroku.example.yml
46
+ - rails/init.rb
47
+ - uninstall.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/glennr/heroku_san
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: A bunch of useful Rake tasks for managing your Heroku apps
82
+ test_files: []
83
+