Drush is a command line tool that allows interaction with a Drupal site. The tool itself is incredibily useful and provides mechanisms to download modules, backup databases and most other things that can be done with Drupal. Drush Make was a plugin for Drush which has now become part of the Drush core and allows Drupal sites to be created via a make file. What Drush Make does is to use the make file to download the modules, themes and libraries needed for a Drupal site ready for the site to be installed. This means you can give this make file to another developer who can then build their own Drupal site.
Installing Drush Make
As of Drush version 5 Drush Make is now part of the Drush core code so getting up and running is easy. Prior to Drush version 5 you had to install Drush Make separately, but the install process wasn't that difficult really. Just create a folder in your home directory called .drush and place the drush make files in there. When finished you should end up with a file like ~/.drush/drush_make/INSTALL.txt.
If you have installed Drush via pear then you will have Drush Make built in.
Anatomy Of A Make File
A Drush Make file has a quite simple format, which is split into a number of different sections. How many sections you use depends on what you need to use in your Drupal build. The bare minimum needed for a make file is the core project version, but you can add module, theme and library information on top of this.
The core parameter defines the major version of Drupal that this make file will create. To create a project for a Drupal 6 build you would enter 6.x, and for Drupal 7 you would enter 7.x. A make file must always contain this information.
core = 7.x
This is the API version of Drush Make, which also must be included in every file. The current version is '2'.
api = 2
This is the main part of the make file and defines the different modules and themes that will be downloaded when the make file is run. If your build file is to be used to download the Drupal core files then you must include an instruction to do that, so this is a good place to start with the projects setting. To include the latest (stable) release of Drupal in your build do the following:
projects = drupal
You can change this to any project name to include that project in your build. For example, to include the latest version of the Views module you would do the following:
projects = views
Once you have the item in the projects list then you can set certain options for it. For example, to set a specific version for the item you add the version attribute to the list, much like you would in PHP. The following sets a specific version of Drupal that wll be used in this install.
projects[drupal][version] = 7.15
You can also set just the major version here if you want to get the latest version of the project.
projects[drupal][version] = 7
The shorthand for setting the version is to simply omit the version attribute, it is assumed that this is the latest version if no other options are supplied.
projects[drupal] = 7
Sometimes it is necessary to apply patches to code, and it is best to do this automatically rather than rely on applying them manually when the site is rebuilt. Drush Make can apply a patch file to a module automatically by using the patch reference and a URL to the patch file.
projects[amodule][patch] = "http://drupal.org/files/issues/amoule.patch"
This directive will change the default location of the directory that the module files will be downloaded to. By default this will be set to "sites/all/modules". The following will set the directory that the CTools module will be placed in to "sites/all/modules/contrib/ctools".
projects[ctools][subdir] = "contrib"
The default behaviour of Drush Make is not to overwrite files if they already exist, in fact, it will flag an error if the directory already exists. This can be changed by setting the overwrite property to TRUE.
projects[amodule][overwrite] = TRUE
libraries[ckeditor][download][type] = "file" libraries[ckeditor][download][url] = "http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.3/ckeditor_3.6.3.zip"
To add a comment to a Drush Make file you just need to add a semi-colon (;)to the start of the line. This is useful if you want to add a header to the file so that you know what it will do, or if you wish to split the file into sections for core, module, theme and library elements.
There are plenty of other options available here and I haven't touched on them all and going through them is almost unnecessary. I have mainly looked at the most commonly used or useful ones but you can change the way the above commands work, as well as do other things like include a make file from a make file. For a full list you can look at the Drush Make readme file.
Creating A Make File
Creating a large make file from scratch is a little tedious (and scary to the newcomer), but there is a short cut that will allow the generation of a make file from an existing Drupal site. When you have set up your Drupal site you can generate a make file for it by using the make-generate drush command. The following will generate a make file called mysite.make in the root of the Drupal build.
drush make-generate mysite.make
On a fresh install of Drupal the above command would create the following make file.
; This file was auto-generated by drush make core = 7.x api = 2 projects[drupal][version] = "7.x"
Once you have this generated you can regenerate it as much as you need, just be warned that if you edit the file it will be overwritten if you regernate it again later. When you enable modules and regenerate the make file you will see those modules added to the make file. To demonstrate this I downloaded and enabled the Views and CTools modules and then regenerated the make file.
; This file was auto-generated by drush make core = 7.x api = 2 projects[drupal][version] = "7.x" ; Modules projects[ctools][subdir] = "contrib" projects[ctools][version] = "1.0" projects[views][subdir] = "contrib" projects[views][version] = "3.3"
Using A Make File
This is where the main power of DrushMake lies, and is probably the easiest part of the whole process. To use a make file with make you just need to run the following command.
drush make mysite.make
Drush Make will then create a Drupal site using the make file as a blueprint. Every time a project is downloaded a notification is printed out on screen so you can easily see that the make file is doing everything it should be. If any problems arise (like missing files or permissions issues) they will also be reported.
Of course, knowing how to use Drush Make is only half of the process. As with any tool of this nature it is only powerful if you use it in the right ways. I have hinted at some strategies of how to get the most out of Drush Make at the start of this post, but I thought I would devote a section to detail some of the things I have learnt whilst using Drush in my day job.
First and foremost, the main benefit of using Drush Make is a massive simplification of source control. Before I started using Drush Make I would add all Drupal source code files, module files and theme files into source control, which would lead to a large overhead in the code that I had to manage.
To simplify this you only need to add your custom files and a make file that will build the rest of the site around these files to your source control management. Taking an example, lets say I was building a site that contained a module called mymodule. My site source code would only contain that module and a make file that built the rest of the site around this module. The directory structure of the source code would look something like this.
sites --all ----modules ------custom --------mymodule ----------mymodule.module ----------mymodule.info mysite.make
I have put the make file in the site root, but it doesn't necessarily need to go here. You can put it in as part of a profile or even just outside of the web root. If you do put it outside the web root you can reference it like this.
drush make ../mysite.make
It is even possible to go one step beyond this and only have the make file that pulls in your custom module files from another source control location. You can currently use Bazaar, CVS, SVN or Git source control systems to include code within a make file.
Drush Make will only download the source files for a project and this does not include any form of configuration or settings. Using it in conjunction with Features allows sites to be built entirely from the ground up. This means you can get a fully working replica of a site via the command line in just three commands.
$ drush make mysite.make $ drush si --account-name=admin --account-pass=admin --db-url=mysql://user:[email protected]/dbname $ drush en mymodule --yes
Here's My Make File
Giving a developer a make file means that they can pull in the needed libraries and modules before enabling a module. Many modules with complex setups now come with make files so that developers can run them and pull in everything needed rather than having to go to multiple resources one at a time and downloading them manually.
Make, Update, Test, Deploy
Once a site has been built and put live you might have the need to update it at some point. You can update your module and core code and ensure that everything works before writing the configback into the make file. With this updated file in hand you can put your site in maintenence mode and apply the code changes before running your database updates.
A few resources to help you out when getting to grips to Drush and Drush Make.
; Use Pressflow instead of Drupal core: ; projects[pressflow][type] = "core" ; projects[pressflow][download][type] = "file" ; projects[pressflow][download][url] = "http://launchpad.net/pressflow/6.x/6.15.73/+download/pressflow-6.15.73.tar.gz"