HOWTO: Work on Drupal using GIT

The Ergo Project website(s) are managed through GIT, to allow tracking the development history and collaboration on further development.

The GIT repository can be viewed through Gitweb, or cloned through the following locations:

  • git://git.ergo-project.org/ergo/web (read-only)
  • ssh://git.ergo-project.org/git/ergo/web (read-write)

The GIT repository has multiple branches. At the time of this writing, these branches are master and test. The point of these branches is to be able to test certain modules and changes outside of the realm of the master branch, and to be able to merge the changes back into the master branch.

Preparing Your Setup

First, obtain a copy of the GIT repository:

$ git clone ssh://git.ergo-project.org/git/ergo/web ergo-web.git

Then, navigate to the ergo-project.org/www/ directory. The contents of this directory are, at the time of this writing:

$ ls -l
total 4276
drwxrwsr-x. 9 jmeeuwen jmeeuwen 4096 2010-03-04 12:33 drupal-6.15
drwxrwsr-x. 9 jmeeuwen jmeeuwen 4096 2010-03-04 01:20 drupal-6.16
lrwxrwxrwx. 1 jmeeuwen jmeeuwen 11 2010-03-04 12:33 public_html -> drupal-6.16
drwxrwsr-x. 2 jmeeuwen jmeeuwen 4096 2010-02-25 15:30 usage

You can see here, two versions of Drupal, and one symbolic link that lets the webserver use the drupal-6.16 tree through having the DocumentRoot point to the public_html symbolic link.

You can also see that the files and directories are (supposed to be) group writeable with the sticky bit set. This causes the production version to also have those permissions, so that group permissions can be given to the www-ergo-project.org group.

Example Action: Adding a Module

This example shows you how to add a module. Before adding the module, please verify whether this module had been added, enabled and installed before using `git log`. We use the commit message convention of "Add module <name>" and "Remove module <name> (<reason>)" in order to be able to retrieve such facts.

Suppose we add the module "foo". Take the following steps:

  1. Download the tarball into the ergo-project.org/www/public_html/sites/all/modules/ directory;
  2. Extract the tarball;
  3. Add the module directory to GIT:
    $ git add ergo-project.org/www/public_html/sites/all/modules/foo/
  4. Commit the module:
    $ git commit -m "Add module foo" ergo-project.org/www/public_html/sites/all/modules/foo/
  5. Push the changes.

Example Action: Updating a Module

This example shows you how to update a module.

  1. Download the tarball into the ergo-project.org/www/public_html/sites/all/modules/ directory;
  2. Remove the module directory:
    $ rm -rf ergo-project.org/www/public_html/sites/all/modules/foo/
  3. Extract the tarball;
  4. Add the module directory to GIT:
    $ git add ergo-project.org/www/public_html/sites/all/modules/foo/
  5. Commit the changes:
    $ git commit -m "Update module foo" ergo-project.org/www/public_html/sites/all/modules/foo/
  6. Push the changes.

Making Changes to the Test Version

When making changes to the test version, please realize that the master branch may have had a couple of commits that were sufficiently non-intrusive to allow to be released to the production version directly, skipping the test version of the website. Pull in those changes to the test branch (preferrably before making any changes to the test branch):

  1. $ git checkout test
  2. $ git merge origin/master

Also note that the test-version of the website uses a different copy of the database. The database contains, amongst other things, the modules that are installed, enabled and how they are configured. You will need to create a copy of the production database before deploying the test version of the website:

  1. $ sudo /usr/local/bin/ergo-reset-testdb-to-proddb

Deploying the Changes

To deploy the changes, you require group membership of 'www-ergo-project.org', and a shell account on the www.ergo-project.org server.

To Production

To deploy the master branch to www.ergo-project.org, run the following command:

$ ergo-release-git-to-prod

This does the following:

  1. Clone the GIT repository in a new location (to ensure cleanliness);
  2. Synchronize the contents to the right location using rsync;
  3. Remove the temporary directory.

To Testing

To deploy the test branch to www-test.ergo-project.org, run the following commands:

$ sudo /usr/local/bin/ergo-reset-testdb-to-proddb
$ ergo-release-git-to-test

This performs the following actions:

  1. Drop the test version of the database;
  2. Re-create the test version of the database using the current production data;
  3. Clone the GIT repository to a new, temporary location (to ensure cleanliness);
  4. Synchronize the contents to the right location using rsync;
  5. Remove the temporary directory.