Drupal: deployment

There are a couple of tools which can be used for Drupal deployment. This article is about managing code, content and configurations across multiple environments.

The problems we face:

  • Move content and configuration from one to another environment
    • What is content and what is configuration? There is no line in Drupal 7. “If it is an Entity it is content, if not it is configuration” (Drupal 8)

Anatomy of a Drupal site

  • Content
  • Configuration
  • Code
  • Files

Configuration

  • Consists of Drupal admin and module settings and presets
  • Imagecache / images styles
  • Configuration workflow begins on development server
    • New modules installed
    • Existing modules configured
    • Content types, fields, and profile structures edited
    • Database stored stylesheets, php code

Content

  • Content workflow begins on the production server
  • User content
    • User registrations
    • User generated content
    • Files and uploads
    • Social interactions (Private Msg, Statuses, etc.)
    • Content management
    • Site and user administration
  • Officiated content
    • News Articles
    • Press Releases
    • Internal Announcements

Code

Can be versioned for easy deployment (SVN / Git). What goes into source control:

  • Code
  • Configuration
  • Theme-based files

Strategies – manage database changes

  • Export your views, panels, rules, and content types to code
  • Use Exportables and Ctools to export other data
  • Manage configurations with Strongarm
  • User Permissions API for roles and permissions
  • Use Features

Strategies – backup and Migrate

  • Use backup and migrate module to create backup profile for content and configuration
  • Use versioning for moving code
  • Configuration must still be entered manualy on deployment
  • Takes some trial and error

Strategies – Launch Manager

  • Aegir
    • Seems to work well for launching initial site rollouts. Not so much for maintenance updates
  • Hudson
    • Extensive initial configuration
    • Integrates with version control
    • Can script specific updates

Strategies – Typically for enterprise environments

  • Features
  • Services and Feeds (Content Publication)
  • Synching Environments
  • File Share
    • Mount files drive
    • Network-Attached Storage (NAS)
    • Content Delivery Networks (CDN)

Features – Export configuration into code

The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case.

  • Extracts configurations into code workflow to avoid database conflicts
  • Allows versioning of configuration
  • Can manage all configuration exports in this way – not feasible or scaleable
  • Features Tools – Automates feature downloads, and creates versioned change files
  • Use deployment tools like Jenkins, Capistrano, Kraftwagen to export features which the Features module doesn’t support

What can be exported:

  • Content types
  • CCK fields
  • Views
  • Imagecache presets
  • Ctools (Panels, Variables, Feeds, Data and more)
  • User roles and permissions
  • Menus and menu links
  • Input formats
  • Context

What is difficult to be exported:

  • Vocabularies
  • Nodequeues
  • Nodes, Terms and Users

Workflow of Deployment Process

  • User X create’s a content type and the CCK fields on his local development site. He package everything as a feature and commit that module to the repository
  • User Y updates his repository, install the feature and automatically receive the configuration that user X created.
  • User Y add’s couple views and imagecache presets and attach them to that feature
  • User X update’s and make adjustments on fields. User X commits  the changes
  • User Y update’s and overwrite styles for views and commit again
  • User Z update’s his repository and fixes our configurations. He commits the changes to our staging site and install the feature. If the client is satisfied he can upload the feature to production site

Kit is a specification, it is a set of guidelines that facilitates building compatible and interoperable Features.

Services

Services provide a standardized solution of integrating external applications with Drupal. Service callbacks may be used with multiple interfaces like REST, XMLRPC, JSON, etc. This allows a Drupal site to provide web services via multiple interfaces while using the same callback code.

  • Publish content to lower environments
  • OAuth Support

Feeds

  • Pull content, users, and pretty much anything exportable by views
  • Can use Data module to map data to where it needs to go
  • OAuth Support
  • Use UUID module when importing to avoid duplicate content

Synching Environments

  • Backup your databases
  • Once content is synched, push dev data
  • If file share, Backup & Migrate exports will be automatically available to all environments
  • Staging environment pushes will be ‘easy’. Use B&M ‘Restore’. Can be used with Drush
  • In production, push during off peak hours, put site in maintenance mode and import data

Deploy module

The Deploy module is designed to allow developers to easily stage Drupal content from one site to another. Deploy automatically manages dependencies between objects (like node references). It is designed to have a rich API which can be easily extended to be used in a variety of situations.

The Drupal 7 version will see a complete rewrite to provide a more flexible API and workflow and to take full advantage of the new APIs in core. This module is still in an alpha stage.

Drush Deploy

Drush deploy is a deployment framework built on Drush. It is heavily influenced by capistrano. This module is still in a development stage.

Jenkins

Jenkins (an extendable open source continuous integration server) is a widely used package for continuous integration. Deployment is a part of this, but it can also be used for automatic tests, making backups, etc. It is triggered either manually, by cron or upon commit into a version control system.

Maven

Jenkins is often used in combination with Apache Maven. Maven is a tool for building and managing any Java-based projects. On the flip side, it’s conventions are focused on use in a Java environment, Java knowledge is needed and you probably need to write Java scripts. Further it probably needs Ant (a Java build tool) to complete all the tasks required for Drupal deployment.

Phing

Phing is a  PHP project build system or build tool based on ​Apache Ant. Phing is a programming language in an XML-format. The integration between Phing and Jenkins is good. Jenkins has a Phing plugin which allows to execute Phing tasks.

Capistrano

Capistrano is a Ruby program that gives you a set of advanced tools to deploy web applications to your servers. Capistrano allows you to copy code from your source control repository (SVN or Git) to your server via SSH, and perform pre and post-deploy functions like restarting a webserver, busting cache, renaming files, running database migrations and so on.

Kraftwagen

Kraftwagen consists of a Drush extension and set of Drupal modules. It reuses existing work where possible, for example: install profiles, Drush Make, Features, version control systems and soon Capistrano.

Kraftwagen’s manifests are named (database) migrations that are defined in modules and can be used to synchronize anything that cannot be done with hook_update_N (schema changes) or Features (e.g.: node types, fields, variables, CTools exportables). Manifests are mainly used to create nodes (or other entities) and assign dynamic variables.

Because Drupal stores a lot a configuration details in the database, version control systems cannot be used to track changes. This makes it hard for a team of developers to collaborate or to stage changes to a separate deployment target before rolling them out in production. Kraftwagen primarily solves this issue by using manifests to sync aspects of Drupal project’s different installations to the same state.

  • Everything in code, under version control
  • Multiple deployment targets (local, staging, production, etc.)
  • Kick-start new projects from skeletons

One thought on “Drupal: deployment

Leave a Reply