Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
-
Upload
drupalday -
Category
Technology
-
view
552 -
download
0
description
Transcript of Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Automating Drupal Development: Make!les, Features and Beyond
Antonio De MarcoAndrea Pescetti
http://nuvole.org @nuvoleweb
Nuvole: Our Team
BELGIUMBrussels
ITALYParma
Clients in Europe and USA
Working with Drupal Distributions
Serving International Organizations
Serving International Organizations
Trainings on Code Driven Development
Automating Drupal Development
1. Automating code retrieval2. Automating installation3. Automating site configuration4. Automating tests
Automating code retrieval
1
Drupal site building blocks
Core
ModulesContributed, Custom, Patched
Themes
External Libraries
Installation Pro!le
drupal.org github.com
example.com
The best way to download codeIntroducing Drush Make
Drush make is a Drush command that can create a ready-to-use Drupal site, pulling sources from various locations. In practical terms, this means that it is possible to distribute a complicated Drupal distribution as a single text file.
Drush Make
‣ A single .info file to describe modules, dependencies and patches
‣ A one-line command to download contributed and custom code: libraries, modules, themes, etc...
Drush Make
Drush Make can download code
; distro.make; Usage: ; $ drush make distro.make [directory];
api = 2core = 7.x
projects[drupal][type] = coreprojects[drupal][version] = "7.7"
Minimal make!le: core only
$ drush make distro.make myproject
drupal-7.7 downloaded.
$ ls -al myproject
-rw-r--r-- 1 ademarco staff 174 May 16 20:04 .gitignoredrwxr-xr-x 49 ademarco staff 1666 May 16 20:04 includes/-rw-r--r-- 1 ademarco staff 529 May 16 20:04 index.php-rw-r--r-- 1 ademarco staff 688 May 16 20:04 install.phpdrwxr-xr-x 70 ademarco staff 2380 May 16 20:04 misc/drwxr-xr-x 43 ademarco staff 1462 May 16 20:04 modules/drwxr-xr-x 6 ademarco staff 204 May 28 13:28 profiles/-rw-r--r-- 1 ademarco staff 1561 May 16 20:04 robots.txtdrwxr-xr-x 13 ademarco staff 442 May 16 20:04 scripts/drwxr-xr-x 5 ademarco staff 170 May 16 20:04 sites/drwxr-xr-x 8 ademarco staff 272 May 16 20:04 themes/-rw-r--r-- 1 ademarco staff 19338 May 16 20:04 update.php-rw-r--r-- 1 ademarco staff 2051 May 16 20:04 web.config-rw-r--r-- 1 ademarco staff 417 May 16 20:04 xmlrpc.php
Minimal make!le: core only
; views.make; Usage: ; $ drush make views.make --no-core .;
api = 2core = 7.x
projects[views][subdir] = contribprojects[views][version] = 3.1
Downloading a module
$ drush make views.make --no-core .
views-7.x-3.1 downloaded.
$ ls -al sites/all/modules/contrib/views/
total 64...-rw-r--r-- 1 ademarco staff 16067 May 28 13:28 views.info-rw-r--r-- 1 ademarco staff 20358 May 28 13:28 views.install-rw-r--r-- 1 ademarco staff 78204 May 28 13:28 views.module...
Downloading a module
Drush Make can apply patches
; distro.make; Usage: ; $ drush make distro.make [directory];
api = 2core = 7.x
projects[drupal][type] = coreprojects[drupal][version] = "7.7"
; Make system directories configurable to allow tests in profiles/[name]/modules to be run.; http://drupal.org/node/911354projects[drupal][patch][911354] = http://drupal.org/files/issues/911354.43.patch
; Missing drupal_alter() for text formats and filters; http://drupal.org/node/903730projects[drupal][patch][903730] = http://drupal.org/files/issues/drupal.filter-alter.82.patch
...
Applying patches
$ drush make distro.make myproject
drupal-7.7 downloaded. drupal patched with 911354.43.patch. drupal patched with drupal.filter-alter.82.patch. drupal patched with 995156-5_portable_taxonomy_permissions.patch. Generated PATCHES.txt file for drupal
Applying patches
Drush Make supports recursion
; Flex Slider
api = 2core = 7.x
libraries[flexslider][download][type] = "get"libraries[flexslider][download][url] = "https://github.com/.../zipball/master"libraries[flexslider][directory_name] = "flexslider"libraries[flexslider][type] = "library"
"exslider / "exslider.make
; flexslider-module.make; Usage: ; $ drush make flexslider-module.make --no-core .;
api = 2core = 7.x
projects[flexslider][subdir] = contrib
Downloading "exslider
$ drush make flexslider-module.make --no-core .
Project flexslider contains 4 modules: flexslider_views_slideshow, flexslider_views, flexslider_fields, flexslider.flexslider-7.x-1.0-rc3 downloaded. Found makefile: flexslider.make flexslider downloaded from https://github.com/.../zipball/master.
$ tree -l sites/all/
sites/all/!"" libraries# %"" flexslider...%"" modules %"" contrib %"" flexslider...
Recursive make!le parsing
Drush Make supports inclusion
; distro.make;; $ drush make buildkit.make [directory];
api = 2core = 7.x
; Include Build Kit distro makefile via URLincludes[] = http://drupalcode.org/project/buildkit.git/../7.x-2.x:/distro.make
Including an external make!le
Build KitExtendable distribution, reusable .make file
Your project: 2 make !les
‣ distro.make: Drupal core with possible core patches and a link to download myproject.make
‣ myproject.make: includes BuildKit’s drupal-org.make plus project-specific modules and themes
drush make distro.make
drush make distro.make
Found myproject.make
drush make distro.make
Found myproject.make
Run myproject.make
Automating installation
2
Installation Pro!le
$ tree myproject-profile
myproject-profile!"" README.txt!"" distro.make!"" drushrc.php!"" myproject.info!"" myproject.install!"" myproject.make%"" myproject.profile
Installation pro!le components
‣ An .info file to specify installation dependencies
‣ An .install file to perform installation tasks and upgrades
‣ Fully customizable via .profile files‣ Can include makefiles and other
stuff
Pro!les: just like modules
name = Myprojectcore = 7.xdescription = Myproject installation profile.
; Coredependencies[] = bookdependencies[] = field_uidependencies[] = file...
; Contribdependencies[] = admindependencies[] = colorboxdependencies[] = ds...
; Featuresdependencies[] = myproject_coredependencies[] = myproject_blog
myproject.info
/** * Implements hook_install() */function myproject_install() { // Enable custom theme theme_enable(array('custom_theme')); variable_set('theme_default', 'custom_theme');}
myproject.pro!le
/** * Implements hook_form_FORM_ID_alter(). */function myproject_form_install_configure_form_alter(&$form, $form_state) {
$form['site_information']['site_name'] ['#default_value'] = 'Drupalissimo'; $form['site_information'] ['site_mail']['#default_value'] = '[email protected]'; $form['admin_account']['account'] ['name']['#default_value'] = 'admin'; $form['admin_account']['account'] ['mail']['#default_value'] = '[email protected]';
$form['update_notifications'] ['update_status_module']['#default_value'] = array(1 => FALSE, 2 => FALSE);}
myproject.pro!le
/** * Implements hook_install_tasks() */function myproject_install_tasks() { return array( 'myproject_create_terms' => array( 'display_name' => st('Create taxonomy terms'), ), ... );}
myproject.install
/** * Implements hook_install_tasks() callback */function myproject_create_terms() { $terms = array(); $vocabulary = taxonomy_vocabulary_machine_name_load('category');
$terms[] = 'Solution'; $terms[] = 'Client'; $terms[] = 'Use case';
foreach ($terms as $name) { $term = new stdClass(); $term->vid = $vocabulary->vid; $term->name = $name; taxonomy_term_save($term); } }
myproject.install
Introducing Drush BakeA Drush command by Nuvole
to create installation profiles based on templates
$ git clone git.nuvole.org:/var/git/starter-profile.git
...
$ tree starter-profile
starter-profile/!"" README.txt!"" distro.make!"" drushrc.php!"" starter.info!"" starter.install!"" starter.make%"" starter.profile
Installation pro!le template
$ drush bake starter-profile/distro.make myproject
$ git nuvole myproject-profile
$ drush make myproject-profile/distro.make myproject
Bootstrap your project in 3 steps
Automating site con!guration
3
FeaturesThe best way to package configuration
‣ A collection of Drupal elements which taken together satisfy a certain use-case.
‣ A modular piece of functionality for a Drupal site.
‣ A way to export configuration into PHP code, in the form of a module.
‣ http://drupal.org/project/features
What is a feature?
Con!guration in Database
Packaged as Features
A feature can have a .make !le tooDrush Make operates recursively
api = 2core = 7.x
; Modules =====================================================================
projects[colorbox][subdir] = contribprojects[colorbox][version] = 1.0-beta4
projects[insert][subdir] = contribprojects[insert][version] = 1.1
; Libraries ===================================================================
libraries[colorbox_library][download][type] = "get"libraries[colorbox_library][download][url] = "http://colorpowered.com/colorbox/colorbox.zip"libraries[colorbox_library][directory_name] = "colorbox"libraries[colorbox_library][destination] = "libraries"
feature_core.makeA feature can specify where to !nd its own dependencies
How to download your projects from any custom repository
$ cat starter-profile/starter.make
api = 2core = 7.x
; Build Kit ===================================================================
includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.x-2.x:/drupal-org.make
; Modules =====================================================================
projects[libraries][subdir] = contribprojects[libraries][version] = 1.0
; Features ====================================================================
projects[feature_core][type] = moduleprojects[feature_core][subdir] = featuresprojects[feature_core][download][type] = "git"projects[feature_core][download][url] = git.nuvole.org:/var/git/feature_core.git
; Themes ======================================================================
projects[twist][type] = themeprojects[twist][download][type] = gitprojects[twist][download][url] = git.nuvole.org:/var/git/twist.git
Introducing Feature ServersKeep features, themes, makefiles, etc... organized.
$ cat starter-profile/starter.make
api = 2core = 7.x
; Build Kit ===================================================================
includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.x-2.x:/drupal-org.make
; Modules =====================================================================
projects[libraries][subdir] = contribprojects[libraries][version] = 1.0
; Features ====================================================================
projects[feature_core][subdir] = featuresprojects[feature_core][location] = http://fserver.nuvole.org/fserver
; Themes ======================================================================
projects[twist][type] = themeprojects[twist][location] = http://fserver.nuvole.org/fserver
Automating tests
4
Don't depend on trustAutomatically test every component
Meet Continuous Integration (CI)
Use Hudson/Jenkins to automatically test:
1. Makefile
2. Installation
3. Configuration
Building a CI Job
‣ Create a job for testing your site‣ Triggered:
‣ Manually‣ Scheduled‣ By events (git push or other jobs)
‣ A job can consist of ant scripts or simple shell commands (including drush)
Test #1: Make!le
‣ Clone your code from git‣ Run drush make‣ Test that the profile is downloaded‣ Test that modules are placed in the expected
folders
Test #1: Shell commands
‣ drush -y --pipe make distro.make‣ test -d profiles/myproject‣ test -d profiles/myproject/modules/contrib‣ test -d profiles/myproject/modules/custom‣ test -d profiles/myproject/modules/features
Test #2: Installation
‣ Triggered by successful completion of Test #1‣ Run drush site-install:
drush -y site-install ... myproject
‣ Expect successful completion
Test #3: Con!guration
‣ Triggered by successful completion of Test #2‣ Relies on simpletest‣ Run drush test-run‣ Expect successful completion
More on Code-Driven Developmenthttp://nuvole.org/bloghttp://nuvole.org/trainings
Thank You.