Sunday, June 27, 2010

Supporting environment-specific configuration organization-wide

Here's a question I posted over at stackoverflow recently. It hasn't generated a lot of commentary, unfortunately, but I'm going to keep working on it. This problem is sure to be the source of future posts.

Problem


Your organization has many separate applications, some of which interact with each other (to form "systems"). You need to deploy these applications to separate environments to facilitate staged testing (for example, DEV, QA, UAT, PROD). A given application needs to be configured slightly differently in each environment (each environment has a separate database, for example). You want this re-configuration to be handled by some sort of automated mechanism so that your release managers don't have to manually configure each application every time it is deployed to a different environment.

Desired Features


I would like to design an organization-wide configuration solution with the following properties (ideally):
  • Supports "one click" deployments (only the environment needs to be specified, and no manual re-configuration during/after deployment should be necessary).
  • There should be a single "system of record" where a shared environment-dependent property is specified (such as a database connection string that is shared by many applications).
  • Supports re-configuration of deployed applications (in the event that an environment-specific property needs to change), ideally without requiring a re-deployment of the application.
  • Allows an application to be run on the same machine, but in different environments (run a PROD instance and a DEV instance simultaneously).

Possible Solutions


I see two basic directions in which a solution could go:
  1. Make all applications "environment aware". You would pass the environment name (DEV, QA, etc) at the command line to the app, and then the app is "smart" enough to figure out the environment-specific configuration values at run-time. The app could fetch the values from flat files deployed along with the app, or from a central configuration service
  2. Applications are not "smart" as they are in #1, and simply fetch configuration by property name from config files deployed with the app. The values of these properties are injected into the config files at deploy-time by the install program/script. That install script takes the environment name and fetches all relevant configuration values from a central configuration service.

Question


How would/have you achieved a configuration solution that solves these problems and supports these desired features? Am I on target with the two possible solutions? Do you have a preference between those solutions? Also, please feel free to tell me that I'm thinking about the problem all wrong. Any feedback would be greatly appreciated.

Thursday, May 20, 2010

MSBuild is strange sometimes...

So I've finally gotten around to creating a profile at http://stackoverflow.com/, because I've run into an issue that warranted posting. FWIW, I'm also trying out MS Connect on this issue. You should refer to those links for a full synopsis of what's going on. But, suffice it to say, I've managed to create a situation where MSBuild behaves differently if I:
  • Run MSBuild against a solution file via the "Exec" task in an MSBuild script
  • Run MSBuild against a solution file via the "MSBuild" task in an MSBuild script

Interestingly enough, I've also found that if I first run the build using the "Exec" task, and THEN using the "MSBuild" task, all is well. But if I try to run using the "MSBuild" task a second (or third, or fourth, etc.) time, it fails. Very odd indeed.

Now, I am typically a fan of MSBuild. I like how it comes for free with the framework (so it's not an additional environmental dependency). I generally like how it is simple to define build workflows with it. But, occasionally, I run into a fun little bug/feature like this that drives me insane (and destroys my productivity) for a day or two. Oh well.

Thursday, March 4, 2010

What's in a Build System?

The term "build system" seems rather nebulous. Is it your build machine? Your continuous integration server? Your makefiles or project files? In my adventures, I've decided to give a specific definition to the term. For what it's worth, I'll give it a public showing here.
The build system takes source code (and possibly other resources) as input and produces a deployable artifact (or possibly multiple deployable artifacts) as output.
While the term "deployable artifact" is almost self-explanatory, I don't think it's obvious. To me, a "deployable artifact" is the set of binaries (and other resources) that can actually be installed on a production machine, or shipped to a client, and run successfully. The "deployable artifact" could be an installer program (like an msi), a set of libraries (dlls, jars, etc), or a SQL change script. It could be something totally different -- it is simply the product in its "deployable" state.

Under this definition, a makefile or project file is actually the closest thing to a "build system" that we identified earlier. However, we often want to do more than just compiling as a part of our "build". For example, in a production "build system", we might want to:
  • Update version numbers
  • Run unit tests and possibly functional tests
  • Perform style or coverage analysis
  • Coalesce the output of several projects into a single artifact
  • Publish the artifact(s) to a publicly accessible location
To make things more interesting, you probably want to do a lot of these things roughly the same way across multiple products within your organization. One-off makefiles and post-build steps in project files won't scale up to the challenge. Most organizations end up with some sort of "standard" build system, typically using one of the scripting systems designed for this kind of thing. Ant/NAnt, MSBuild, and Rake are popular options.

Since you're probably going to end up building one of these "standard" build systems, why not do it well? There are a few key properties that I believe a well executed build system should have:

1) The build system should have very few environmental dependencies

