Quantcast
Channel: Web Architecture, Web Production, Web Marketing » Subversion
Viewing all articles
Browse latest Browse all 2

Using Subversion Part 2 – Auto Publish a Subversion commit

$
0
0

Subversion comes prebuilt with a system of “hooks”. Basically for most actions you would perform with a subversion repository you can also hook another program up to that action. For example you can tell subversion to also update a site locally on each commit.

The first step in this process is to make sure that your website as it exists on your dev server has been checked out from subversion and that permissions and ownership is set as you want it (that part’s up to you and outside the scope of this post). Let’s say I was working on the google site that was held in my repository in the “site” directory, I’d do something like:

svn checkout file:///home/google/repository/site/trunk/ webroot/

Now that a fresh checkout exists in the webroot, we’ll set things up to do an automatic subversion “update” on each commit.

From the subversion FAQ’s I found this handy chunk of C code.

#include
#include
#include
int main(void)
{
  execl("/usr/bin/svn", "svn", "update", "/path/to/site/webroot/",
        (const char *) NULL);
  return(EXIT_FAILURE);
}

The FAQ basically says that you take this chunk of code, add your own webroot path and compile it. If you’re like me and you compile C code once every year, or perhaps never, here’s the specifics on a Linux box. I use the gcc compiler and save the file as “update_site.c”

gcc update_site.c -o update_site

Not too complicated.

Now to preserve file permissions on your site properly, make sure that the owner of the website can execute this program from the svn hook but changing the mode of the compiled program to add the s switch.

chmod +s update_site

The last step is to tell subversion that it should run this update_site program after each commit. In your repository navigate to the hooks directory on the file system. Open up the file called post-commit.tmpl. There’s a couple example lines at the bottom of mine that execute python scripts for mailing and logging the commit, I just comment those out by putting a # in from of the lines and then on the last line of the file add the full path to the new update_site script. Like: /full/path/to/update_site

When you’re done, copy or move this post-commit.tmpl template to just post-commit and make sure that the webserver user can execute it.

With this process, you’re pretending that the webroot is the working directory for a subversion user. This means that the .svn directories normally in your working directory will now be present in the webroot as well. In case you have any passwords mixed in with you’re code, disable browsing of those directories in Apache. Thankfully this isn’t often an issue with ColdFusion datasources but it still doesn’t hurt to be safe.

Add the following to your apache httpd.conf file:

# Disallow browsing of Subversion working copy administrative dirs.

    Order deny,allow
    Deny from all

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images