When a site goes live, are you crossing your fingers or are you confident that everything is configured? Are you looking to manage and optimize site deployments like any other operational process? Do you find it impossible to create development, test and production environments that act the same every time? Do you have a custom set of modules or configurations that you rely on for all your sites?
This session will teach you how to optimize your site deployments with open tools such as drush, drush make, features, leveraging software versioning systems such as subversion and git. Beyond these projects, the session will train you to develop your own custom modules for consistent and precise deployments including variables, users, content types, nodes, imagecache presets, menus, blocks, theme configuration, and more.
Using these techniques you can automate and optimize your deployment procedures, giving you technical flexibility and saving valuable time.
Redesigned, revised and streamlined for DrupalCamp Toronto 2011.
Optimize Site Deployments with Drush v2 (DrupalCamp Toronto 2011)
1. Optimize Site Deployments with Drush
Saturday, 2011.11.12 – Drupal Camp Toronto 2011
Jon Peck, Owner, FluxSauce.com
Audience: Intermediate
Revision 2.
2. Who am I?
Jon Peck
Founded web application
development firm
FluxSauce
Zend Certified PHP
Engineer
Web development since
1998
Used Drupal for the last
three years
3. Overview
Why should you script site deployments?
What are drush and drush make, and how can you use
them?
What are features, and does it fit your needs?
What are some recommended site deployment
strategies?
How can you develop your own strategy?
4. Why script site deployments?
Reliability
Track changes over time
(including blame)
Support multiple tiers
Manage and optimize your
operations
"Aaahhh!!!", CC BY 2.0 by Evil Erin @ flickr
5. What is drush?
drush is a
command
line shell
and
scripting
interface
for Drupal.
6. What can you use drush for?
Manage modules Manipulate and extract site
variables
Manage users
Execute MySQL queries using
Execute Drupal commands Drupal config
7. What is drush make?
A standard
recipe for
downloading
everything
you need for
a site
installation.
8. Three steps for deployment
Get the files (drush make)
drush -y make --no-patch-txt "PATH/drush.make" FOLDER
2. Install and configure (drush)
cd FOLDER
drush -y site-install --config="PATH/drushrc.ENV.php”
3. Enable modules (drush)
drush -y en
admin_menu
ctools ...
11. What can you use features for?
Within your site (GUI)
Leveraging drush (command line)
12. What are features’ limitations?
Imperfect exports
No site variables without
third-party modules
No theme, block support
No control logic
If you can't do it in the
GUI...
"40+296 Hello?", CC BY 2.0 by Bark @ flickr
13. Custom modules for granular control
With hook_install(), you can programmatically…
Create users, roles, permissions
Create and hide blocks
Create content (nodes)
Import content types / CCK
Create vocabularies and terms (fields)
Set site variables (drush vget)
Import views
14. Custom module “gotchas”
Custom modules used like this need a user associated
drush -u 1 -y en custom_module
Clear all caches after installing your custom module
drush cc all
Changes and updates need to go in hook_update_N
within your module
15. Deployment strategies
Store everything in a versioning system
Always backup both your scripts and database first!
Tiered development strategy
Unique database credentials for each tier
When in doubt, rebuild on dev first
Instead of repeating steps, do it in code
Document the process
16. How can I do this?
Get drush
Get drush_make
Define your needs.
Build and document your module toolbox
Start small, then scale up
17. "Question mark in Esbjerg", CC BY-SA 2.0 by Alexander Drachmann @ flickr
Questions?
Note: I have not used these techniques with Apache Ant or
phpUnderControl.
18. Thank you!
drush
http://drupal.org/project/drush
drush_make
http://drupal.org/project/drush_make
Drupal Deployment Skeleton (DDS) jpeck@fluxsauce.com
http://goo.gl/09JkE (gitHub) @FluxSauce
http://fluxsauce.com
drush make Generator
http://drushmake.me
permissions_api
http://drupal.org/project/permissions_api
Traditional Development... Practice for Software
Development
http://dltj.org/article/software-development-practice
Notas del editor
PHP 4 & 5Senior software engineer, development manager and systems administratorStarted using Drupal for sites on the side
This presentation is a result of working on multiple sites and trying to reign in both the entropy associated with deployments and out of frustration from having to keep reconfiguring details.The script examples I will be showing use bash, but you can probably do something very similar with Windows if you were so inclined.There are three primary modules that I will highlight today; drush, drush make, and features.The features module is an extremely powerful tool, but it is in no means the final solution. I'll explore both the good and the bad of features.There's many ways to deploy sites; I'll discuss the way I currently do it based on my experience, both working with a in-house, distributed and one-person team. No size fits all, some sizes fit most, and every client is unique. With that said, I hope that these strategies can be incorporated into your deployments and make your life easier.
When you deploy a site, are you crossing your fingers? Do you know exactly what's going to happen? Did you remember every last variable, setting, configuration, module and theme?Leverage software versioning systems to store your configurations.How many people here already use a system like SVN or git?Separate configurations for development, staging and productionYou can track how long it takes to do things, document why something was done, and constantly improve the process
Drush is a back end tool - a command line shell and scripting interface for Drupal.Easy, fast interface for administrative tasks Originally designed for Drupal 4, it has been maintained and expanded to support Drupal 5, 6 and 7Many modules include support for DrushThis is an example of the status command
Download, enable, disable modulesCreate, block or cancel users, set passwords, add or remove rolesClear cache, flush images, index search items, update database…Very useful for building custom modules that configure your siteExcellent for debuggingNotice how it also automatically downloaded the dependency, FirePHP
drush make is an extension that uses a parsed configuration to create a ready-to-use drupal site, downloading from sources as neededCore and contrib from Drupal.orgChecking out code from CVS, SVN, git, and bzr reposGet archives for librariesDoes not require databaseIt can play nice with installation profiles, but I have not had a need to develop my own using this strategy.It is compatible with Acquia Drupal and Pressflow.Using drush, you can export a drush make configuration from your existing site. drush generate-makefileThe website, drushmake.me is a graphical user interface that generates drush make files
Get the files using drush make. It uses a configuration file; this is same for all environments.Install and configure. You can specify a particular configuration specific to an environmentEnable modules using drush
Much like many of you, I have to deal with a large number of sites on a regular basis. With that comes the overhead of keeping track of configurations, variables, tweaks and the such.In response, I developed the Drupal Deployment Skeleton to facilitate the rapid deployment and development of commercial sites. It's available as open-sourced through github so you can leverage it to allow you to create your own scriptable deployments. I filled the skeleton with numerous examples,You must customize these scripts to your environment to be able to use it; this is not a turnkey package.drush.*.php - Site configurations for drushdrush.make - drush make configurationconfig.ini - For each environment, defines where config is and where the site will goinstall.sh - Performs the actual installation, similar to simplest example setup.sh - Gets path, loads configuration, verifies configurationrebuild.sh - After prompt, destroys database and removes site, then reinstalls
Features is a module that captures and manages a collection of Drupal entitiesIt includes both a graphical user interface and APIBundles exportable components into a single moduleVery Easy to use
Within your site:Site contentContent typesUsersRolesModule dependenciesimagecache presetsMenusPermissionsUsing drush:List all available featuresUpdate code of existing feature to include DB changes - drushfuRevert to feature defaultsShow a diff
Publishing preference, for example - told it not to publish on the front page, does it anywayYou have to keep going over the same changes time and time again. Strongarm exposes some variables, but not all.Themes and blocks have to be manually changed and updated.It's a blunt force instrument, and therefore doesn't handle logic or precedence, like do not do X if Y existsIt's a great tool, but if you can't do it in the GUI, your hands are going to get dirty.Fortunately, there is another way.
Beyond the site administrator - the first user, you often will have roles that you want to place your client's users in.For brochure websites in particular, I disable the login block. Depending on the design needs of the client, I will also remove the "Powered by Drupal" block. While you want your client to maintain their own content, often you have static content, pages usually, that you want to populate the site with.Content Construction Kit is a great and easy way to create new content types; you can export them with the UI and import them programatically. Do you use taxonomies to categorize your content? You can easily create vocabularies and terms out of the box.Leverage drush'svget, variable get command to keep track of before and after configuration changes with a quick diff Create WYSIWYG profiles - use them across multiple sites!Imagecache profilesRather than making you suffer through a bunch of dry examples, they are at the end of the presentation and you can download the slides at your leisure.Store your module in your favorite repository
This is one I learned from hard experience - Some operations require a user to be associated, so enable your custom module separately, explicitly specifying UID 1.
Even if you're a one man shop Backup - especially in production, before making any changes Tiered: Development - working environment for individual developers or small teams. Can also include integration, where the entire team's work is combined and validated.Staging - identical to production as possible, simulating actual release. Also good for demonstration and training.Production - Public facing deployment.Tiering - this can dovetail into a larger discussion of software versioning and branching Make sure everything works the way you want it toYou ultimately want someone else to be able to do this for you
The Drush manual is a bit overwhelming, but just search in the page and you'll get the hang of it.Drush make is also well documented; their examples are well worth looking at.What exactly are you trying to accomplish? Are you putting a skeleton in place for your client to fill, or do you have all content already?Cluster it by purpose.Ex: I need imagecache, galleria, cck, file, image, and jquery_update for an image gallery.Get files, install and configure, enable modules
----- Meeting Notes (11/12/11 12:11) -----synchronizing contentproduction to