You need code changes deployed to the development and production servers faster? You’re using releases? Sometimes you need it faster? Then read on…
Recently I find myself more and more occupied debugging problems with Beanstalk releases functionality (Those of you using our support may have noticed). The main reason – FTP limitations. We have three daemons constantly uploading to customer servers, yet sometimes it takes an hour for the queue to reach the release. Even though our ftp client tries to act smart and do the so called ‘incremental’ uploads, it still means checking each file in the repository.
We have marked sitecopy for evaluation, somewhere in the backlog.
“It is slow”. I feel your pain.
Not only this – we have a time limit of 20 minutes per release attempt. After 20 minutes the process gives up and leaves deployment in an unfinished state, which apparently is not the smartest thing to do (By the way, we have a discussion right now – do you think that it is a good idea to send mail to the account owner in this case?). This time limit often is not enough to upload a large changeset, if the connection between the servers is slow. Currently, I have doubled it to 40 minutes, hoping that this will resolve some cases of large repositories (especially imported ones) not passing.
OK, enough grim pictures, on to a solution
But, first, let’s check if you have what it takes…
- A web server, accessible from the internet
- Shell access to it
- Subversion client installed on it
- (sigh) PHP. Of course, any language will do
We recently introduced a special integration called web hooks, very simple and versatile.
Ready? Set, go!
First of all, let’s checkout the project on the web server. Login using ssh, then
$: cd /var/www # or wherever you keep your project.
$: svn co https://myspace.svn.beanstalkapp.com/myrepo #prompted for pass and username. I would suggest that you use a read-only account.
$: ls /var/www/myrepo # The project should be here
Now, let’s install the web hook
Don’t expect something fancy, it is a 2-line script (initially it was one line, but I ran into troubles using system, and my PHP is very rusty.)
<?php
exec('/usr/bin/svn up /var/www/myrepo --username petyo --password ***** --no-auth-cache', $out);
print_r($out); // This is just to check if it works at all. And no, my password is not five asterisks.
?>
(You may double-check the path to the svn binary, using which svn)
Save this as PHP file, and put it somewhere visible from web. Try it by loading it in the browser – http://myserver.com/my-repo-hook.php. You should see a message like this:
Array ( [0] => At revision 9. )
Horray – you have set it up! There is a chance that exec and system are disabled through php.ini.
All that is left now is to specify the web hook. Go to https://myaccount.beanstalkapp.com/myrepo/integrations/web_hooks/setup (Setup > Integration > Web Hooks) and fill in the url of your web hook.
You’re done
This is it, in fact on every commit, Beanstalk will request the URL of your web hook, triggering svn update on the remote subversion copy.
Gotchas?
I can think of few, The most important thing is to check the permissions. The web hooks PHP file contains svn user and pass, so it is a good idea to set permissions just enough for the web server to execute it. Also, since the web server user (www-data, for example) will do the checkout, it is a good idea to chown the project root folder to it.
Disclaimer: This by no means comes to replace the releases functionality we already have, or serve as some sort of an excuse. Consider it more as a fun and alternative way to have your code changes propagated.


9 Comments
1 Trackbacks/Pingbacks
just wanted to say i love your service. its awesome. and you just gave me a great way to do updates to customers applications without ftp :)
trs21219 — February 11, 2009, 3:20 pm
Thanks! We love hearing feedback like this.
Chris Nagele — February 11, 2009, 7:09 pm
thanks for the example, this is exactly the kind of thing I will want to do should my client take my recommendation and use your service.
Ryan Stubblefield — February 18, 2009, 8:29 pm
is it possible to have it only do this when a specific part is updated? i have a dev branch and every time i commit to dev i dont want to commit to my clients websites. so is it possible to only call that when something is merged or committed with the trunk?
trs21219 — February 24, 2009, 2:31 pm
Of course. It is up to you to parse the yml posted to the web hook script, which provides information for the commit. If you need any help – please checkout the format described in the web hooks integration page itself, or contact us through http://support.wildbit.com.
Petyo Ivanov — February 24, 2009, 6:00 pm
Great job. thank you.
vps — June 6, 2009, 11:44 am
Petyo – thanks for this. Unfortunately we’d really like the Release functionality inside of Beanstalk. This webhook option bypasses the Release function and doesn’t give us any of that feature’s benefit.
What we really want is to SSH into our box and call a script. Then we can do all our real deployment on our side (db, java, etc) AND we get to use all of the Release functionality in Beanstalk.
Adam Wride — December 23, 2009, 1:48 pm
fyi – I have posted a similar request @ Beanstalk here: http://help.beanstalkapp.com/discussions/suggestions/68-scripting-for-release-functionality-inside-of-beanstalk Other Beanstalk users: if you are looking for this as well, please comment here =)
Adam Wride — December 23, 2009, 2:28 pm
Write a comment