Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

@executeInDrupalVm annotation not respected #1582

Closed
bobbygryzynger opened this issue Jun 2, 2017 · 10 comments
Closed

@executeInDrupalVm annotation not respected #1582

bobbygryzynger opened this issue Jun 2, 2017 · 10 comments
Assignees
Labels
Bug Something isn't working

Comments

@bobbygryzynger
Copy link
Contributor

My system information:

Operating system type: macOS
Operating system version: 10.12.5
BLT version: 8.x-dev
Output of blt doctor:

$ blt doctor
Attempting to run doctor on host machine...
[Acquia\Blt\Robo\Tasks\DrushTask]  The drush command 'blt-doctor' could not be found.  Run `drush           [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions. 
[Acquia\Blt\Robo\Tasks\DrushTask]  Exit code 1 
[warning] Unable to run the doctor using alias '@<site>.default.local'. Trying with '@self'...
[warning] Unable to run the doctor using alias '@self'. Trying without alias...
[error]  The drush command 'blt-doctor' could not be found.  Run `drush           [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions. 

When I run this command:

blt frontend

And I expected that my frontend tasks would be run inside the virtual machine. Instead my output indicates the frontend targets are being run on the host machine:

$ blt frontend
> frontend:build
Executing frontend-build target hook...
[ExecStack] gulp build
[16:09:28] Using gulpfile ~/Sites/<site>/gulpfile.js
@grasmash grasmash added 8.9.x Bug Something isn't working labels Jun 2, 2017
@grasmash
Copy link
Contributor

grasmash commented Jun 2, 2017

Is your VM booted?

Unable to run the doctor using alias '@.default.local'.

It strikes me that should work. Have you tested the alias? It looks like BLT cannot ssh into the VM.

Can you test a command like vagrant exec echo "hello world"?

grasmash added a commit to grasmash/bolt that referenced this issue Jun 2, 2017
@grasmash grasmash self-assigned this Jun 2, 2017
@grasmash
Copy link
Contributor

grasmash commented Jun 2, 2017

The drush command 'blt-doctor' could not be found.

That's also weird. Have you tried clearing your drush caches? drush cc drush.

@bobbygryzynger
Copy link
Contributor Author

bobbygryzynger commented Jun 2, 2017

Trying this on a fresh install now.

vagrant exec:

$ vagrant exec echo "hello world"
hello world

drush status:

$ drush @<site>.default.local status
 Drupal version                  :  8.3.2                                                                                                                                              
 Site URI                        :  http://<site>.default.local                                                                                                                       
 Database driver                 :  mysql                                                                                                                                              
 Database hostname               :  localhost                                                                                                                                          
 Database port                   :  3306                                                                                                                                               
 Database username               :  admin                                                                                                                                              
 Database name                   :  <site>_default                                                                                                                                    
 Database                        :  Connected                                                                                                                                          
 Drupal bootstrap                :  Successful                                                                                                                                         
 Drupal user                     :                                                                                                                                                     
 Default theme                   :  bartik                                                                                                                                             
 Administration theme            :  seven                                                                                                                                              
 PHP executable                  :  /usr/bin/php                                                                                                                                       
 PHP configuration               :  /etc/php/5.6/cli/php.ini                                                                                                                           
 PHP OS                          :  Linux                                                                                                                                              
 Drush script                    :  /var/www/<site>/vendor/drush/drush/drush.php                                                                                                      
 Drush version                   :  8.1.10                                                                                                                                             
 Drush temp directory            :  /tmp                                                                                                                                               
 Drush configuration             :  /var/www/<site>/drush/drushrc.php                                                                                                                 
 Drush alias files               :  /var/www/<site>/docroot/../drush/site-aliases/aliases.drushrc.php /var/www/<site>/docroot/../drush/site-aliases/example.acsf.aliases.drushrc.php 
                                    /var/www/<site>/docroot/../drush/site-aliases/example.local.aliases.drushrc.php                                                                   
 Install profile                 :  standard                                                                                                                                           
 Drupal root                     :  /var/www/<site>/docroot                                                                                                                           
 Drupal Settings File            :  sites/default/settings.php                                                                                                                         
 Site path                       :  sites/default                                                                                                                                      
 File directory path             :  sites/default/files                                                                                                                                
 Private file directory path     :  /var/www/<site>/files-private                                                                                                                     
 Temporary file directory path   :  /tmp                                                                                                                                               
 Sync config path                :  /var/www/<site>/config/default  

blt doctor:

$ drush cc drush
'drush' cache was cleared.                                                                                                                                                                                                                                [success]
$ blt doctor
Attempting to run doctor on host machine...
[Acquia\Blt\Robo\Tasks\DrushTask]  The drush command 'blt-doctor' could not be found.  Run `drush           [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions. 
[Acquia\Blt\Robo\Tasks\DrushTask]  Exit code 1 
[warning] Unable to run the doctor using alias '@<site>.default.local'. Trying with '@self'...
[warning] Unable to run the doctor using alias '@self'. Trying without alias...
[error]  The drush command 'blt-doctor' could not be found.  Run `drush           [error]
cache-clear drush` to clear the commandfile cache if you have
installed new extensions. 

blt frontend:

$ blt frontend 
> frontend:build
Executing frontend-build target hook...
[ExecStack] gulp build
[16:30:58] Using gulpfile ~/Sites/<site>/gulpfile.js

grasmash added a commit to grasmash/bolt that referenced this issue Jun 2, 2017
@grasmash
Copy link
Contributor

grasmash commented Jun 2, 2017

What does vagrant status return?

@grasmash
Copy link
Contributor

grasmash commented Jun 2, 2017

These are the two methods that really decide whether the VM is used:


  /**
   * Determines if Drupal VM is initialized for the local machine.
   *
   * I.E., whether Drupal VM is the default LAMP stack for BLT on local machine.
   *
   * @return bool
   *   TRUE if Drupal VM is initialized for the local machine.
   */
  public function isDrupalVmLocallyInitialized() {
    // We assume that if the local drush alias is ${project.machine_name.local},
    // rather than self, then Drupal VM is being used locally.
    $drush_local_alias = $this->getConfigValue('drush.aliases.local');
    $expected_vm_alias = $this->getConfigValue('project.machine_name') . '.local';

    return $drush_local_alias == $expected_vm_alias && file_exists($this->getConfigValue('repo.root') . '/box/config.yml');
  }

  /**
   * Determines if Drupal VM is booted.
   *
   * @return bool
   *   TRUE if Drupal VM is booted.
   */
  public function isDrupalVmBooted() {
    if (!$this->commandExists('vagrant')) {
      return FALSE;
    }

    $result = $this->executor->execute("vagrant status")
      ->printOutput(FALSE)
      ->printMetadata(FALSE)
      ->interactive(FALSE)
      ->run();
    $output = $result->getOutputData();

    return strstr($output, "running");
  }

I wonder if $drush_local_alias == $expected_vm_alias is TRUE for you? The expectation is that ${project.machine_name}.local is the name of your drush alias for your VM.

@bobbygryzynger
Copy link
Contributor Author

vagrant status

$ vagrant status
Current machine states:

octagon                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

@bobbygryzynger
Copy link
Contributor Author

bobbygryzynger commented Jun 2, 2017

Sounds like this is the issue:

I wonder if $drush_local_alias == $expected_vm_alias is TRUE for you? The expectation is that ${project.machine_name}.local is the name of your drush alias for your VM.

I have a different alias for each site. I've set my default alias to the one that connects to sites/default, but this isn't <project.machine_name>.local.

@grasmash
Copy link
Contributor

grasmash commented Jun 2, 2017

So maybe that check is bad?

I need some way to determine if your local machine is configured to use DVM. It's possible that a given project has DVM config created, but a developer would like to opt out and use something else. In this case, they can change drush.aliases.local to @self in project.local.yml and opt-out of VM usage.

@bobbygryzynger
Copy link
Contributor Author

Hmm, yeah that is a little tricky. My knee-jerk response is to say that a top-level config value may be a more straight forward approach, as in:

dvm: true

It would be easy to toggle this off for individual developers and wouldn't rely on comparing config values that don't necessarily have to match otherwise. The current approach requires the developer to change a config value anyway if they want to opt out - this seems to make the relationship more explicit.

To simply its usage, one of the DVM commands could set this value in blt/project.yml during one of the initializing tasks.

@bobbygryzynger
Copy link
Contributor Author

bobbygryzynger commented Jun 2, 2017

Another thought if you'd like to make this more automated, you could always compare the output of vagrant status to project.machine_name. Of course this would have to be done sparingly as retrieving output from vagrant status gets to be pretty slow if you start stacking these commands up.

Here, the developer could have DVM set up locally and halt it if they'd like to opt out, but for this you would have to check if project.machine_name and 'running' appear on the same line.

But really, all of this might not be worth the extra effort if all I really have to do is change an alias name, which really isn't that difficult to do. And I can confirm that this begins to work as expected once that comparison passes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants