mfournier91 / rails-deployment

[rails,heroku,deploy]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deployment

Learning Objectives

  • 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

Framing

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.

Questions?

Questions?

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.

Questions?

Resources

Cheat Sheet

Deployment Steps

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

To push changes to your app

$ 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.

To change your migrations

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

To switch your Heroku app's environment to development

$ heroku config:set RAILS_ENV=development

...and to change it back:

$ heroku config:set RAILS_ENV=production

Deleting apps

$ 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.

About

[rails,heroku,deploy]

License:Creative Commons Zero v1.0 Universal