Your build system should ideally require that nothing be installed on the system other than the scripting language in which it is written. Even better, the scripting language could come along with the platform, like MSBuild (which installs with the .NET framework). If your build system makes use of third party script libraries (it probably will), you should deploy those along with your build system. If your build system uses a particular unit test runner, deploy it with your build system. Strive to place as few requirements as possible on the environment in which your system runs.

2) The build system should not be dependent on a particular continuous integration server

It's very tempting to conflate the notions of "build system" and "build server". However, that would be a violation of our first property. Every aspect of the build system should be runnable anywhere. That includes version numbering, unit test execution, and deployable package creation. Resist the urge to use your continuous integration server to define a compile, test, package workflow and implement it in the build system instead (CruiseControl.NET explicitly discourages you from using their NUnit task). You will thank me for this the first time you need to debug the way your CI server is running the unit tests for a particular product. In fact, I don't really like the term "production build system" -- developers should be executing the build system against their project, on their local machines, all the time. Plus, if you follow this principle, you'll be able to very easily change out your CI server if you find a better one.

3) The build system should make it very easy to follow standard conventions

The build system itself is a product that is used by your organization's developers. With that in mind, it should be designed for ease of use. It should come pre-packaged with subroutines that handle common build tasks your developers need. It should give them a version numbering convention for free. It should automatically find their unit tests and execute them. The build system is a software product; it needs to be easy (dare I say enjoyable?) to use.

4) The build system should be extensible and flexible

This is seemingly the opposite of property 3, but I believe that they can happily co-exist. Your build system should be an extensible platform that allows your developers to tweak it to do "non-standard" things if they need to. Implementing your build system as a suite of scripts in a well-known scripting language is an important first step, as this allows your developers to add new components or rewrite existing components if they need to. Beyond this, however, your build system should itself be pluggable and extensible, allowing users to swap out one element while keeping the others, inject an extra step, or reorder the workflow.

If you take the time to create a build system that satisfies these properties, you will have significantly reduced the friction of setting up a new project or altering an existing build. You'll make it easy to automate all your builds in a standard way and set up a CI server to consume build output. You'll make the world a little bit more efficient.

Monday, February 22, 2010

Continuous Integration as Positive Reinforcement

The primary goal of continuous integration is to provide a nice binary "health" metric for your project. "Red" vs. "Green"; "Broken" vs. "Fixed". The idea is that developers expect their build to be green, and if it goes red, they spring into action to fix it as soon as possible.

I agree that this is the first-order value added by continuous integration. However, when your build is green, CI can provide very useful information about just how green your project really is. How many tests passed? What's the code coverage? Are there any style issues? If you take the time to hook up tools that generate this data to your build process and get your CI server to display the results, you can get near-real-time feedback on not just the "red/green" status of your project, but the exact shade of green.

Having this detailed "health" data conspicuously displayed on your CI server's interface provides positive reinforcement for improving the metrics. Only 10 unit tests for the entire project? Maybe I'll take a few minutes and add some. CruiseControl.NET does a lovely job providing this reinforcement because, out of the box, it gives you a graph of tests passed over time, so you can see your test total go up and up as you add more.

