Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial release.

  • Loading branch information...
commit 910b14813b693feac9ef36aa6a4530f78e3dcc28 0 parents
@jqr jqr authored
3  .gitignore
@@ -0,0 +1,3 @@
+doc
+pkg
+Thumbs.db
1  CHANGELOG
@@ -0,0 +1 @@
+v0.0.1. Initial release.
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Elijah Miller
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 README.rdoc
@@ -0,0 +1,64 @@
+= Heroku San
+
+Helpful stuffs for Heroku.
+
+== Install
+
+ script/plugin install git://github.com/fastestforward/heroku_san.git
+
+Upon installation your $EDITOR will be opened for editing 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.
+
+ apps:
+ # shorthand: heroku app
+ production: awesomeapp
+ staging: awesomeapp-staging
+ demo: awesomeapp-demo
+
+== Usage
+
+After configuring your Heroku apps you can use a rake tasks to control the
+apps.
+
+ rake production deploy
+
+A rake task with the shorthand name of each app is now available and adds that
+server to the list that subsequent commands will execute on. Because this list
+is additive, you can easily select which servers to run a command on
+
+ rake demo staging restart
+
+A special rake task 'all' is created that causes any further commands to
+execute on all heroku apps.
+
+Manipulate collaborators on all this project's apps (prompts for email
+address):
+
+ rake all heroku:share
+ rake all sharing:unshare
+
+Need to add remotes for each app?
+
+ rake all heroku:remotes
+
+A full list of tasks provided:
+
+ rake all # Select all Heroku apps for later command
+ rake console # Opens a remote console
+ rake deploy # Deploys, migrates and restarts latest code.
+ rake heroku:apps # Lists configured apps
+ rake heroku:create_config # Creates an example configuration file
+ rake heroku:gems # Generate the Heroku gems manifest from gem dependencies
+ rake heroku:remotes # Add git remotes for all apps in this project
+ rake heroku:share # Adds a collaborator
+ rake heroku:unshare # Removes a collaborator
+ rake migrate # Migrates and restarts remote servers
+ rake restart # Restarts remote servers
+
+Frequently used tasks are not namespaced, everything else lives under heroku.
+
+
+Homepage:: http://github.com/fastestforward/heroku_san
+License:: Copyright (c) 2008 Elijah Miller <mailto:elijah.miller@gmail.com>, released under the MIT license.
1  init.rb
@@ -0,0 +1 @@
+system('rake heroku:create_config')
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
145 lib/tasks/heroku.rake
@@ -0,0 +1,145 @@
+HEROKU_CONFIG_FILE = File.join(RAILS_ROOT, 'config', 'heroku.yml')
+
+HEROKU_SETTINGS =
+ if File.exists?(HEROKU_CONFIG_FILE)
+ YAML.load_file(HEROKU_CONFIG_FILE)
+ else
+ {}
+ end
+
+(HEROKU_SETTINGS['apps'] || []).each do |name, app|
+ desc "Select #{name} Heroku app for later commands"
+ task name do
+ @heroku_apps ||= []
+ @heroku_apps << name
+ end
+end
+
+desc 'Select all Heroku apps for later command'
+task :all do
+ @heroku_apps = HEROKU_SETTINGS['apps'].keys
+end
+
+namespace :heroku do
+ desc "Generate the Heroku gems manifest from gem dependencies"
+ task :gems do
+ RAILS_ENV='production'
+ Rake::Task[:environment].invoke
+ list = Rails.configuration.gems.collect do |g|
+ command, *options = g.send(:install_command)
+ options.join(" ") + "\n"
+ end
+
+ File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f|
+ f.write(list)
+ end
+ end
+
+ desc 'Add git remotes for all apps in this project'
+ task :remotes do
+ each_heroku_app do |name, app, repo|
+ system("git remote add #{name} #{repo}")
+ end
+ end
+
+ desc 'Adds a collaborator'
+ task :share do
+ print "Email address of collaborator to add: "
+ $stdout.flush
+ email = $stdin.gets
+ each_heroku_app do |name, app, repo|
+ system_with_echo "heroku sharing:add --app #{app} #{email}"
+ end
+ end
+
+ desc 'Adds a collaborator'
+ task :unshare do
+ print "Email address of collaborator to remove: "
+ $stdout.flush
+ email = $stdin.gets
+ each_heroku_app do |name, app, repo|
+ system_with_echo "heroku sharing:remove --app #{app} #{email}"
+ end
+ end
+
+ desc 'Lists configured apps'
+ task :apps => :all do
+ each_heroku_app do |name, app, repo|
+ puts "#{name} is shorthand for the Heroku app #{app} located at:"
+ puts " #{repo}"
+ puts
+ end
+ end
+
+ desc 'Creates an example configuration file'
+ task :create_config do
+ example = File.join(File.dirname(__FILE__), '..', 'templates', 'heroku.example.yml')
+ if File.exists?(HEROKU_CONFIG_FILE)
+ puts "config/heroku.yml already exists"
+ else
+ puts "Copied example config to config/heroku.yml"
+ FileUtils.cp(example, HEROKU_CONFIG_FILE)
+ system_with_echo("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
+ end
+ end
+end
+
+desc "Deploys, migrates and restarts latest code"
+task :deploy do
+ each_heroku_app do |name, app, repo|
+ branch = `git branch`.scan(/^\* (.*)\n/).to_s
+ if branch.present?
+ system_with_echo "git push #{repo} #{branch} && heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
+ else
+ puts "Unable to determine the current git branch, please checkout the branch you'd like to deploy"
+ exit(1)
+ end
+ end
+end
+
+desc "Opens a remote console"
+task :console do
+ each_heroku_app do |name, app, repo|
+ system_with_echo "heroku console --app #{app}"
+ end
+end
+
+desc "Restarts remote servers"
+task :restart do
+ each_heroku_app do |name, app, repo|
+ system_with_echo "heroku restart --app #{app}"
+ end
+end
+
+desc "Migrates and restarts remote servers"
+task :migrate do
+ each_heroku_app do |name, app, repo|
+ system_with_echo "heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
+ end
+end
+
+
+def system_with_echo(*args)
+ puts args.join(' ')
+ system(*args)
+end
+
+def each_heroku_app
+ if @heroku_apps.present?
+ @heroku_apps.each do |name|
+ app = HEROKU_SETTINGS['apps'][name]
+ yield(name, app, "git@heroku.com:#{app}.git")
+ end
+ puts
+ else
+ puts "You must first specify at least one Heroku app:
+ rake <app> [<app>] <command>
+ rake production restart
+ rake demo staging deploy"
+
+ puts "\nYou can use also command all Heroku apps for this project:
+ rake all heroku:share"
+
+ exit(1)
+ end
+end
5 lib/templates/heroku.example.yml
@@ -0,0 +1,5 @@
+apps:
+ # shorthand: heroku app
+ production: awesomeapp
+ staging: awesomeapp-staging
+ demo: awesomeapp-demo
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.