I have been developing DuZhe Text Analyzer using Ruby on Rails 3 (since it is my preferred method of developing backend for online applications) over the last month or so. Since this is longer than a 20-minute application, I decided to use a version control system, git. I intend to roll out features continuously so a good deployment strategy is very important for me. I decided to use Capistrano for no particular reason other than the flexibility it offers to deploying rails applications.

Finally, to run the Rails 3 app, I’m using Passenger (mod_rails) to execute the ruby code. I’ve chosen Passenger because it is the fastest option for executing Ruby apps offered by my web hosting provider.

Getting all 3 components to work together, unfortunately, was not trivial. It took a while to get it all to work because primarily there is not much documentation on generating a recipe for Capistrano that works with Rails 3.

Here is a step by step on how to get Ruby on Rails 3 deployed on Passenger-enabled servers with git and Capistrano.

1. Set Up Git Repository

I will not go into how to install git on the server and locally; that is for another tutorial. I recommend to make sure the git locally and remotely are of the same version or some unexpected bugs may arise.

First, make a copy of your project, just to be safe, then change directory to the project directory:

1

[localuser ~]$ cd projectdir

Now that we are in the right folder, let’s set up the project as a local git project. First, let’s look at all the steps and analyze them one by one:

1

2

3

4

[localuser projectdir]$ git init

[localuser projectdir]$ touch .gitignore

[localuser projectdir]$ git add .

[localuser projectdir]$ git commit

The first line tells git to initialize this folder as a repository. After it is done, we create an empty .gitignore file. This is where you can write what files to include from the repository. I’m leaving it blank for now. Next I let git know to add all the files in the directory to the local repository (note the “.” at the end; it can be replaced for specific files). Finally, I let git know to commit any changes (which in this case would be everything).

Now we need to switch over to the remote server and and set up a remote repository:

1

2

3

4

5

[localuser projectdir]$ ssh [remoteuser@]host

[remoteuser ~]$ mkdir projectdir.git

[remoteuser ~]$ cd projectdir.git

[remoteuser projectdir.git]$ git init --bare

[remoteuser projectdir]$ exit

First, we SSH into the remote server and create a new directory where we want the remote files to be stored. We initialize the directory as a barebones git repository, since there are no files there yet. Finally we return back to the local machine.

Next we are going to push our local repository to the remote host and set up some short cuts to make it easier in the future:

1

2

3

[localuser projectdir]$ git remote add origin ssh://[user@]host/~/projectdir.git

[localuser projectdir]$ git push origin master

[localuser projectdir]$ git branch --set-upstream master origin/master

In the first line we set up a short cut to push the repository to keyword: origin, rather than typing the address every single push. Next we push the previous commitment to the “origin” server under master branch. Finally, we set ... Lire la suite de l'article