Skip to content

Instantly share code, notes, and snippets.

@juandazapata
Last active January 2, 2016 09:39
Show Gist options
  • Save juandazapata/8284289 to your computer and use it in GitHub Desktop.
Save juandazapata/8284289 to your computer and use it in GitHub Desktop.
# =============================================================
# 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
@jboyens
Copy link

jboyens commented Jan 8, 2014

Why not just use Heroku San?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment