Simplify your Heroku deploy with quick and concise deployment rake tasks.
Add this line to your application's Gemfile:
and then execute
install it yourself with
gem install paratrooper
Instantiate Paratrooper with the name of your heroku application.
You can also provide a tag:
::.('amazing-app', tag: 'staging')
::.('amazing-app') do |deploy| deploy.tag = 'staging' end
You can authenticate your Heroku account in a few ways:
- Provide an API Key
::.('app', api_key: 'API_KEY')
- Set an environment variable
ENV['HEROKU_API_KEY'] = 'API_KEY' ::.('app')
- Local Netrc file
This method works via a local Netrc file handled via the Heroku Toolbelt and is the default and preferred method for providing authentication keys.
Git SSH key configuration
If you use multiple SSH keys for managing multiple accounts, for example in your
.ssh/config, you can set the
::.('app', deployment_host: 'HOST')
::.('amazing-app') do |deploy| deploy.deployment_host = 'HOST' end
This also works if you're using the heroku-accounts plugin:
::.('app', deployment_host: 'heroku.ACCOUNT_NAME')
By providing tag options for Paratrooper, your code can be tagged and deployed from various reference points.
::.("staging-app", tag: 'staging')
This will create/update a
staging git tag at
::.("amazing-production-app", tag: 'production', match_tag: 'staging' )
::.('amazing-production-app') do |deploy| deploy.tag = 'production' deploy.match_tag = 'staging' end
This will create/update a
production git tag at
staging and deploy the
Sensible Default Deployment
You can use the object's methods any way you'd like, but we've provided a sensible default at
This will perform the following tasks:
- Create or update a git tag (if provided)
- Push changes to Heroku
- Run database migrations if any have been added to db/migrate
- Restart the application
- Warm application instance
require 'paratrooper' namespace :deploy do desc 'Deploy app in staging environment' task :staging do deployment = ::.("amazing-staging-app", tag: 'staging') deployment.deploy end desc 'Deploy app in production environment' task :production do deployment = ::.("amazing-production-app") do |deploy| deploy.tag = 'production' deploy.match_tag = 'staging' end deployment.deploy end end
Bucking the Norm
Our default deploy gets us most of the way, but maybe it's not for you--we've got you covered. Every deployment method has a set of callback instructions that can be utilized in almost any way you can imagine.
add_callback method allows for the execution of arbitrary code within different steps of the deploy process.
There are 'before' and 'after' hooks for each of the following:
For example, say you want to let New Relic know that you are deploying and to disable your application monitoring.
# lib/tasks/deploy.rake namespace :deploy do desc 'Deploy app in production environment' task :production do deployment = ::.("amazing-production-app") do |deploy| deploy.tag = 'production' deploy.match_tag = 'staging' deploy.add_callback(:before_setup) do |output| output.display("Totally going to turn off newrelic") system %Q[curl https://rpm.newrelic.com/accounts/ACCOUNT_ID/applications/APPLICATION_ID/ping_targets/disable -X POST -H "X-Api-Key: API_KEY"] end deploy.add_callback(:after_teardown) do |output| system %Q[curl https://rpm.newrelic.com/accounts/ACCOUNT_ID/applications/APPLICATION_ID/ping_targets/enable -X POST -H "X-Api-Key: API_KEY"] output.display("Aaaannnd we're back") end end deployment.deploy end end
Or maybe you just want to run a rake task on your application. Since this task may take a moment to complete it's probably a good idea to throw up a maintenance page.
# lib/tasks/deploy.rake namespace :deploy do desc 'Deploy app in production environment' task :production do deployment = ::.("amazing-production-app") do |deploy| deploy.maintenance = true deploy.add_callback(:after_teardown) do |output| output.display("Running some task that needs to run") deploy.add_remote_task("rake some:task:to:run") end end deployment.deploy end end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature).
- Commit your changes (
git commit -am 'Add some feature').
- Push to the branch (
git push origin my-new-feature).
- Create new Pull Request.
- Rye Mason for the fantastic heading image.