Set Up a Simple Deployment System
Understand heroku environments
Before deploy in production is always recommended to test everything first, probably you have a Test suit for test your application, but you never know want is going to happen when you deploy all changes to production. What people usually do is create a staging environment, that copies the production environment.
Basically you deploy first to staging and then test evrything, so after checking everything you may deploy to production with the confidence that everything works perfectly. Heroku as I said before is amazing it allow’s us to create multiple environments, Heroku provides us with many documentation to create our environments. Managing Multiple Environments for an App This post show us how to create different environments. The problem is if you have an existing App is not very clear how to do it, but I shall help you do it.
From our terminal, we must have Heroku Toolbelt installed, to allow us use the command line. Heroku has method call fork that will clone an existing app into another, you don’t need to create app the first, heroku will create the app and clone everything into this new app.
your-app-name with the actual name of your app and
your-app-name-staging with the name for the staging environment you want.
This process might take some time.
After that we must add a new remote to git so we can push to it.
Now we can push to staging
git push staging master
After that you may go a little further you can install a gem Paratrooper that help us with the deployment task.
The basic use of this gem is pretty simple we have to create a rake task inside our
lib/task folder call it
deploy.rake and place this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
With this file in our app we can call the different rake tasks
rake deploy:staging or
Inside the production task is
deploy.match_tag = 'staging'. This signifies that we only will push to production, what has been push to staging, this way we can not skip the staging part.