Capistrano series - local setup and Capistrano

Well, we've nearly done the work needed on the Slice so now we can concentrate on setting up our local workstation and installing Capistrano.

Remember that the subversion repository will hold the application revisions and Capistrano will deploy any changes from our workstation to the Slice.


Workstation

I am using a Mac for my workstation. If you are using Linux then the procedure will be very similar.

However, if you are using Windows as your workstation OS, then you may have to install and configure extra packages so you can install Ruby on Rails and Capistrano.

I don't have any links for that so if anyone has any, I will add them to the article.

Versions

Try and make sure the versions of Ruby, rubygems, Rails and Capistrano are the same on both your Slice and your workstation.

This will solve many issues that can arise without actually doing anything.

Installing rubygems from source on both machines will alleviate many difficulties encountered when trying to match versions.

A simple:

sudo gem update
sudo gem update --system

will have rubygems and any installed gems at the latest version.

Check out

We can start by checking out project1 from the subversion repository (see this article for details of the subversion setup).

In your development directory (on your local workstation) issue the following command:

svn co svn+project1ssh://123.45.67.890/home/demo/repository/project1

In my case, I was in a folder called 'dev' so now I have an empty folder called 'project1' in:

/Users/onion/dev/

Rails

Now we have an empty project1 folder, let's fill it with the start of our project:

rails project1 -c

What's the '-c' option all about?

This automatically adds the created files to subversion (it doesn't commit the changes).

It's a great setting that you should get used to using, so when you add a controller or model, etc just add the '-c' tag.

OK, now move into the rails application:

cd project1

Subversion Priming

In a rails application, especially one that is active (such as when it is being developed), there are quite a few files that we don't want in the repository each time we commit a change.

The tmp and log directories are good examples of where superfluous files will reside - especially as these files can end up being several MB (or more) in size.

Luckily, this is easily dealt with by instructing subversion to ignore them in any commit.

Start by committing the changes (remember the changes were automatically added to subversion by our use of the '-c' flag):

svn commit -m "Initial commit of project"

We then tell subversion to ignore certain files with the propset setting:

svn propset svn:ignore "*" log/
svn propset svn:ignore "*" tmp/

You can, of course, ignore more files such as the database.yml file if that fits your needs better.

Then commit that change:

svn commit -m "added ignore to tmp and log"

The output is as follows:

Sending        log
Sending        tmp

Committed revision 2.

Excellent. We now have the project up and running, committed to subversion and ready to install Capistrano.

Capistrano install

Installing Capistrano is as simple as:

sudo gem install capistrano

Note I use the same syntax on my Mac as I use on my Slice - your workstation may need a slightly different command.

On my local machine, rubygems automatically installed the following dependencies:

needle-1.3.0
net-ssh-1.1.2
net-sftp-1.1.0

Quick check of the version:

cap -V

Capistrano v2.1.0

Good news. Capistrano is installed and ready to roll.

capify

Let's get right down to it and 'capify' our project.

Ensuring you are in your project folder (in my case /Users/onion/dev/project1), issue the following command:

capify .

Note the period (.) at the end of the command. This tells Capistrano to 'capify' the directory we are in.

The output is as follows:

[add] writing `./Capfile'
[add] writing `./config/deploy.rb'
[done] capified!

Huh. Bit of an anticlimax really.

Subversion add and commit

When we used the rails command to create the project we used the '-c' option to automatically add the files to subversion.

Capistrano doesn't have that option so we have two files we need to add. Let's have a look at them first:

svn status

?      Capfile
?      config/deploy.rb

That look correct so let's add them to subversion:

svn add Capfile 
A         Capfile

svn add config/deploy.rb 
A         config/deploy.rb

And finally commit the change:

svn commit -m "yay, I capified it..."

Now we are at revision 3.

Summary

This is a very exciting stage of our series:

  • We have the Slice setup and ready to serve the application.

  • We have our local machine setup with a svn controlled version of the application

  • We've setup subversion to ignore superfluous files

  • We've installed Capistrano and capified the project1 folder

Wow. A lot has happened so far but we still have a little way to go.

The next article will look at configuring Capistrano so we can enter a few commands to deploy the application.

Don't forget that we still need to configure a vhost for Nginx to serve the site, but once that is done, future deployments are just a command away.

PickledOnion.

Article Comments:

David Parker commented Wed Jan 30 04:10:25 UTC 2008:

Hello PickledOnion, great tutorials. I'm running into a bit of a snag. I'm trying to do run (from my local workstation): svn commit -m "initial commit"

and I get the error: Can't create directory '*/transactions/0-1.txn': Permission denied

I've followed just about every tutorial so far leading up to this one. My iptables looks like the one you created here: http://articles.slicehost.com/assets/2007/9/4/iptables.txt except I am using a different port, not 30000.

I also went through the SSH tutorial for SVN (works for checkout): http://articles.slicehost.com/2007/9/5/using-ssh-with-svnserve

I tried both with and without for this line in the iptables: -A INPUT -p tcp --dport 3690 -j ACCEPT

I don't really know where to go from here. Any ideas for me? Thanks.

PickledOnion commented Wed Jan 30 10:28:28 UTC 2008:

Hi David,

I don't understand the '*/transactions/0-1.txn' part of your post.

Where does the * come from? I've never seen that so am not sure where it comes from.

Anyway, if it works for checking the repo out, I wonder if you have svnserve running (if you are using SSH tunnels, then you do not need svnserve running).

If it is running, then you will need to set the permissions in the svnserve conf file.

I would ensure svnserve is not running (i.e. you don't need port 3690 running).

If you are going to use svnserve and not SSH tunnels then I am not sure how to do that as I only use SSH for my subversion repos and Capistrano.

Hope that helps.

PickledOnion

Charles Harvey commented Fri Feb 01 23:33:58 UTC 2008:

Hi David-

You may run svnadmin create as root and the tried to commit as a regular user such as demo.

Try deleting your repository using rm -r /whatever the name is on the server

than rerunning the svnadmin create as a your regular user such as demo

This should fix your problem.

Runar commented Sun Jun 22 21:32:50 UTC 2008:

If cap -V or capify doesn't work after installing the capistrano gem, try adding the following to the PATH variable:

PATH=$PATH:/var/lib/gems/1.8/bin

export PATH

or add /var/lib/gems/1.8/bin to the PATH variable in ~/.bashrc and run source ~/.bashrc to enable the path variable.

That helped me on Ubuntu 8.0.4 Hardy.

The entire article is here: http://ctrlshiftesc.wordpress.com/2008/01/09/capify-problems-help/

Charles Roper commented Fri Oct 03 06:35:44 UTC 2008:

Just a quick heads-up: the following do not work under Windows Vista:

svn propset svn:ignore "*" log/
svn propset svn:ignore "*" tmp/

More info about that can be found here and here.

jack commented Mon Jan 12 11:25:46 UTC 2009:

On Windows Vista here (dev machine), and I got Capistrano to install without any extra packages.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)