Creating Your Own Bazaar Server

By now we've all heard about the Bazaar (bzr) version control system. If you're a coder then you're well aware of what a version control system is and why it's helpful. If you code on Launchpad you're equally aware how incredibly awesome this system is.

Rather than discuss how incredible bazaar is, I'd like to explain how to set up a production level deployment for a bzr server. If you're curious what makes bazaar great, just try it out. You can use https://staging.launchpad.net/ to create branches for playing around.

To deploy a low level and basic setup you only need to run this command on your server:
sudo aptitude install openssh-server bzr

That's really all there is to it. You can now push an existing code branch to your server using the following command:
bzr push bzr+ssh://yourserver.com/~/branch

That's only a basic deployment. What I like doing is having branches where multiple people can work on the same branch. This first thing I do is create a directory that this whole thing will be based in. I like to do this on its own partition for obvious reasons. For me this always exists at /bazaar. I then use the following:

# Get into the branch directory
cd /bazaar
# Create a directory for branch content
mkdir bzr
# Make a nice short directory name to this
cd /
ln -s /bazaar/bzr

Now anyone with the right permissions (root) can push to the server using bzr push bzr+ssh://yourserver.com/bzr/branch. However, we don't want to give everyone root access. Instead of doing this, I issue the following:

# Create a generic bzr group
groupadd bzr
# Assign group to branches
chown root:bzr /bazaar/bzr

Now anyone in the bzr group can push to this. However, we're working in teams of users. The user that makes the commit will be the only one that can manage this branch. I guess it's time to learn about the "sticky bit." This little bit allows us to retain the group that owns the directory. The sticky bit doesn't seem to like retaining the owner but that becomes irrelevant because it's the groups we care about.

# Set generic permissions
chmod 770 /bazaar/bzr
# Set the sticky bit
chmod +s /bazaar/bzr

Now it's time to give a user permission to work with these branches.
usermod -a -G bzr username

You should be ready to rock now. If you create a branch and decide that only a handful of users should be able to access it, this is easy. Something could be a highly secret piece of code that is the "bread and butter" to a massive project you are undertaking.

# Create new group
groupadd bzr-special
# Set permissions on branch
chown -R root:bzr-special /bzr/branch
# Add users to the special group
usermod -a -G bzr-special username

Heck Ya! That was easy enough wasn't it? It really is once you've gone through the hassle of picking out these little things. It's actually amazingly easy if you have a guide. I wasn't able to find this guide and I hope this will help others trying to do the same thing.

What's next? I'd suggest pulling the loggerhead source and setting it up. This is a great tool for seeing revision changes. I'd like to see a way to send an email diff on branch changes but this may be too hard without created a chopped down version of Launchpad.

General: 
Ubuntu: 

Submitted by amanica on Mon, 11/02/2009 - 04:01

You mentioned: "I'd like to see a way to send an email diff on branch changes"
Maybe this plugin will do the trick for you:
http://doc.bazaar-vcs.org/plugins/en/email-plugin.html

Thanks for this great post, we should try to get it into the official documentation.

Submitted by AstroFloyd (not verified) on Sun, 12/18/2011 - 03:29

Nice, thanks - I'm going to give it a try.

One comment - chmod +s sets the setuid/setgid permissions, not the sticky bit (e.g. http://en.wikipedia.org/wiki/Setuid).

Submitted by Serrano Pereira (not verified) on Wed, 03/28/2012 - 17:25

Thanks Michael for the article. It was very helpful.

AstroFloyd's comment about the sticky bit is indeed correct. The command "chmod +s" does NOT set the sticky bit. But the usage of "chmod +s" is correct in this article. As described on the Wikipedia page:

"The setuid and setgid flags, when set on a directory, have an entirely different meaning. Setting the setgid permission on a directory (chmod g+s) causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner ID is never affected, only the group ID)".

Which is exactly what we want in this case. I was confused at first because "chmod +s" has a very different meaning when applied to an executable. I hope this clears things up for other people who run into the same issue.

Submitted by Scott Murphy (not verified) on Wed, 02/29/2012 - 07:31

First time you type: bzr push ssh+bzr://yourserver.com/~/branch
I had to type: bzr push bzr+ssh://yourserver.com/~/branch

To make it work.

Submitted by michael on Mon, 03/05/2012 - 21:48

Thanks, I corrected that.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.
2011 © Michael Lustfield