Drupal Development Best Practices: Techniques (Part II)

Profile picture

As we talked about in the last post about Drupal Development Tools, the process of making Drupal websites is a lot like cooking and requires great tools, techniques, and secret sauce to make it all happen. Here are some of the techniques we use on our projects:

The Techniques

Due Diligence and Drupal Development Plans

Just as breakfast is the most important meal of the day, writing an initial Drupal development plan is the most important part of any project. It might seem like paperwork or busywork, especially to seasoned developers where Agile is Cowboy spelled backwards, but it has been my experience that every extra hour you spend planning saves you several hours at the end of the project - plus all the headaches. This process is pretty straight forward for small sites - identify the major content types, views, and contributed modules you need - and then start building. It usually takes a couple of hours thinking it through and often helps to talk it through with another developer.

For larger sites, the process of building a Drupal development plan should be a more involved one where you consult with all of the developers, themers, and designers involved in the process. For sure a lot of the Drupal implementation is obvious (this is a node!) , but it is the hard stuff (especially the custom code and how that all fits together) that will throw you for a loop. At Chapter Three we believe that the best development process is an iterative one and items will be changed, modified, and blended throughout the process, however, its much easier to change something if you know the structure of what you are changing in the first place. There are many ways to put together a project plan, but here is a basic Drupal development template we have used to give you some ideas.

Sandbox Environments

As I mentioned previously, we use SVN version control for all our projects and to take full advantage of this we give every developer their own sandbox copy of the code located at projectname.chapterthree.com/ ~username. This allows the developer to work in isolation and only commit up changes when they are ready to have them reviewed. We have an automatic SVN post-commit hook that fires on each commit to update our general development instance (project.chapterthree.com) with the latest and greatest code. There are occasionally SVN conflicts that need to be resolved, but its much safer than trying to work off the same general copy of the code - in fact, our SVN post-commit hook explicitly forbids commits from any non-sandboxed copy of the code.

The database is shared across sandboxes for convenience sake - Drupal places nice with multiple administrators - but we try to do as much configuration in the code as possible (see below). It is easy enough to segment the databases if needed and for more advanced database development we do. The files directory is likewise shared (as a symlink) for development convenience stake, but we never store anything critical in that directory. Moreover, in cases of remote developers, we can easily export the SQL + files and checkout the SVN so they can work in their own environments. We have a script for that too.

Dealing with Database Changes: Export It to Code

Let's face it - Drupal's database driven storage model does not provide a clear distinction between content and configuration, which makes all of our lives difficult. We cannot selectively copy parts of the database and push it through from development to staging and then to live without blowing away existing content and configuration. This technique can work in isolated, absolute cases, but it is at best unreliable and is only limitedly auditable and cannot cleanly be stored in SVN. Instead, at Chapter Three, we avoid this problem as much as possibly be exporting our changes to code. Variables can be set via update hooks with variable_set() and hook_update_N() and a host of modules (Views, CCK, Imagecache, Chaos Tools, Block) allow exportable and importable elements in code. The Features module, bless its code, makes this process much easier (especially if you are using contexts) and we have a few internal techniques, like exporting specific views to specific files, that allow for easily updates and management of the code. This makes pushing changes easy - just update SVN and run update.php (or drush updatedb).

Quality Assurance: Have a Designated Person Involved

The process of delivering quality code to your client is something that the right set of tools can help with. In our last post, we talked about we use Simpletest and Selenium to do automatic testing of site functionality. This automation helps to improve things a lot, but we have found it is important to have a real person take a look at the code as well. In our process we have the primary developer of a piece of functionality do a first pass and then hand it over to a dedicated quality assurance person.

At Chapter Three, we employ Ray Thompson as our full time Quality Assurance specialist. Ray approaches each project with "fresh eyes" and maintains an "user perspective" for each piece of functionality. Ray has developed his own process - adapted for general best practices - to test features and functionality, identify problems, and report back to developers - using descriptions, screenshots, and video clips - the items that need to be resolved. During the creation of our development plan we create a separate Quality Assurance plan which helps Ray run through the project's user scenarios. We find this combination of testing - some automatic and some manual - to be the best way to guarantee a fabulous final product.

