deploying to heroku steps to remember
Deploying to Heroku can be a royal pain in the ass, or it can be easy. If you haven’t deployed in a while (or ever), you can forget some steps. Making it more of a pain. But for now, we can all remember together! I’m assuming you’ve already got that darned heroku toolbelt. Invisible toolbelts…
- Create a new Heroku App
Add git to your local reposity in the root directory (if you haven’t already) (only noobs wouldn’t have git init’d already)
terminal commands: git init git add . git commit -m 'this is the best app ever created in the future of the internets'
link your local repository to your heroku app
heroku git:remote -a [app_name]
Push your local app to heroku
git push heroku master
run a couple rails commands on your new heroku server.
heroku run rake db:schema:load
heroku run rake db:seed
One thing to note here: only run rake db:schema:load the first time you’re updating the database. Use rake db:migrate afterwards because rake db:schema:load will delete all production data.
now it’s time to test your app… pray it works, but it will most likely fail. And when it fails heroku won’t tell you ANYTHING about what’s wrong out of the box… So add some lines to production.rb and you can get more informative logs.
# add these lines to production.rb (after the do, before the end) logger = Logger.new(STDOUT) logger.level = 0 Rails.logger = Rails.application.config.logger = logger config.log_level = :info
Well, it’s time for another commit to heroku. Yep, every time you change something you gotta deploy it to heroku.
git add . git commit -m 'added heroku verbose logs' git push heroku master (wait 3-4 minutes for heroku to do its thing)
Let’s watch those logs for the errors!
heroku logs --tail
That’s the basics of deploying to git. But other things have also tripped me up in the past.
Other Errors and Recommendations that have tripped me up!
Rails provides you with a nice file called secrets.yml. But to use it for secrets, you’ll want to hide it from git if you’re hosting your code on a repository. BUT, heroku wants to use secrets.yml soooo you can’t actually use it for secrets. Introducing the github gem figaro, it will create a new file for all your secrets!
Postgres only… with Heroku
If you haven’t setup your app with postgres, you’ll need to edit a couple files to get it there. A quick google search should help. Otherwise start your app with the following line
rails new [app_name] --database=postgresql
That will get your app started with postgres for development and production.
Background Images Not Showing Up
RAWWWWR!!!! This one seems to trip me up every time. It all looked good on development! Now it’s looking… somewhat… empty in production. It’s simple. Just update one line in production.rb
config.assets.compile = false # to... config.assets.compile = true
And update your gemfile with the following gem
gem 'rails_12factor', group: :production
- Custom Domain
Remember to add your custom domain to your heroku app’s domain settings.
HEROKU AND SUSPENDERS, DON’T USE HEROKU DASHBOARD PROMOTE
Suspenders offers to create heroku and staging and production website – BUT THE PROBLEM IS WHEN WE PROMOTE VIA THE HEROKU DASHBOARD, IT WILL NOT RECOMPILE ASSETS. SO YOU CAN ADD THIS TO THE PROFILE
release: rake assets:precompile
But that doesn’t work because actually, heroku will NOT recreate the initial slug, so SOME assets will still use the
staging root url.
Basically, when deploying from staging to production, deploy directly to production from the command line when possible. Unless you figure out other methods.