description = "I've blogged before about deploying Rails applications. Normally I opt for using capistrano, but it turns out <code>git-deploy</code> is a light-weight, but worthy alternative."
slug = "deploying-with-git-deploy"
+++
I've blogged before about deploying Rails applications. Normally I opt for using capistrano, as it provides all the features I need and is pretty easy to customize if needed.
One of my previous strategies was to use capistrano to checkout a branch on a remote server, and `git fetch` that branch upon a new deployment.
The problem with capistrano, however, is that it can be quite slow from time to time. It also has a lot of features I never or only rarely use, like multi-host deployments.
A few days ago someone pointed out [git-deploy](https://github.com/mislav/git-deploy) to me. I tried it out and it is _fantastic_. Let me explain that.
After this, you should find the following files in `deploy/`:
*`after_push`
*`before_restart`
*`restart`
The filenames are self explanatory, but here's a quick run through:
**`after_push`**
This file is run after you've pushed your code to the remote server. It gathers some information about your changes, sets up the environment and kicks of the other two scripts.
**`before_restart`**
Before you can restart your server, you will probably need to update some things. By default git-deploy will check if it needs to run migrations, perform a `bundle install` and precompile your assets.
**`restart`**
Does exactly what it says, it will restart your Rails app. By default it's configured for Passenger, so it simply touches `tmp/restart.txt`.
## Server setup, RVM and Sidekiq
What follows is a step-by-step guide of how I setup a new server. In this case for a project using ruby-2.0 with RVM and Sidekiq for background processing.
**0. Set your RAILS_ENV**
I always declare `RAILS_ENV` en `/etc/environment`. This file gets loaded everywhere and saves you the headache of adding this env variable with every rails command you execute later.
I also set my editor here, so I'm not surprised by nano when doing `visudo` or `crontab -e`.
Just follow the instructions of the Passenger install script. Depending on your system configuration, you may be asked to add some (temporary) swap space.
Passenger will spit out three lines that you should add to the bottom of `/etc/apache2/apache2.conf`:
In order to use RVM and `rvmsudo` properly, we need to set that up in `deploy/after_push`. Add the following lines before the `run` commands at the bottom.
* You don't need the `git-deploy` gem installed to deploy your project.
* Keep your `deploy/` scripts up to date and under version control.
* Anyone with SSH access to your server can deploy the project.
## Conclusion
I think that capistrano is a fine tool, but for many projects it's overkill. `git-deploy` is light weight and easy to use and gets the job of deploying your app done quickly. It's also easily extendable, if you need it.
Give it a try. You can easily spin up a VPS over at [Digital Ocean](http://aj.gs/digitalocean) to play around or host your next awesome project. (Disclaimer: referral link). If you use Digital Ocean, you may also be interested in my iOS App: [Binary Deep](http://aj.gs/binary-deep).