Automating Drupal Deployment with Drush Make and Features

44
Automating Drupal deployment with drush_make, installation profiles and features Presented by: Adrian Rollett & Adam Jensen Central Web Support University of North Texas Twitter: @acrollet @jazzslider

Transcript of Automating Drupal Deployment with Drush Make and Features

Page 1: Automating Drupal Deployment with Drush Make and Features

Automating Drupal deployment with drush_make,

installation profiles and features

Presented by: Adrian Rollett & Adam Jensen

Central Web SupportUniversity of North Texas

Twitter: @acrollet @jazzslider

Page 2: Automating Drupal Deployment with Drush Make and Features

Who are we, anyway?

UNT Central Web Support office handles:Systems administrationWeb application developmentHosting services

UNT recently selected Drupal as the official campus CMSHave rolled out ≈300 instances of our custom Drupal distribution

Page 3: Automating Drupal Deployment with Drush Make and Features

What's in it for me?

Image by flickr user atlanticlost

Page 4: Automating Drupal Deployment with Drush Make and Features

Dynamic web apps without Drupal

Functionality lives in codeContent lives in the database

Page 5: Automating Drupal Deployment with Drush Make and Features

Dynamic web apps with Drupal

Functionality lives mostly in code, but what about…Content types?Views?Dependencies?

How do you…Use version control?Package it up for redistribution?Deploy it elsewhere?

One common solution: put database dumps in version control!

Page 6: Automating Drupal Deployment with Drush Make and Features

Versioning database dumps is kind of like making a photocopy of a pig: messy, difficult and time-consuming

Original photos by flickr users sugarmtnfarm and binglib

Page 7: Automating Drupal Deployment with Drush Make and Features

So what then?

Functionality should still live in code if possible, but why?

Page 8: Automating Drupal Deployment with Drush Make and Features

Less Clicking: make your changes in code, not with a mouse

Image from warmouse.com

Page 9: Automating Drupal Deployment with Drush Make and Features

Easy automation of deployment

Original image by flickr user jasoneppink

Page 10: Automating Drupal Deployment with Drush Make and Features

Features

The Features module (currently beta3) allows you to export sets of functionality (photo albums, blogs, calendars, etc.) as "features"Features are modules, but at a higher level of abstractionKey differences:

Code is generated, (usually) not written by handCollects functionality rather than creating itEasily enabled by lay people, and they don't have to look at the core modules page to do it

Page 11: Automating Drupal Deployment with Drush Make and Features

What is a feature?

Features bring together all the little pieces that make up usable, fully-configured Drupal functionality.

Image from XKCD: http://xkcd.com/659/

Page 12: Automating Drupal Deployment with Drush Make and Features

What are the pieces?

Information about module dependenciesExported configurations for things like…

content types,views,menu items, andpretty much anything else that…

can be exported as code, andhas a machine-readable name.

Most importantly: features are modules, so all these pieces are defined in code. No database dumps to manage.

Page 13: Automating Drupal Deployment with Drush Make and Features

For example…

Page 14: Automating Drupal Deployment with Drush Make and Features

Making an event calendar the old way

Download calendar, cck, date, and views; enable several relevant modules from each project.Create an "Event" content type.Assign a date field to the Event content type.Clone the calendar view that comes with the calendar module.Modify the view such that it only shows Event nodes, and places them on the calendar using their date field.Go back over the end result to make sure you didn't miss a step.All told, ≈15 minutes. Not too bad, but…

Page 15: Automating Drupal Deployment with Drush Make and Features

Making an event calendar with features

Do all that other stuff once.Create a new feature, making sure to specify…

The module dependenciesThe content type to exportThe view to export

Initial setup, ≈20 minutes. But then…

Page 16: Automating Drupal Deployment with Drush Make and Features

Deploying a feature

Once you've built your feature, deploying to another site is simple:

Install the feature code as you would any other moduleMake sure that the dependent modules are thereVisit admin/build/features and enable it!

Time spent: ≈5 minutes, maybe less.

Page 17: Automating Drupal Deployment with Drush Make and Features

Some advantages

As long as the module dependencies are there, you can now install this same feature on any site in virtually no time.Since everything is in code, it's…

versionable,packageable, anddeployable.

End users can turn it on and off without worrying about the nitty gritty configuration details.

Page 18: Automating Drupal Deployment with Drush Make and Features

What it doesn't do

Some common needs that features can't handle yet on its own:

Exporting taxonomy vocabularies.

Exportables module can help with this

Exporting variables.Enabling blocks.Exporting nodes (not really within scope).Probably more things.

Page 19: Automating Drupal Deployment with Drush Make and Features

How to deal with that

Features are modules. If necessary, you can add your own hook_enable() and hook_disable() code to ensure that everything is set up as it needs to be.Avoid changing any of the module.features.*.inc files. These can be overridden if you later re-export your feature, so stick to editing the .module and .info files.

Page 20: Automating Drupal Deployment with Drush Make and Features

Features servers

Rather than uploading features modules to drupal.org, you can set up your own server using the feature server module

http://code.developmentseed.org/featureserver/dashboard

Decentralized approach to distribution means you can have greater control over the processSee http://developmentseed.org/blog/2009/jun/24/distributed-feature-servers-drupal for more information

Page 21: Automating Drupal Deployment with Drush Make and Features

What's next?

Features is great for discrete functionality, but what if you could do the same thing for your entire site?

Page 22: Automating Drupal Deployment with Drush Make and Features

Drush: a quick review

Command-line interface for managing DrupalSome helpful commands:

drush dl {project}drush enable {module}drush disable {module}drush update {module}There's lots more; run drush by itself for a list of available commands

Page 23: Automating Drupal Deployment with Drush Make and Features

What is drush_make?

