Over the last couple of days an internal thread has been making the rounds at Acquia about speeding up Composer for Drupal builds. With Drupal 8, Lightning and the BLT project making heavy use of Composer to manage its dependencies, users frequently rebuilding from source, or those in remote regions with slow internet face a lot of dead time.

Within the discussion, someone mentioned Toran Proxy which acts as a mirror for Packagist, GitHub and other repositories that store code libraries. Because I live in Australia, the available bandwidth to external repositories is sometimes extremely slow; this lead me to try Toran out.

My home development server uses Fedora 19 (Schrödinger’s Cat) and it's a place I frequently try out scripts, applications and other tooling to both verify it does what it says, and keep a technical eye in as my career drifts ever further away. I was able to translate the download/configuration instructions into a Puppet manifest and have Toran deployed on my server in relatively short time however ran into issues with ensuring BLT (which uses packages.drupal.org) downloaded packages from the right places.

In the end, the solution which worked for me was to patch one line in one file (src/Toran/ProxyBundle/Command/CronCommand.php) of Toran Proxy, whilst ensuring I continually ran Toran's inbuilt cron to generate the right resources for my local build to pull in. Prior to doing this I was running into dependency issues that lead me down seven or eight different garden paths. My definitive guide to getting Toran Proxy set up with BLT is as follows and presumes all initial instructions provided by the Toran Proxy team have been followed:

Apply the attached patch

Navigate to the /settings page and use the following image as a rough guide for configuring your instance

Run Toran cron by executing php bin/cron -v

Alter your BLT composer.json to use the following (changing the repo URL from toran.adammalone.net to the domain your toran instance runs on and removing the secure-http parameter if your mirror uses HTTPS)

"config": { "secure-http": false }, "repositories": { "0": { "type": "composer", "url": "http://toran.adammalone.net/repo/private/" }, "1": { "type": "composer", "url": "http://toran.adammalone.net/repo/packagist/" }, "2": { "packagist": false } },

Cross your fingers and run composer install

If any parts of the build fail, examine your app/toran/config.yml file and ensure that all the Drupal packages (except Coder) are tagged with packages.drupal.org and all non-Drupal packages are tagged with packagist.org.

Create a new entry in crontab to run the Toran cron as frequently as desired so packages are continually updated.

Your mileage may vary, but I was able to reduce a 40 minute build down to around 8 minutes as my laptop was sourcing libraries from a server 3 metres away rather than the other side of the World. The only slow downs for me were packages tagged with '*' or '-dev' as they bypass Toran and don't get added to my local cache.