Capistrano series - alternative subversion setups
In the main Capistrano series, we set it up so that the main repository could only be access from the local workstation (so a deployment would checkout the repo to the workstation, zip it up, upload it and then unzip it).
This is great from a security point of view, but what if the subversion repository is on the same Slice as the application (as is the case with many people)?
local and remote
In the case of the subversion repository being on the same Slice as the application, there are two aspects to consider.
Firstly, as far as the local workstation is concerned, it will need SSH access to the repository so it can check in and out any changes.
Secondly, the Slice doesn't need SSH access, it just needs access to the repository as part of the Slice filesystem.
As these are quite different methods of accessing the same subversion repository, we will need to define the precise access methods and set which machine uses which method.
Deploy.rb
Let's go back to our old friend: deploy.rb.
At the moment (from the main Capistrano setup), it looks like this:
set :application, "domain1.com"
set :user, "demo"
set :repository, "svn+project1ssh://123.45.67.890/home/demo/repository/project1"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"
set :port, 30000
set :deploy_to, "/home/demo/public_html/#{application}"
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion
role :app, application
role :web, application
role :db, application , :primary => true
set :deploy_via, :copy
set :runner, user
after "deploy", "deploy:cleanup"
after "deploy:migrations", "deploy:cleanup"
Notice the repository setting at the top of the file. It sets out one access point to the repository (svn+ssh).
Later on, we set the deploy_via technique as copy.
Delete
Let's change those settings to reflect the need for the local workstation to access the repository via SSH and the Slice to access the repository via its own filesystem.
Start by deleting this line:
set :deploy_via, :copy
Secondly, to save confusion, simply delete the existing repository setting:
set :repository, "svn+project1ssh://123.45.67.890/home/demo/repository/project1"
Add
You may have noticed that I have mentioned the words 'local workstation' a few times already.
Well, there is a good reason for that. It may seem a little counter intuitive, but to set the way the local workstation access the remote repository (via SSH) we need to add this line:
set :local_repository, "svn+project1ssh://1223.45.67.890/home/demo/repository/project1"
So the 'local_repository' setting is how the local workstation accesses the remote repository.
To set how the Slice accesses its local filesystem we add this line:
set :repository, "file:///home/demo/repository/project1"
Keep in mind the difference between the two locations.
Done
That's it.
Now your deploy.rb file should look something like this:
set :application, "domain1.com"
set :user, "demo"
set :local_repository, "svn+project1ssh://123.45.67.890/home/demo/repository/project1"
set :repository, "file:///home/demo/repository/project1"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"
set :port, 30000
set :deploy_to, "/home/demo/public_html/#{application}"
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion
role :app, application
role :web, application
role :db, application , :primary => true
set :runner, user
after "deploy", "deploy:cleanup"
after "deploy:migrations", "deploy:cleanup"
Deploy
To deploy an application change is just the same as before.
On your local workstation, enter the command:
cap deploy
Capistrano will detail what it is doing and the important difference to note is this line at the beginning of the output:
* executing "svn checkout -q -r24 file:///home/demo/repository/project1 .............
You can see that the Slice is checking out the repository from the Slice file system.
Summary
Capistrano is very flexible when it comes to defining how you deploy your applications.
PickledOnion.


Article Comments:
Chris Prakoso commented Thu Jun 19 08:12:32 UTC 2008 ago:
Thanks for this write-up, just what I need for my setup.