public
Last active

  • Download Gist
heroku_deploy_tasks.rake
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
# =============================================================
# REQUIREMENTS
# =============================================================
# - Heroku toolbelt installed in your system
# - A heroku remote named `staging`.
# - A heroku remote named `production`.
# =============================================================
 
namespace :h do
# -------------------------------------------------------------
# DEPLOY
# -------------------------------------------------------------
# It deploys the current branch to heroku and runs the DB
# migrations.
# -------------------------------------------------------------
# rake h:deploy staging
# rake h:deploy production
desc 'Deploy the app'
task :deploy do
environment = ARGV.last
Bundler.with_clean_env { sh "heroku maintenance:on -r #{environment}" }
Bundler.with_clean_env { sh "git push #{environment} HEAD:master -f" }
Bundler.with_clean_env { sh "heroku run rake db:migrate -r #{environment}" }
Bundler.with_clean_env { sh "heroku restart -r #{environment}" }
Bundler.with_clean_env { sh "heroku maintenance:off -r #{environment}" }
task environment.to_sym do ; end
end
# -------------------------------------------------------------
# RESTART
# -------------------------------------------------------------
# rake h:restart staging
# rake h:restart production
desc 'Restart the app'
task :restart do
environment = ARGV.last
Bundler.with_clean_env { sh "heroku restart -r #{environment}" }
task environment.to_sym do ; end
end
 
# -------------------------------------------------------------
# LOGS
# -------------------------------------------------------------
# Run the logs in `tail` mode.
# -------------------------------------------------------------
# rake h:logs staging
# rake h:logs production
desc 'Tail the logs for the app'
task :logs do
environment = ARGV.last
Bundler.with_clean_env { sh "heroku logs -t -r #{environment}" }
task environment.to_sym do ; end
end
 
# -------------------------------------------------------------
# CLEAR THE CACHE
# -------------------------------------------------------------
# Runs the heroku console and executes a `Rails.cache.clear`
# command.
# -------------------------------------------------------------
# rake h:cache staging
# rake h:cache production
desc 'Clears the Rails cache for the app'
task :cache do
environment = ARGV.last
Bundler.with_clean_env { sh "heroku run rake h:clear_cache_task -r #{environment}" }
task environment.to_sym do ; end
end
 
task :clear_cache_task => :environment do
Rails.cache.clear
end
end

If you have to clear your cache on every deploy, you're doing something wrong.

@jelder yeah you're right, I added it for reference only, but you're totally right. I'm updating it.

Correct me if I'm wrong, but I believe you need to restart the app after running a database migration.

@dipth you're right. Otherwise you'll see forms that don't save. Thanks for the observation. I'm updating it again :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.