Development -> Staging -> Live Deployment

Just as it is important to be disciplined about sandbox development practices, so too is it important to be disciplined about our deployment practices. At Chapter Three we follow a disciplined approach where all development happens on the development server, code is pushed to staging for testing and evaluation, and when everything is approved it is pushed live. To help us manage this process we have several custom scripts:

  • code_merge_staging.php - This script takes the code from our SVN development branch, merges it onto the production branch, and then updates the staging site with the new code. By default this all happens under once branch, but can be configured per branch if we have several open branches (perhaps one for tweaks to a live site and another for new feature development).
  • db_sync_staging.php - This script takes a copy of the live database and overwrites the staging database, as well as syncing the associated files from live to staging. This syncing is particularly helpful for testing since it allows us to test our new code against the latest and greatest from the live server. We do a few tweaks to the export script (like not dumping the cache tables) to improve performance since that is often a large and unnecessary thing to migrate over.
  • code_push_live.php - This script takes the current, tested code from the SVN production branch and exports it into the production box. The code is pushed as an SVN export to keep the production code all in sync - once you push it, it all goes live immedaitely.

Prototype Sprints

The first week of any project is critical because it defines the structure and tone for everything that comes later. A solid Drupal development plan is a good start, but after that is written comes the all important prototype sprint. The goal of this sprint is to build a functional prototype while the specifications are fresh in our minds from the development plan phase. We typically start with the hardest problems first, since its a poor idea to leave incorporating a newly released module or integrating an unfamiliar API till the end.

Ideally, these sprints are done as a group - with two or three people working on each one. This simultaneously lets us get several people up to speed on a project and allows us to work collaboratively, sharing information with each other during the process. In cases where the timeline is short - and many of our projects are on short timelines - the sprint is critical to removing blocking issues and getting the project development process (content entry, theming, advanced custom development) rolling. This is how we built a site in a day and how we start the process for even the largest of sites.

Look for the last blog post in this series on Drupal Development secret sauce in the next few weeks!

Comments

I've worked on corporate, small, and educational environments and seen quite a few different deployment practices. Do you guys mind releasing a template of your .php deployment code? Would love to see how to connect these pieces with this.

Sounds very familiar :).
Though a few small improvements may make life even easier.

First there is the ~/developerName issue. It requires .htaccess for each developer to have a different RedirectBase. This, a.o. made me configure apache so that it runs on developerName.dev.example.com.

Second there is that external developer, or the other odd one who works on Windows. It is almost undoable to make windows users work over FTP or SSH, so you either have to tell them to work locally and FTP files all the time (I have seen several developers go alt-tab-doubleclick-in-filezilla like 2-300 times a day) nor else get into a samba nightmare. This a.o. is why I advice dev teams to leave developers the freedom to choose and run their own local sandbox, if they want so. Now that i think of it, coupling foo.dev.example.com domains to everyones local sandbox should not be hard, in a simple network.

And then there is git. It requires less then a few hours to get your dev-team to use that instead of SVN. Transition is simple. And I haven't met a single developer whom, after changing to git, did not sincerely love it. The biggest problem is that people think "I'll look at it some day. for now that is too much work". It really isn't. I have been in a situation where forcing the dev-team to git in an hour, provided less hassle and time then getting that darned SVNconflict solved.

Pushing from tags. When on git, an automatic export to LIVE from new tags is simple. So is it from SVN.
In one place, I built a simple post-commit script that will push every tag that has the pattern REL-x.y to production server immediately after creation. That way you can keep everyone out of live, once all the symlinks, permissions and so forth are set correctly.

With one team, I am experimenting a pre-commit-run-trough-coder module as well. If that coder module gives back any criticals, the commit will not continue. Every dev is lazy and when the heat is on, people will forget about having code checked.
I am confident that in this team, quality will greatly increase.

We solve the .htaccess rewriteBase issue in the project sandbox (projectname) script. It's a simple regexp, although doing devname.project.server.com type architecture wouldn't be very hard with proper vhost wildcarding or global rewriterules. Currently our setup ain't broke, we we weren't fixin' it. ;)