From drupal.org/project/drush_make:

Provides the equivalent of a make script for Drupal, using Drush.

Page 24: Automating Drupal Deployment with Drush Make and Features
Page 25: Automating Drupal Deployment with Drush Make and Features

From the readme file:

Drush_make is an extension to drush that can create a ready-to-use drupal site, pulling sources from various locations.

It does this by parsing a flat text file (similar to a drupal .info file) and downloading the sources it describes.

In practical terms, this means that it is possible to distribute a complicated Drupal distribution (such as Development Seed's Managing News) as a single text file.

Page 26: Automating Drupal Deployment with Drush Make and Features

What can drush_make do?

Download Drupal core, as well as contrib modules from drupal.org.Fetch themes and installation profiles.Check code out from CVS, SVN, git and bzr repositories.Download plain .tar.(gz) and .zip files (particularly useful for libraries that can not be distributed directly with drupal core or modules).Fetch and apply patches.

Page 27: Automating Drupal Deployment with Drush Make and Features

What does a makefile look like?

It can be as simple as this:

$ sudo cat distro.buildcore = 6.xprojects[] = drupalprojects[cws_d6][type] = "profile"projects[cws_d6][download][type] = "svn"projects[cws_d6][download][url] = "file:///export/web/svn/drupal_install_profiles/trunk/cws_d6"projects[cws_d6][download][branch] = "trunk"

Page 28: Automating Drupal Deployment with Drush Make and Features

$ drush make distro.build newProject information for drupal retrieved. drupal downloaded from http://ftp.drupal.org/files/projects/drupal-6.14.tar.gz.cws_d6 downloaded from file:///export/web/svn/drupal_install_profiles/trunk/cws_d6.Project information for admin_menu retrieved. Project information for cck retrieved. Project information for cws_event_calendar retrieved. adminrole downloaded from http://ftp.drupal.org/files/projects/adminrole-6.x-1.1.tar.gz.adminrole patched with adminrole_exceptions.patch.cws_event_calendar downloaded from https://cws.unt.edu/[...]/cws_event_calendar-6.x-1.0-beta4.tar.northtexas downloaded from file:///export/web/svn/cws/northtexas_theme.tinymce downloaded from http://downloads.sourceforge.net/[...]/tinymce_3_2_7.zip.

Here it is in action (truncated output):

Page 29: Automating Drupal Deployment with Drush Make and Features

Wait a minute, how did drush_make know to grab all those other items?

If the installation profile you specify includes a make file, drush_make will automatically parse it.

That's the beauty of recursion!

Original photo by flickr user frangipani_photograph

Page 30: Automating Drupal Deployment with Drush Make and Features

What can't drush_make do?

Configure the database settings and install drupal itself. (an installcore command has been added to drush, but works only with Drupal 7)Make changes to an existing drupal installation.Configure or enable modules, set variables, etc.drush make coffee not implemented at this time

Page 31: Automating Drupal Deployment with Drush Make and Features

Can't I do the same stuff with a shell script?

Yes, but there are several advantages:A drush_make make file is simply descriptive; tell it what dependencies your site needs, and it handles the process of retrieving themMake files are sharable, distributable, and guaranteed to work on any system that runs DrupalMake files also tend to be more succinct and human-readable than shell scripts (no need to know bash/python/ruby/etc.)It's a standard, public, open source tool instead of a custom solution

Page 32: Automating Drupal Deployment with Drush Make and Features

Custom Drupal to Go: tying it all together with installation profiles

Original photo by flickr user dsnet

Page 33: Automating Drupal Deployment with Drush Make and Features

If features provide all needed functionality, what use are installation profiles?

Original photos by flickr users albaum and texasrobo

Page 34: Automating Drupal Deployment with Drush Make and Features

Installation profiles are the glue between drush_make and features

Installation profiles

Page 35: Automating Drupal Deployment with Drush Make and Features

drush_make + features will give you this out of the box:

FAIL

Page 36: Automating Drupal Deployment with Drush Make and Features

What you see after logging in to an Open Atrium site for the first time

Page 37: Automating Drupal Deployment with Drush Make and Features

Wait, aren't installation profiles bad???

The main problem holding back the full potential of installation profiles is the lack of a packaging tool for contributed modules.

-- Greg Knaddison (greggles)

Installation profiles have had a bad rap for some amount of time. Probably the chief complaint is the following:

Page 38: Automating Drupal Deployment with Drush Make and Features

drush_make solves that problem!

Original image by flickr user dbgg1979

Page 39: Automating Drupal Deployment with Drush Make and Features

Other drawbacks of installation profiles

You must know PHP and the Drupal APIsIf you're a developer, hopefully this doesn't scare you!the installation_profile_api module helps somewhat

They can be somewhat finicky to buildThey can only be run at install time.

anything you want to be able to enable and disable should be contained in a feature (or module update)

Page 40: Automating Drupal Deployment with Drush Make and Features

What are installation profiles good for in the context of this presentation?

Enabling a custom themeDoing one-time setup tasks like

enable modules and featuresdownload and install translationsdisable unnecessary default functionality

Anything! *

* (perhaps not anything)

Page 41: Automating Drupal Deployment with Drush Make and Features

Tips for building Installation Profiles

Start with the default profile, and modify it to your purposesThe open atrium installation profile is a nice exampleAlways look for an install_profile_api helper function firstThe name of your profile and the directory it's in should be the sameWhen debugging an install profile, you'll want php debug output to be onClear *all* caches at the end of your profile

Page 43: Automating Drupal Deployment with Drush Make and Features

Questions?

Page 44: Automating Drupal Deployment with Drush Make and Features

Thank you!

Adam Jensen @jazzslider

Adrian Rollett @acrollet

UNT Central Web Support https://webadmin.unt.edu