Created
August 13, 2013 16:48
-
-
Save rjacoby/6223116 to your computer and use it in GitHub Desktop.
Convoluted&fragile precompile&deploy script
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
namespace :deploy do | |
desc 'Deploy a particular tag' | |
task :tag, [:tag_name, :destination_remote] do |t, args| | |
main_branch = %x[git symbolic-ref HEAD 2>/dev/null].split('/').last.strip | |
tag_name = args[:tag_name] | |
destination_remote = args[:destination_remote] | |
destination_env = destination_remote.split('-').last | |
cached_assets = "tmp/assets-#{destination_env}" | |
puts "* Deploying tag #{tag_name} from main branch: #{main_branch} to #{destination_env}" | |
puts "* Creating temp branch from tag: #{tag_name}..." | |
puts '' | |
%x[git checkout #{tag_name}] | |
puts '' | |
puts "* Using local asset cache for speed" | |
%x[mv #{cached_assets} tmp/assets] | |
puts '' | |
puts "* Precompiling assets for rails environment '#{destination_env}'..." | |
%x[RAILS_ENV=#{destination_env} rake assets:precompile --trace] | |
puts '' | |
puts "* Committing assets to local copy of tag..." | |
%x[git add public/assets] | |
%x[git commit public/assets -m"tmp local checkin for deploy"] | |
puts '' | |
dummy_tag = %x[git rev-parse HEAD 2>/dev/null].strip | |
puts "* Deploying tag to Heroku with locally precompiled assets" | |
git_cmd = "git push #{destination_remote} #{dummy_tag}:master --force" | |
puts "* Doing: #{git_cmd}" | |
%x[#{git_cmd}] | |
puts '' | |
puts "* Moving the cache to avoid cross-env issues..." | |
%x[rm -rf #{cached_assets}] | |
%x[mv tmp/assets #{cached_assets}] | |
puts "* Switching back to your original main branch: #{main_branch}" | |
%x[git checkout #{main_branch}] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment