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.
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.
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.
sudo gem update sudo gem update --system
will have rubygems and any installed gems at the latest version.
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://126.96.36.1990/home/demo/repository/project1
In my case, I was in a folder called 'dev' so now I have an empty folder called 'project1' in:
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:
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.
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.
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:
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.
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.