I haven't had the issues you talk about w/windows users or external developers. Windows has fine SFTP support through a number of cheap/free apps, and ssh via putty. We also easily support external/local development by adding per-project htpasswd-based access to Trac/SVN.

The next level is indeed distributed version control, but if you need to support windows people, Git can be problematic. We're currently experimenting with BZR (as well as some automated support for desktop development w/the Acquia Stack installer).

Sure there are free apps that allow moving files over SSH or putty. But afaik there is no solution that is both (rather) stable and allows working on local files.
Not in the way Linux or Mac support network transparancy.

My main reason behind letting people work in a local sandbox, however, is not so much (lack) of tools.

It is my belief in productivity trough freedom. Meaning: just let a developer choose her own tools, environment and configuration, and she will be most productive. There are those who prefer a macbook with expensive tools. There are those who insist on windows with eclipse. Those who want a completely hacked up minimalistic gui on debian and so on.

It is my belief in productivity trough freedom. Meaning: just let a developer choose her own tools, environment and configuration, and she will be most productive.

This is very true.

One exception though is the area of training. When someone is first learning a new system or discipline, it can be quite helpful to learn within the context of an existing/working system. In those cases, it's often very helpful to provide a dev environment/workflow. You don't want to be too heavy-handed, but not having to start from scratch can be very helpful.

I haven't had the issues you talk about w/windows users or external developers.

External developers is an area I'm currently having trouble with and I'm wondering how you (*or others on this thread) handle this?

I've been trying to figure out a way to have remote developers work locally on a svn checkout to their own environment -- but have them save over the internet to a common, remote database. I'm finding this simply isn't working because requests to the mysql server over the network are simply TOO SLOW (10-30 seconds per page load.

Thanks,
Mike

Trying to use a remote mysql database via a consumer-grade internet connection is a non-starter. It's just not gonna work.

If you are dealing with multiple people trying to configure a site, you may need to share a development server, or follow the discipline to put your changes into hook_updates() in code, which can be committed to version control and then "added" to the main development site via update.php or drush updatedb.

It's also very important to make it easy for local developers to get updated copies of the DB onto their desktops so they can all stay in sync. If you're not dealing with vast amounts of data, you can probably do that on-demand. Otherwise, nightly dumps are a good idea.

Agreed with Frederic - would be great if you could provide more detail (or even source...) for the PHP code you use for managing code merging, database refreshes etc....

Has anyone had any luck getting a similar set up running using Capistrano? We are using it for deployments and it works like a dream. At WeMakeWebsites, we are automating all environment-level processes using Capistrano.

> Code base - We will have two code branches. one Dev and other Production.

> Code in development need to be checked in everyday to Dev branch

> Code completed need to go production branch.

> There is will be an automated process to deploy app as following twice a day

>> Check-out the code from production branch

>> Compile the code

>> If build fails send a message to team

>> If build success run all the junit tests

>> Report test failure to dev team

>> No bugs deploy the build and send email to dev and qa team

i want these requirements for my company help me.

Sounds like a good best practice workflow. We'll be working on providing something like this "out of the box" as a service as part of future PANTHEON development, but at this point you'll need to tackle it by reading documentation and setting it up. It's way too complex to address in just one blog post! :)

Mbt zapatosEnciendo el televisor escuchando el diálogo de los demásMbt zapatosTal vez los que me pueden dar cuenta de la historia
Usted tiene que amar no puedo aprenderMbt zapatosImpotente viendo que la situación empeore.Sentirse realmente en serio vistazo a la situación.Yo no puedo darte el futuro ustedMbt zapatosTranquilo final del tratamiento es otro.Cuando las lágrimas para permanecer.Shangyiqiaozai
La separación es otra de Mbt zapatosentender

Add comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br/> <br /> <p> <img> <blockquote> <i> <b> <u>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Client Testimonial

We picked Chapter Three because of a track record of creating sites that work as good as they look, and an approach to open, collaborative web spaces that meshed with ours. I'll come back to them because they deliver what they promise, when they promise it. Chapter Three represents a group of creative, dedicated professionals who know how to think big and then make it happen.

Alex Halavais, Technical Director from DML Central, a project of the MacArthur Foundation

Drupalcon SF 2010