I don’t think there’s a quick way to figure out your first “real” Rails deployment process. Sure there’s Heroku (and now cloudControl, based here in Berlin) with magic one- or two-liner deployments. But they get expensive very quickly if you’re running more than a dev server. Your file system also remains fixed after deployment, so you will end up storing your user assets in yet another cloud service. So for now I am relying on a cheap VPS from Dreamhost. A little more complex but also more flexible, and I’m learning a lot.
Some background before getting started:
- Railscast: Deploying to a VPS
- Capistrano on Dreamhost (kinda dated, but useful)
- Syncing a git repository directly between your machine and Dreamhost. No GitHub!
I spent a good while figuring out a recipe to deploy a Rails app using Git with Capistrano on Dreamhost’s particular hosting setup. I felt compelled now to share some of the snags I hit, so hopefully I can save someone else out there from wasting a few hours.
A Capistrano recipe for Dreamhost
I’m assuming you set up Capistrano in your app. My config/deploy.rb ended up looking like this. Read through just to get a sense of how this works with Dreamhost. All-caps should be replaced with your own values:
If your git repo is in place, and you just want to deploy your damn shit from your local terminal, run cap deploy:setup just once before running cap deploy. Capistrano will be verbose about anything going wrong, so it won’t be a mystery to track down what the problem is, if you have one. Something probably will go wrong the first time.
More like than not, your asset pipeline won’t precompile properly through the Capistrano deployment. If you figured out the secret to that, let me know. So for now I SSH into my
/home/username/app/current folder and run
bundle exec rake:assets --precompile.
Set up your shared gems folder
You might also find your VPS environment needs customization to use gems shared across different Rails apps, and StackOverflow will be your friend there.
If you’re sharing gems, the most important thing you’ll need that’s specific to Dreamhost is this bit of code in the top of your
Passenger will also be vocal about what you’re missing if you try to access your newly deployed app from a web browser.