Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

85
Automating Drupal Development: Makeles, Features and Beyond Antonio De Marco Andrea Pescetti http://nuvole.org @nuvoleweb

description

Guarda il talk su http://www.youtube.com/watch?v=QEu9JKRehQ8 E dai un giudizio su https://joind.in/talk/view/7699

Transcript of Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Page 2: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Nuvole: Our Team

BELGIUMBrussels

ITALYParma

Page 3: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Clients in Europe and USA

Page 4: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Working with Drupal Distributions

Page 5: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Serving International Organizations

Page 6: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Serving International Organizations

Page 7: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Trainings on Code Driven Development

Page 8: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Automating Drupal Development

1. Automating code retrieval2. Automating installation3. Automating site configuration4. Automating tests

Page 9: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Automating code retrieval

1

Page 10: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Drupal site building blocks

Core

ModulesContributed, Custom, Patched

Themes

External Libraries

Installation Pro!le

Page 11: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

drupal.org github.com

example.com

Page 12: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

The best way to download codeIntroducing Drush Make

Page 13: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 14: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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

Page 15: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

‣ 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

Page 16: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Drush Make can download code

Page 17: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; 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

Page 18: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 19: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; views.make; Usage: ; $ drush make views.make --no-core .;

api = 2core = 7.x

projects[views][subdir] = contribprojects[views][version] = 3.1

Downloading a module

Page 20: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 21: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Drush Make can apply patches

Page 22: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; 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

Page 23: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 24: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Drush Make supports recursion

Page 25: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 26: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 27: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; 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

Page 28: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; flexslider-module.make; Usage: ; $ drush make flexslider-module.make --no-core .;

api = 2core = 7.x

projects[flexslider][subdir] = contrib

Downloading "exslider

Page 29: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 30: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Drush Make supports inclusion

Page 31: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

; 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

Page 32: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Build KitExtendable distribution, reusable .make file

Page 33: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 34: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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

Page 35: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

drush make distro.make

Page 36: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

drush make distro.make

Found myproject.make

Page 37: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

drush make distro.make

Found myproject.make

Run myproject.make

Page 38: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Automating installation

2

Page 39: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Installation Pro!le

Page 40: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 41: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ tree myproject-profile

myproject-profile!"" README.txt!"" distro.make!"" drushrc.php!"" myproject.info!"" myproject.install!"" myproject.make%"" myproject.profile

Installation pro!le components

Page 42: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

‣ 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

Page 43: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

name = Myprojectcore = 7.xdescription = Myproject installation profile.

; Coredependencies[] = bookdependencies[] = field_uidependencies[] = file...

; Contribdependencies[] = admindependencies[] = colorboxdependencies[] = ds...

; Featuresdependencies[] = myproject_coredependencies[] = myproject_blog

myproject.info

Page 44: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

/** * Implements hook_install() */function myproject_install() { // Enable custom theme theme_enable(array('custom_theme')); variable_set('theme_default', 'custom_theme');}

myproject.pro!le

Page 45: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

/** * 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

Page 46: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 47: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

/** * Implements hook_install_tasks() */function myproject_install_tasks() { return array( 'myproject_create_terms' => array( 'display_name' => st('Create taxonomy terms'), ), ... );}

myproject.install

Page 48: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 49: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

/** * 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

Page 50: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 51: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Introducing Drush BakeA Drush command by Nuvole

to create installation profiles based on templates

Page 52: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 53: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ drush bake starter-profile/distro.make myproject

$ git nuvole myproject-profile

$ drush make myproject-profile/distro.make myproject

Bootstrap your project in 3 steps

Page 54: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Automating site con!guration

3

Page 55: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

FeaturesThe best way to package configuration

Page 56: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 57: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

‣ 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?

Page 58: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Con!guration in Database

Page 59: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Packaged as Features

Page 60: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 61: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

A feature can have a .make !le tooDrush Make operates recursively

Page 62: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 63: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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

Page 64: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

How to download your projects from any custom repository

Page 65: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 66: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Introducing Feature ServersKeep features, themes, makefiles, etc... organized.

Page 67: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 68: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 69: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 70: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 71: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

$ 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

Page 72: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Automating tests

4

Page 73: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Don't depend on trustAutomatically test every component

Page 74: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Meet Continuous Integration (CI)

Use Hudson/Jenkins to automatically test:

1. Makefile

2. Installation

3. Configuration

Page 75: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 76: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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)

Page 77: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 78: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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

Page 79: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

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

Page 80: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 81: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Test #2: Installation

‣ Triggered by successful completion of Test #1‣ Run drush site-install:

drush -y site-install ... myproject

‣ Expect successful completion

Page 82: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 83: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

Test #3: Con!guration

‣ Triggered by successful completion of Test #2‣ Relies on simpletest‣ Run drush test-run‣ Expect successful completion

Page 84: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Page 85: Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond

More on Code-Driven Developmenthttp://nuvole.org/bloghttp://nuvole.org/trainings

Thank You.