Middlebury

Drupal Development

Revision as of 12:03, 14 April 2010 by Adam Franco (talk | contribs) (Adding or Upgrading a Module: Added instructions for dealing with ignored settings files.)

_

_

Checking Out the Project

Add your user to the SVN configuration

On chisel:

  • emacs /var/svn/repos/drupal/conf/authz
    • Add "username = rw" where username is your username below the "imcbride = rw" line
  • emacs /var/svn/repos/drupal/conf/passwd
    • Add "username = password" where username is your username and password is the password you'd like to use for SVN
  • emacs ~/.subversion/config
    • Uncomment L13 "store-passwords = no"
    • Uncomment L19 "store-auth-creds = no"

Checking out drupal

svn checkout svn://chisel.middlebury.edu/drupal/trunk drupal_dir_name

Remember the value you use for "drupal_dir_name" as you will need to enter it later.

Set up the database

Create a new database on chisel using http://chisel/phpmyadmin. If you preface the database name with "drupal_", the testuser account will have automatic access to the database. Otherwise, you will need to set up user privileges for the database. In order for drupal to work with the modules we have installed, you will need to grant the database user the following privileges:

  • Data
    • SELECT
    • INSERT
    • UPDATE
    • DELETE
    • FILE
  • Structure
    • CREATE
    • ALTER
    • INDEX
    • DROP
    • CREATE TEMPORARY TABLES
    • SHOW VIEW
    • CREATE ROUTINE
    • ALTER ROUTINE
    • EXECUTE
    • CREATE VIEW
  • Administration
    • LOCK TABLES
    • REFERENCES

You can import a blank database from the central drupal instance:

mysqldump -u testuser -p -h chisel.middlebury.edu drupal > ~/drupal.sql
mysql -u testuser -p -h chisel.middlebury.edu -D your_db_name < ~/drupal.sql

Set up the Webserver

You do not need to perform this step if you are setting up Drupal in your user home directory on chisel, however it is required when setting up new pre-production instances on longhouse. You must be logged in as root to perform these actions.

Edit /etc/httpd/conf/httpd.conf and add the following in the Directory section:

<Directory "/path/to/drupal">
AllowOverride All
</Directory>

Then run "service httpd restart".

Set up the Filesystem

Assuming you've set this up in ~/public_html/drupal_dir_name on chisel:

  • cp /var/www/html/drupal/.htacccess ~/public_html/drupal_dir_name
    • Edit L101 to read "RewriteBase /~username/drupal_dir_name".
  • cp /var/www/html/drupal/sites/default/settings.php ~/public_html/drupal_dir_name/sites/default/
    • Edit L93 to end with the name of the database you set up previously.
  • chmod -R 777 ~/public_html/drupal_dir_name/sites/default/files

Log in as the admin user

Go to http://chisel.middlebury.edu/~yourname/drupal_dir_name/?q=user and log in as 'admin'.

Development with Git

The Git Documentation site is a great resource for tutorials and details on all commands. If you are used to Subversion, the Git-SVN Crash Course is a good resource.

Cloning the central repository

Your ssh keys must be authorized to access the central repository. All chisel accounts' ssh keys have been authorized to do so at the time of this writing. Contact Adam to add ssh keys for other machines (such as your desktop) if desired.

  1. cd to your public_html directory on chisel:
    cd ~/public_html/
  2. clone the repository and create a working directory with git-clone:
    git-clone git@chisel.middlebury.edu:drupal.git
    You should now have a working directory at ~/public_html/drupal/
  3. Export the default versions of the two ignored files, .htaccess and sites/default/settings.php to your working directory:
    git-diff -p origin/core -- .htaccess | git-apply -R
    git-diff -p origin/core -- sites/default/settings.php | git-apply -R

Browsing History

You can use the command-line program git-log and git-show-branchto browse the history, but a much better experience is provided by the gitk graphical browser.

gitk can be started from the git-gui's "Repository" menu, or from the command line:

  1. SSH to chisel using an XTerm:
    ssh -X chisel.middlebury.edu
  2. cd to the working directory:
    cd ~/public_html/drupal/
  3. open gitk showing all branches:
    gitk --all &

Committing Customizations

No customizations to Drupal should be made on the core or modules branches. These two branches are reserved for code coming directly from third-parties. Keeping our customizations off of these branches allows us to be able to easily see where our modifications to core code and modules reside and to maintain those modifications more easily through upgrades.

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. Ensure that you are on the master branch:
    git-status
    If not, check out your master branch:
    git-checkout master
  3. Get any changes from the central (origin) repository if desired:
    git-pull origin master
  4. Make some changes to files....
  5. Stage changes to one or more files:
    git-add path/to/desired/file
    or stage all changes:
    git-add .
  6. Commit the staged changes to your repository:
    git-commit -m "My commit message."
  7. Repeat steps 4-6 as many times as desired.
  8. Push your changes to the central repository:
    git-push origin master

Push conflicts

Sometimes you get an error like the following when you go to push your changes to the central repository:

[afranco@chisel drupal-tmp (master)]$ git-push origin master
To git@chisel.middlebury.edu:drupal.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@chisel.middlebury.edu:drupal.git'

This error indicates that there are new change-sets in the central repository that come after commit that your new changes are based off of. To resolve this issue, the easiest way is to "rebase" your changes on top of those in the central repository. This is done with:

git-pull --rebase origin master

This is equivalent to:

git-fetch origin master
git-rebase origin/master

With this command, your change-sets since you diverged from the central repository's master branch will be set aside, your master branch updated from the central repository's, then your change-sets will be replayed. Once your repository has been rebased, you can push successfully:

git-push origin master

Adding or Upgrading a Module

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. This process will wipe out your settings in .htaccess and sites/default/settings.php, so copy them to a location outside of your working directory:
    mkdir ~/drupal-settings/; cp .htaccess sites/default/settings.php ~/drupal-settings/
  3. Check out your modules branch.
    • You will initially need to create a modules branch that will track the central repository's modules branch. Do this with
      git-checkout --track -b modules origin/modules
    • If you have already created your modules branch, use
      git-checkout modules
      to check out your modules branch, then
      git-pull origin modules
      to bring your modules branch up to date with the central repository's modules branch.
  4. cd to the modules directory:
    cd sites/all/modules
  5. Delete the original modules directory if upgrading so that we get rid of files that are no longer in the new version
    rm -R modulename
  6. fetch the new module tarball:
    wget http://ftp.drupal.org/files/projects/modulename-6.x-2.6.tar.gz
  7. Decompress the new module tarball:
    tar xzf modulename-6.x-2.6.tar.gz
  8. Delete the new module tarball:
    rm modulename-6.x-2.6.tar.gz
  9. Stage the changes (and additions/removals):
    git-add .
  10. Commit the changes (and additions/removals):
    git-commit -m "Upgraded modulename to version 6.x-2.6 from tarball."
  11. If you are upgrading multiple modules, repeat steps 5-10 for each module.
  12. Check out your master branch:
    git-checkout master
  13. Merge the changes from the modules branch into the master branch:
    git-merge modules
    Note that any customizations to the module should be retained in the merge.
  14. Copy your .htaccess and sites/default/settings.php back:
    cp ~/drupal-settings/.htaccess .; cp ~/drupal-settings/settings.php sites/default/
  15. Verify that everything is hunky-dory and the new versions of modules work as expected.
  16. Push all changes in your master and modules branches to the matching branches in the central (origin) repository:
    git push origin modules
    then
    git push origin master
    These can be both pushed at the same time with
    git push origin master modules

Removing a Module

Removing a module is like upgrading one, but we use the git-rm command to delete files and stage the deletions.

  1. cd to the working directory:
    cd ~/public_html/drupal/
  2. Check out your modules branch.
    • You will initially need to create a modules branch that will track the central repository's modules branch. Do this with
      git-checkout --track -b modules origin/modules
    • If you have already created your modules branch, use
      git-checkout modules
      to check out your modules branch, then
      git-pull origin modules
      to bring your modules branch up to date with the central repository's modules branch.
  3. cd to the modules directory:
    cd sites/all/modules
  4. Delete the original modules directory:
    git-rm -rf modulename
  5. Commit the deletion:
    git-commit -m "Deleted modulename."
  6. Check out your master branch:
    git-checkout master
  7. Merge the changes from the modules branch into the master branch:
    git-merge modules
    Note that any customizations to the module may result in merge conflicts that will need to be resolved (by using git-rm again on the master branch, then committing.
  8. Verify that everything is hunky-dory and no dependencies are broken.
  9. Push all changes in your master and modules branches to the matching branches in the central (origin) repository:
    git push origin modules
    then
    git push origin master
    These can be both pushed at the same time with
    git push origin master modules

Upgrading the Drupal Core

Coming soon...

Deploying change-sets to Production

Coming soon...

Version-control of production configuration

Coming soon...