Roll your own Subversion server, SVN Setup

If you’re not familiar with SVN, Slicehost has a great Introduction to Subversion article which will bring you up to speed on the basics. It also has a whole subsection of Subversion articles which I highly recommend you read before continuing.

I’ll continue assuming you know how to do most of the stuff detailed in those guides. Specifically, we will deploy a svnserve instance listening on the default SVN port which will serve multiple repositories (not multiple projects) from a repository container in your home folder.

Install Subversion (and git!)

At this point, Subversion should already be installed on your system. If it’s not, this will take care of it:

sudo yum install subversion

Now while this tutorial might be about Subversion, Warehouse is hosted at GitHub and the easiest way to download it is via git so let’s install that right now too. Git lives under the EPEL repository we installed Nginx from so this simple command should do:

sudo yum install git

Create your repositories

Let’s begin by creating the folder to hold all of our repositories. We will also create a couple of test projects to get started. I will use the multiple repository type of layout where each project has its own repository. However, if you prefer something different, I’m sure you could easily adapt my guide to it.

From your home folder, run the following commands:

mkdir repositories
...
svnadmin create repositories/project1
svnadmin create repositories/project2

Now let’s create a template folder which we can use to create the standard repo layout in newly created repos:

mkdir -p repositories/svn_default/{trunk,branches,tags}

Import the default layout into our test repos:

svn import /home/demo/repositories/svn_default file:///home/demo/repositories/project1 -m "initial import"
...
svn import /home/demo/repositories/svn_default file:///home/demo/repositories/project2 -m "initial import"

Create some projects

Next create some dummy projects and import them into the repositories:

mkdir project1
touch project1/project1.txt
...
svn import /home/demo/project1 file:///home/demo/repositories/project1/trunk -m "app import"

mkdir project2
touch project2/project2.txt
...
svn import /home/demo/project2 file:///home/demo/repositories/project2/trunk -m "app import"

We now have two separate repositories to play with.

Clean up

Delete the original project folders as they are no longer needed

rm -rf project*

Initialize svnserve

Let’s setup svnserve to serve our repositories now. Be sure to read the Introduction to svnserve guide first and follow the instructions on opening up the firewall for svnserve access on port 3690. Now start svnserve with the following command:

svnserve -d -r /home/demo/repositories/

Autostart svnserve

To make svnserve start automatically, add the following to your crontab:

crontab -e

@reboot svnserve -d -r /home/demo/repository

Test it

Let’s check out one of our test projects on our computer and verify it is working correctly. On your local computer, run:

svn co svn://code.example.com/project1
...
A    project1/trunk
A    project1/trunk/project1.txt
A    project1/branches
A    project1/tags
Checked out revision 2.

Everything looks good! We have our trunk/branch/tag structure and the file we checked in earlier is in there.

Security

The default svnserve configuration files allow for anonymous read access and authenticated write access. This might work for you but I’d like to secure the install a bit. However, I’ll hold off on that until we finish setting up Warehouse which we will use to secure svnserve.

It is also important to note that svnserve stores passwords on the server in a plain-text. This is not as bad as it sounds as authentication is done using the CRAM-MD5 mechanism so the passwords are never sent in the clear. So unless someone has physical access to the server, your passwords are safe. Of course, this might not be enough security for some users so a future upgrade will be to move to an Apache HTTP svn server which allows you to store passwords in a hashed format. But for now, the standard svnserve configuration will serve us well.

End Notes

We have now finished initializing our repository home. Even without Warehouse, your server is fully functional as a simple SVN server. In the next part we will get Warehouse installed to make managing simpler to and to provide a front-end interface for our code repositories.

Tags: , , ,


blog comments powered by Disqus