Deployment
Part 1: Launching Eileen Builds with Rails: Deployment with Capistrano, Unicorn, Nginx on Centos6
Note: I never did finish parts 2-4 for this blog post. I waited too long to write them and forgot how they worked. I've left this post up even though it's not really valid any longer. There are much better articles now on getting this running.
I'm going to do this post in four parts. Part 1: checklist things to do before deployment, Part 2 Capistrano, Part 3: Unicorn, and Part 4: Nginx. I also don't have the ability for draft posts set up yet, so...instead I'm publishing in parts so I don't need to write it all at once.
Launching this Rails app was not easy, although since I had never deployed an app, I wasn't expecting it to be easy. There are a bunch of little things you need to know about deployment if it's your first time that I think it would be helpful for other first-timers. Also, when you've been working on that web app for 24 hours straight you forget the all important mental checklist.
Please feel free to correct me to tell me I'm "doing it wrong" because this is my first deployment and I will fully admit I might have no idea what I'm doing.
Preparing Your App for Deployment
One thing I failed to do and I regret a lot is making sure certain files aren't include in git with my .gitignore
. Files to remove are:
- db/*sqlite3
- log/*.log
- public/assets* (now I did this because I wasn't using any public assets, and didn't want the rouge stylesheets being added)
- Gemfile.lock
Chances are if your app is running on sqlite3 in development it won't be in production and will more likely be using a MySQL database or PostgreSQL. My app is using MySQL so we'll go over setting up your Gemfile for that.
If you have just gem 'sqlite3' in your Gemfile you'll need to change it to what I have below. While here you'll probably want to add the gems needed for deployment as well.
Before deploying you'll need to precomile your assets with:
rake assets:precompile
This is really important because I forgot this step and could not figure out why my assets weren't showing up and I was getting a lot of "No Route Matches" in my logs. I didn't find this anywhere other were having this problem and no one said "hey maybe you forgot this really important thing."
Once capistrano is set up you can automate this task during deployment, but we'll cover that in Part 2.
When Parts 2-4 are written they will be linked to at the bottom of this post.