- Define 'deployment', and contrast different methods of deploying an application
- Describe the difference between development, test, and production environments
- Deploy a rails application using heroku
- Run migrations on heroku
- Debug errors on heroku (using logs)
- Describe the major points of a
12-factor
application as applied to deployment - Use environment variables to keep sensitive data out of code
- List common pitfalls and their solutions when deploying to heroku
- Describe the role of the asset pipeline in rails
Deployment is the act of putting our app up on one or more servers connected to the internet, such that people can use our app.
I Teach: Rails Environments (10 / 10)
I Teach: Deployment (10 / 20)
We Do: Deploying to Heroku (30 / 50)
We're going to use Heroku to deploy our app, because it has a "free" pricing tier, and is very easy to get started with.
I Skim: Common Errors (10 / 60)
- Rails Asset Pipeline
- Getting Started Deploying Rails on Heroku
- The Twelve-Factor App
You may be wondering about the name of that gem... it's based on an idea called 'The Twelve-Factor App', which is a set of 12 principles that modern apps should follow so that they can be deployed on any provider, and can scale up easily (i.e. can grow as the userbase grows).
- Screencasts
The whole series of commands for deploying to Heroku is:
Add to the bottom of your Gemfile:
gem "rails_12factor", group: :production
$ bundle install
$ git add .
$ git commit -m "added 12factor"
$ heroku create my-sweet-app
# wait...
$ git push heroku master
# wait...
$ heroku run rake db:migrate
$ heroku run rake db:seed
$ heroku open
Then, to view your app's server log:
$ heroku logs -t
$ git add .
$ git commit -m "your message"
$ git push heroku master
Note that this will not update Github. If you want to push your changes to Github as well, you need to run git push origin master
as usual.
Do not edit an existing migration file. Instead:
$ rails g migration yourMigrationName
# Edit the new migration file
$ rake db:migrate
$ git add .
$ git commit -m "added migration"
$ git push heroku master
$ heroku run rake db:migrate
$ heroku config:set RAILS_ENV=development
...and to change it back:
$ heroku config:set RAILS_ENV=production
$ heroku apps:delete --confirm my-sweet-app
You're likely to end up with a bunch of Heroku apps. To delete all of them at once, you can add this function to your .bash_profile
:
function happ(){
for app in $(heroku apps)
do heroku apps:delete --confirm $app
done
}
...and then run happ
from anywhere on your computer.