drupal-boilerplate icon indicating copy to clipboard operation
drupal-boilerplate copied to clipboard

drushrc.php modification to load from Git repo root doesn't work with Drush aliases

Open davereid opened this issue 10 years ago • 6 comments

I have a local system alias that points to a drupal-boilerplate site's docroot. This site also has it's own drush configuration file located at /var/www/mysite.com/drush/drushrc.php.

// ~/drush/local.drush.aliases.drushrc.php
$aliases['mysite'] = array(
  'root' => '/var/www/mysite.com/docroot',
  'uri' => 'http://mysite.com/',
);

If I were to run the drush @local.mysite status config command from my home directory (and not anything from inside the mysite.com directory), this is what I get for my drush output:

drush @local.lullabot status config
 PHP configuration     :  /etc/php5/cli/php.ini                  
 Drush configuration   :  /home/davereid/.drush/drushrc.php 

This is the bug. It should be including the file from /var/www/mysite.com/drush/drushrc.php. This is the expected output:

drush @local.lullabot status config
 PHP configuration     :  /etc/php5/cli/php.ini                                                
 Drush configuration   :  /var/www/mysite.com/drush/drushrc.php 
                          /home/davereid/.drush/drushrc.php

davereid avatar Jul 09 '14 22:07 davereid

Basically it looks like drush_get_option('root') only works if you literally are passing a --root option to Drush. It does not provide us with the selected alias' root directory.

davereid avatar Jul 09 '14 22:07 davereid

The following is what I've gotten to work for me. I broke out things into separate sub-functions for understandability.

https://gist.github.com/davereid/45df5478b5154c73f737

davereid avatar Jul 09 '14 22:07 davereid

This is by design. It's not supposed to work outside of a Drupal root, unless you specifically pass --root. This is a helper for local development, it's not really meant outside of that.

On Wednesday, July 9, 2014, Dave Reid [email protected] wrote:

The following is what I've gotten to work for me. I broke out things into separate sub-functions for understandability.

https://gist.github.com/davereid/45df5478b5154c73f737

— Reply to this email directly or view it on GitHub https://github.com/Lullabot/drupal-boilerplate/issues/32#issuecomment-48545290 .

James Sansbury | Development Manager | Lullabot o: (877) 585-5226 x 722 e: [email protected] t: twitter.com/q0rban w: lbt.me/q0rban

q0rban avatar Jul 09 '14 23:07 q0rban

To elaborate, now that I'm not reading this from my phone… ;)

This looks like some great work here, @davereid!

The point of this drushrc snippet is simply so that you can quickly spin up new sites for lots of different projects on your local development environment without having to muck around with your personal aliases.drushrc.php file. As you can see on the original post by grayside, the purpose of this isn't to avoid properly setting up drush aliases in the actual environments themselves, only to simplify and ease the transition between lots of projects in local development. You can read my comment on that post about the addition of the --root option.

My inclination is to leave this as is and just add some clarifying text about the purpose of this code. It's really not meant for non-development environments—If you need aliases to work as you expect on those environments, then you should configure them directly in the aliases.drushrc.php file. Anything else is too much magic, IMO, and will just cause frustration when something isn't working as is expected.

q0rban avatar Jul 10 '14 00:07 q0rban

Hrm, that's a really fair point. I think @bchavet and I were experiencing issues because the server didn't have the original modification to drushrc.php in place, and we didn't see that the deployment script we were using actually did a cd <root of alias> before running any other commands.

I could easily just code the includes in my alias file kind of using the same code and it does seem to work.

$local_sites = array(
  'mysite' => 'mysite.com',
);
foreach ($local_sites as $local_alias => $local_domain) {
  if (is_dir('/var/www/' . $local_domain)) {
    $aliases[$local_alias] = array(
      'root' => '/var/www/' . $local_domain,
      'uri' => 'http://' . $local_domain . '/',
    );
    if ($repo_root = _drushrc_find_repo_root($aliases[$local_alias]['root'])) {
      if (is_dir($repo_root . '/drush')) {
        if (is_file($repo_root . '/drush/drushrc.php')) {
          $aliases[$local_alias]['config'] = $repo_root . '/drush/drushrc.php';
        }
        if (is_dir($repo_root . '/drush/commands')) {
          $aliases[$local_alias]['include'] = $repo_root . '/drush/commands';
        }
        if (is_dir($repo_root . '/drush/aliases')) {
          $aliases[$local_alias]['alias-path'] = $repo_root . '/drush/aliases';
        }
      }
    }
  }
}

davereid avatar Jul 10 '14 01:07 davereid

On the plus side, I know way more about the Drush bootstrap and configuration loading process now.

davereid avatar Jul 10 '14 01:07 davereid