drupal version control & file system basics

Post on 13-May-2015

4.310 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation for Triangle Drupal User's Group on March 17, 2010. Includes discussion of why version control is a good idea, how to deal with special Drupal issues (updating modules, core) and how to set up your file structure.

TRANSCRIPT

Drupal Version Control & File System Basics

Julia Kulla-MaderTriangle Drupal User’s GroupMarch 17, 2010http://www.juliakm.com@juliakm

What is version control?

• A way of managing changes to documents, programs, or other data stored as computer files. (Wikipedia)

What are some version control systems?

Why use version control?

• Real world scenarios

Why am I getting a white screen of death?

• Version control lets you see what the most recent code change was on your site.

Can I get rid of that white screen of death?

• Version control lets you roll back to a previous version.

My client decided that they prefer a way earlier version of my module

• Version control lets you roll back a specific file to any point in time (when it was under version control).

I really want to use this new module but I'm afraid it's going to destroy my site.

• Using version control, you can maintain multiple versions of your code. For example, you can create a sandbox (“trunk”) just for testing out experimental modules.

My co-worker and I are editing the same page. What if we overwrite one another?

• Version control lets you merge changes when conflicts arise.

Why the heck did I make this change last year?

• Version control lets you record log messages over time so that you can communicate with your old self.

Who was the last person to touch this module?

• Version control lets to see the last person who edited a file.

I want to quickly deploy my code on a new server.

• Version control makes it easy to quickly grab a repository and put in on your local computer or a new server.

I'm sick of copying files from my computer to the server.

• Using “hooks” you can set up you server to automatically reflect a new change to your site made on your local computer.

What Does Version Control Look Like In Practice?

• Example: Association for the Advancement of Sustainability in Higher Education

• Version Control System: Subversion

How is AASHE’s repository set up?

• Trunk: the latest, least stable version of our code

• Branch: the working version of code, very similar to live code

• Tags: each new version of the site is tagged

What does this look like when we are coding?

• If we are testing out new modules or major upgrades, we work in trunk first.

• Commits to trunk show up at dev.aashe.org

• If we are fixing bugs or updating code, we work in the current branch first.

• Commits to the current branch show up at stage.aashe.org

• We never touch the releases, we just create a new one when the branch code is tested.

• We have a release script for making a new release.

What does the release script do?

• Creates the next tag.

• Creates an export of the branch repository.

• Creates a symlink from the public folder to the new release.

• Creates symlinks to the file directories (explanation to follow)

svn copy file://$path/www/branches/branch-3.0/ file://$path/www/releases/release-$release -m "$commit"

svn export --force file://$path/www/releases/release-$release /var/www/aashe.org/releases/release-$release

rm /var/www/aashe.org/publicln -s /var/www/aashe.org/releases/release-$release /var/www/aashe.org/public

What are some version control hurdles specific to Drupal?

Updating Modules

• We use drush to update Drupal modules locally, then commit to the staging site (unless it’s Views or CCK, then trunk)

• drush is a command line shell and Unix scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.

drush up mymodulename

Updating Core

• We download the version of Drupal we are using from Drupal.org and the latest version, unzip them, and create a patch file using the diff command

• Next, we test to see if there are any conflicts by doing a dry run from the root Drupal directory

• Last, we apply the patch file for real from the root directory

wget http://ftp.drupal.org/files/projects/drupal-6.16.tar.gztar -xzf drupal-6.16.tar.gzwget http://ftp.drupal.org/files/projects/drupal-6.15.tar.gztar -xzf drupal-6.15.tar.gzdiff -Naur drupal-6.15 drupal-6.16 > drupal-current-to-drupal-latest.patch

patch -p1 --dry-run < drupal-current-to-drupal-latest.patch

patch -p1 < drupal-current-to-drupal-latest.patch

Preventing Files From Being Accidentally Deleted or Versioned

• We store our files at the same level as our public directory and create a symlink to it

• Our release script rebuilds these symlinks each time there is a new release

ln -s /var/www/aashe.org/files /var/www/aashe.org/public/filesln -s /var/www/aashe.org/documents /var/www/aashe.org/public/documents

Next Steps

• Pick your favorite version control system

• Research your version control system of choice

• If you don’t want to mess with the command-line, look for a GUI tool like TortiseSVN, Versions, SvnX, or a code editor like Eclipse, Textmate

• Decide on your repository structure

• Start writing versioned code

Next Up: Mastering the Drupal Database

• Hello Allen

top related