Created
December 13, 2012 03:14
-
-
Save anonymous/4273735 to your computer and use it in GitHub Desktop.
A Heroku app deploy rake file that automates asset syncing to S3 via the asset_sync gem by doing the asset compilation locally with the correct ENV vars for asset_sync.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RailsApplication | |
module Deploy | |
class << self | |
def run(*cmd) | |
system(*cmd) | |
raise "Command #{cmd.inspect} failed!" unless $?.success? | |
end | |
def deploy(app, branch = "master") | |
branch ||= "master" #in case it was passed as nil | |
puts "-----> Compiling Assets..." | |
heroku_env_vars = heroku_app_env_vars(app) | |
heroku_env_vars.each {|k, v| ENV[k] = v unless ENV[k].present?} | |
run "git checkout #{branch}" | |
Rake::Task["assets:precompile"].execute | |
run "git add public/assets" | |
run "git commit -m'deploy compiled assets'" | |
run "git push origin #{branch}" | |
puts "-----> Pushing..." | |
#run "git push git@github.com:RailsApplication/#{app}.git HEAD:master -f" | |
run "git push --force git@heroku.com:#{app}.git #{branch}:master" | |
puts "-----> Migrating..." | |
run "heroku run rake db:migrate --app #{app}" | |
puts "-----> Seeding..." | |
run "heroku run rake db:seed --app #{app}" | |
puts "-----> Restarting..." | |
run "heroku restart --app #{app}" | |
end | |
def heroku_app_env_vars(app) | |
heroku_env_vars_output = `heroku config -a #{app}` | |
heroku_env_vars_output_split = heroku_env_vars_output.split("\n") | |
heroku_env_var_lines = heroku_env_vars_output_split[1, heroku_env_vars_output_split.size] | |
heroku_env_vars = heroku_env_var_lines.inject({}) do |output, line| | |
match_data = line.match('([^:]+):(.*)') | |
output.merge match_data[1].strip => match_data[2].strip | |
end | |
end | |
end | |
end | |
end | |
desc "Deploy heroku app from branch (or master by default)" | |
task :deploy, [:app, :branch] => [:environment] do |t, args| | |
RailsApplication::Deploy.deploy(args[:app], args[:branch]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment