Drupal version control
and deployment techniques
ENTICE meeting David Martín Clavo
TOC
0. The Problem
1. Features
0. The Problem
● How to keep track of the changes?
● How to deploy changes from a development environment to a production environment?
0. The Problem
● First solution: dump the database to a text file and apply version control to it.
● Issues:
o Configuration and content are mixed:
– Configuration: CCK, Views, Blocks... – Content: nodes
o If we deploy to production, we get the new Views /
1. Features
Introduction
● Features is Drupal a module that:
o Allows to export configuration items from the
Drupal DB into code.
o Allows to import code into configuration in the DB. o Has a poorly chosen name...
1. Features
Introduction
● Many things can be exported / imported: views, CCK content types, CCK fields, menus,
blocks...
● Things are exported into features. A feature is a folder with code files, similar to a module.
● A feature can contain different types of
configuration items (e.g. 2 content types with their fields, and 3 views).
1. Features
Exportables
● Exportables are things that can be moved 100% to code:
o Views
o Imagecache presets.
o Ctools: Panels and OpenLayers o Rules
o Blocks (with help of Context module)
1. Features
Faux-exportables
● Faux-exportables: cannot be moved but can be synchronized:
o CCK (better with Features+Strongarm modules):
– Content types – Fields
– Field groups
o Roles & Permissions o Menus
o Vocabularies (but not its terms)
o Nodes, terms and users: experimental state.
● Faux-exportables can be overriden in the DB, and the Features
1. Features
Benefits
● Helps organizing a complex project.
● Exported features can be version controlled.
● features can be shared with other people.
● features can be deployed.
● features can be hosted in a feature server
● features help upgrade from Drupal 6 to Drupal 7.
● features can be reused between projects.
● If a site admin overrides a feature and something
1. Features
Integration with drush
● drush: command line tool for Drupal:
o drush dl: download core.
o drush dl cck views: download contributed projects. o drush en content views: enable modules.
o drush cc (all): clear cache.
● Integration with Features module:
o drush fl : list all the features in a site.
o drush fu : update the code of the features from the
1. Features
How to use
● Install and enable Features, Strongarm and
CTools modules (CTools is a dependency of Strongarm).
● In admin/build/features, create a feature by
selecting what components to include in it
o Add the “content type” before adding CCK fields.
● We obtain a .tar.gz file.
● Unzip it into sites/all/modules of another site. ● In admin/build/features of the other site,
1. Features
DEMO
● 2 sites: development and production
● Sites have CCK, Views, Features, Strongarm installed.
● A CCK content type with fields and a couple Views already created.
● We export them into a feature.
1. Features
Conclusion
● Apply version control to features to keep track of
changes in your Content Types, Views...
● drush helps: use drush fu to automatically
update a feature's code before committing.
● Use features to deploy changes from
development to production without squashing the content.
● git is recommended as VC system, but not compulsory
2. Other tools & techniques
Controller feature / module
● Some changes cannot be exported to features,
e.g. enabling / disabling modules.
● Technique: we write an empty module / feature
and we implement the hooks:
o hook_install
o hook_uninstall
o hook_update_N
– Used by other devs when they update from the version
2. Other tools & techniques
Installation profiles
● Code that gets executed when Drupal gets installed with install.php.
● Declares which modules are active.
● Custom code: initial configuration, interaction with the admin.
2. Other tools & techniques
Makefiles and drush make
● Drupal makefile: flat text file that declares what a
Drupal site is made of (i.e. a manifest): modules, themes, features, patches.
● .make files get executed by drush make
● Useful for:
o Knowing what is exactly on a site. o Building / rebuilding a site.
2. Other tools & techniques
Aegir
● A Drupal application that can monitor, deploy, and upgrade other Drupal sites.
● Allows mass deployment, updates, etc. ● Helps with the development > staging >
production workflow.
● Different Aegir users can have permissions to manage different remote sites.
Other DrupalCon sessions
● Attended module development training.
● Connecting Drupal with external systems: best practices.
● Debugging Drupal. ● Drupal performance.
Thanks :) Questions?
?
ENTICE meeting David Martín Clavo