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

866 views

Published on

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

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
866
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

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

  1. 1. Automating Drupal Development: Makefiles, Features and Beyond Andrea Pescetti Antonio De Marco http://nuvole.org @nuvoleweb
  2. 2. Nuvole: Our TeamBELGIUM ITALY Brussels Parma
  3. 3. Clients in Europe and USA
  4. 4. Working with Drupal Distributions
  5. 5. Serving International Organizations
  6. 6. Serving International Organizations
  7. 7. Trainings on Code Driven Development
  8. 8. Automating Drupal Development1. Automating code retrieval2. Automating installation3. Automating site configuration4. Automating tests
  9. 9. 1Automating code retrieval
  10. 10. Core ModulesContributed, Custom, Patched Themes External LibrariesInstallation Profile Drupal site building blocks
  11. 11. drupal.org github.com example.com
  12. 12. The best way to download code Introducing Drush Make
  13. 13. Drush MakeDrush make is a Drush command thatcan create a ready-to-use Drupal site,pulling sources from variouslocations. In practical terms, thismeans that it is possible to distributea complicated Drupal distribution as asingle text file.
  14. 14. 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...
  15. 15. Drush Make can download code
  16. 16. Minimal makefile: core only; distro.make; Usage:; $ drush make distro.make [directory];api = 2core = 7.xprojects[drupal][type] = coreprojects[drupal][version] = "7.7"
  17. 17. Minimal makefile: core only$ drush make distro.make myprojectdrupal-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
  18. 18. Downloading a module; views.make; Usage:; $ drush make views.make --no-core .;api = 2core = 7.xprojects[views][subdir] = contribprojects[views][version] = 3.1
  19. 19. 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...
  20. 20. Drush Make can apply patches
  21. 21. Applying patches; distro.make; Usage:; $ drush make distro.make [directory];api = 2core = 7.xprojects[drupal][type] = coreprojects[drupal][version] = "7.7"; Make system directories configurable to allow tests in profiles/[name]/modules; 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-al...
  22. 22. Applying patches$ drush make distro.make myprojectdrupal-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
  23. 23. Drush Make supports recursion
  24. 24. flexslider / flexslider.make; Flex Sliderapi = 2core = 7.xlibraries[flexslider][download][type] = "get"libraries[flexslider][download][url] = "https://github.com/.../zipball/master"libraries[flexslider][directory_name] = "flexslider"libraries[flexslider][type] = "library"
  25. 25. Downloading flexslider; flexslider-module.make; Usage:; $ drush make flexslider-module.make --no-core .;api = 2core = 7.xprojects[flexslider][subdir] = contrib
  26. 26. Recursive makefile parsing$ 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.makeflexslider downloaded from https://github.com/.../zipball/master.$ tree -l sites/all/sites/all/!"" libraries#   %"" flexslider...%"" modules %"" contrib %"" flexslider...
  27. 27. Drush Make supports inclusion
  28. 28. Including an external makefile; 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
  29. 29. Build KitExtendable distribution, reusable .make file
  30. 30. Your project: 2 make files‣ 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
  31. 31. drush make distro.make
  32. 32. Found myproject.makedrush make distro.make
  33. 33. Run myproject.makeFound myproject.makedrush make distro.make
  34. 34. 2Automating installation
  35. 35. Installation Profile
  36. 36. Installation profile components$ tree myproject-profilemyproject-profile!"" README.txt!"" distro.make!"" drushrc.php!"" myproject.info!"" myproject.install!"" myproject.make%"" myproject.profile
  37. 37. Profiles: just like modules ‣ 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
  38. 38. myproject.infoname = Myprojectcore = 7.xdescription = Myproject installation profile.; Coredependencies[] = bookdependencies[] = field_uidependencies[] = file...; Contribdependencies[] = admindependencies[] = colorboxdependencies[] = ds...; Featuresdependencies[] = myproject_coredependencies[] = myproject_blog
  39. 39. myproject.profile/** * Implements hook_install() */function myproject_install() { // Enable custom theme theme_enable(array(custom_theme)); variable_set(theme_default, custom_theme);}
  40. 40. myproject.profile/** * 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] = info@drupalissimo.com; $form[admin_account][account] [name][#default_value] = admin; $form[admin_account][account] [mail][#default_value] = dev@nuvole.org; $form[update_notifications] [update_status_module][#default_value] = array(1 => FALSE, 2 => FALSE}
  41. 41. myproject.install/** * Implements hook_install_tasks() */function myproject_install_tasks() { return array( myproject_create_terms => array( display_name => st(Create taxonomy terms), ), ... );}
  42. 42. 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); }}
  43. 43. Introducing Drush Bake A Drush command by Nuvoleto create installation profiles based on templates
  44. 44. Installation profile template$ git clone git.nuvole.org:/var/git/starter-profile.git...$ tree starter-profilestarter-profile/!"" README.txt!"" distro.make!"" drushrc.php!"" starter.info!"" starter.install!"" starter.make%"" starter.profile
  45. 45. Bootstrap your project in 3 steps$ drush bake starter-profile/distro.make myproject$ git nuvole myproject-profile$ drush make myproject-profile/distro.make myproject
  46. 46. 3Automating site configuration
  47. 47. FeaturesThe best way to package configuration
  48. 48. What is a feature?‣ 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
  49. 49. Configuration in Database
  50. 50. Packaged as Features
  51. 51. A feature can have a .make file too Drush Make operates recursively
  52. 52. api = 2core = 7.x; Modules =====================================================================projects[colorbox][subdir] = contribprojects[colorbox][version] = 1.0-beta4projects[insert][subdir] = contribprojects[insert][version] = 1.1; Libraries ===================================================================libraries[colorbox_library][download][type] = "get"libraries[colorbox_library][download][url] = "http://colorpowered.com/colorbox/libraries[colorbox_library][directory_name] = "colorbox"libraries[colorbox_library][destination] = "libraries" feature_core.make A feature can specify where to find its own dependencies
  53. 53. How to download your projects from any custom repository
  54. 54. $ cat starter-profile/starter.makeapi = 2core = 7.x; Build Kit ===================================================================includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.x; 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
  55. 55. Introducing Feature ServersKeep features, themes, makefiles, etc... organized.
  56. 56. $ cat starter-profile/starter.makeapi = 2core = 7.x; Build Kit ===================================================================includes[] = http://drupalcode.org/project/buildkit.git/blob_plain/refs/heads/7.x-; 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
  57. 57. 4Automating tests
  58. 58. Dont depend on trust Automatically test every component
  59. 59. Meet Continuous Integration (CI)Use Hudson/Jenkins to automatically test: 1. Makefile 2. Installation 3. Configuration
  60. 60. 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)
  61. 61. Test #1: Makefile‣ Clone your code from git‣ Run drush make‣ Test that the profile is downloaded‣ Test that modules are placed in the expected folders
  62. 62. 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
  63. 63. Test #2: Installation‣ Triggered by successful completion of Test #1‣ Run drush site-install: drush -y site-install ... myproject‣ Expect successful completion
  64. 64. Test #3: Configuration‣ Triggered by successful completion of Test #2‣ Relies on simpletest‣ Run drush test-run‣ Expect successful completion
  65. 65. Thank You.More on Code-Driven Developmenthttp://nuvole.org/bloghttp://nuvole.org/trainings

×