I know that this works from personal experience. I love seeing the test numbers go up in my build reports -- it's a very concrete metric documenting progress, something that is quite rare in programming. I've also seen this happen with co-workers, who, upon seeing test data show up in CruiseControl.NET, spent a Friday afternoon adding tests. And that, to steal a phrase, is a good thing.

Tuesday, February 9, 2010

Implementing Binary Publishing With Subversion

The basic concept of "binary publishing" is to have an automated system that publishes build artifacts (binaries, like dlls or object files) back into source control so that they can then be referenced in another (downstream) project. This gives your developers the opportunity to easily share binaries, as opposed to needing to share code. This can be desirable if you are trying to to reduce coupling between internal components, or if your monolithic builds are getting too large to be manageable.

To implement binary publishing, you need a source control system that supports some sort of "symbolic link" syntax, where checking out project X automatically checks out dependency Y, because the "symbolic link" to dependency Y is defined on project X itself. Subversion's externals syntax does the trick (I believe that git's submodules can do the same thing, but I haven't tried it myself).

In addition, you need an automated mechanism for committing to the repository. Effectively, to "publish" build artifacts to a binary repository, we want to make the "HEAD" (to use the subversion term for the current revision of the repository) look exactly like the unversioned directory filled with build artifacts that our build process generated. In subversion, this is trickier than it should be out-of-the-box, because you need to first determine what has been added and deleted, and then apply the requisite "svn" commands to make those changes commit-able (subversion is optimized for the "working copy" scenario, where you interact with a working copy that can track your changes, as opposed to this scenario where our work is done in an unversioned directory, and then we wish to apply the "changes" to the repository in one step). Luckily, the subversion developers have already implemented this functionality for us, via the somewhat hard-to-find svn_load_dirs.pl script. To actually get the script, you need to go directly to subversion's subversion repository, as it is not included with the binary distributions. To get this working properly on Windows, the script required a few modifications, which I will describe in a later post.

By wiring svn_load_dirs.pl into your build process, you can easily have your continuous integration server publish artifacts to a subversion-powered binary repository automatically with every developer commit.

Saturday, February 6, 2010

Breaking The Build

Software development is more than programming. Once code has been written, it must be versioned, built, published, tested, deployed, and configured. This "post-code" part of the development process is often neglected. I'm not sure why, but I suspect that developers (of which I am one) prefer the "fun" aspects of development; namely the coding. Actually building and releasing software tends to be "messy" -- there are all kinds of prerequisites and environmental issues to be tracked down, incompatibilities with other software to be dealt with, and users who get very angry (understandably) when their systems crash. Developers are all too happy to throw these problems "over the wall" to a release engineering team to sort out all that messy stuff. For some reason, the release engineering team is often all to happy to deal with the messiness manually, rather than put in place processes and frameworks to make their lives easier and give developers more control over (and responsibility for) the process.

We're here to change all that.

Here's the secret. Build and release management is really a software development problem. The same principles that apply to software development apply to the design of release management processes and tools. Don't repeat yourself. Keep it simple. You ain't gonna need it. All of this applies to the design of your release process. You want the process to be simple, flexible, reproducible, and robust. It should be easy to create a new project without having to jump through a lot of hoops to get it deployed to production "properly". It should be easy to change the process and have that change apply to all your projects (without needing to copy and paste). Developers should have control over, and take pride in, the way their software is built and deployed, not just the way their software runs once it is deployed.

"Breaking the Build" is inspired by the now-common colloquialism among developers regarding "breaking" the continuous build for their code. Caring about a broken build, and working to fix it, is the first step towards having a development team that embraces release management as a core responsibility. The goal of this blog is to push that envelope further, and discuss how developers (and release engineers) can build a quality end-to-end software development process that continually and efficiently delivers value to the organization. We'll discuss software architecture, productivity tools, process design, development methodologies, and everything under the sun that can help us design better software that is easy to deliver to users.

Welcome!