Skip to content

Commit

Permalink
Warn user forcefully when executing commands outside VM.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Mar 5, 2018
1 parent 9db8baa commit 69a360f
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Robo/Commands/Doctor/DoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DoctorCommand extends BltTasks {
* @command doctor
*
* @launchWebServer
* @executeInVm
*/
public function doctor() {
$this->doctorCheck();
Expand Down
4 changes: 4 additions & 0 deletions src/Robo/Commands/Frontend/FrontendCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FrontendCommand extends BltTasks {
*
* @command source:build:frontend
* @aliases sbf frontend
* @executeInVm
*/
public function frontend() {
$this->invokeCommands([
Expand All @@ -27,6 +28,7 @@ public function frontend() {
*
* @command source:build:frontend-assets
* @aliases sbfa frontend:build
* @executeInVm
*/
public function assets() {
return $this->invokeHook('frontend-assets');
Expand All @@ -37,6 +39,7 @@ public function assets() {
*
* @command source:build:frontend-reqs
* @aliases sbfr frontend:setup
* @executeInVm
*/
public function reqs() {
return $this->invokeHook('frontend-reqs');
Expand All @@ -51,6 +54,7 @@ public function reqs() {
* @todo add alias for tests:frontend.
*
* @launchWebServer
* @executeInVm
*/
public function test() {
return $this->invokeHook('frontend-test');
Expand Down
1 change: 0 additions & 1 deletion src/Robo/Commands/Generate/AliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class AliasesCommand extends BltTasks {
*
*/
public function generateAliasesAcquia() {

$this->cloudConfDir = $_SERVER['HOME'] . '/.acquia';
$this->setAppId();
$this->cloudConfFileName = 'cloud_api.conf';
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Commands/Setup/AllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AllCommand extends BltTasks {
* Executes source:build:* and installs Drupal via setup.strategy.
*
* @command setup
* @executeInVm
*/
public function setup() {
$this->say("Setting up local environment for site <comment>{$this->getConfigValue('site')}</comment>.");
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Commands/Setup/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BuildCommand extends BltTasks {
* @validateDrushConfig
* @validateMySqlAvailable
* @validateDocrootIsPresent
* @executeInVm
*
* @todo Add a @validateSettingsFilesArePresent
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Robo/Commands/Setup/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ConfigCommand extends BltTasks {
*
* @command drupal:update
* @aliases du setup:update
* @executeInVm
*/
public function update() {
$this->invokeCommands(['drupal:config:import', 'drupal:toggle:modules']);
Expand All @@ -28,6 +29,7 @@ public function update() {
* @aliases dci setup:config-import
*
* @validateDrushConfig
* @executeInVm
*/
public function import() {
$strategy = $this->getConfigValue('cm.strategy');
Expand Down
1 change: 0 additions & 1 deletion src/Robo/Commands/Setup/DrupalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class DrupalCommand extends BltTasks {
*
* @validateMySqlAvailable
* @validateDrushConfig
* @executeInDrupalVm
* @hidden
*
* @return \Robo\Result
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Commands/Setup/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ImportCommand extends BltTasks {
* @aliases dsi
*
* @validateDrushConfig
* @executeInVm
*/
public function import() {
$task = $this->taskDrush()
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Commands/Setup/ToggleModulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ToggleModulesCommand extends BltTasks {
* @aliases dtm toggle setup:toggle-modules
*
* @validateDrushConfig
* @executeInVm
*/
public function toggleModules() {
if ($this->input()->hasArgument('environment')) {
Expand Down
9 changes: 5 additions & 4 deletions src/Robo/Commands/Sync/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SyncCommand extends BltTasks {
* SSH forwarding.
*
* @command drupal:sync:all-sites
*
* @aliases dsa sync:all
* @executeInVm
*
* @see https://github.com/acquia/blt/issues/1875
*/
Expand All @@ -43,8 +43,8 @@ public function allSites() {
* for each multisite.
*
* @command drupal:sync:default:site
*
* @aliases ds drupal:sync:default sync sync:refresh
* @executeInVm
*/
public function sync($options = [
'sync-files' => FALSE,
Expand All @@ -65,6 +65,7 @@ public function sync($options = [
* @aliases dsf sync:files
*
* @validateDrushConfig
* @executeInVm
*
* @todo Support multisite.
*/
Expand All @@ -90,8 +91,8 @@ public function syncFiles() {
* Iteratively copies remote db to local db for each multisite.
*
* @command drupal:sync:db:all-sites
*
* @aliases dsba sync:all:db
* @executeInVm
*/
public function syncDbAllSites() {
$exit_code = 0;
Expand Down Expand Up @@ -122,8 +123,8 @@ public function syncDbAllSites() {
* @command drupal:sync:default:db
*
* @aliases dsb drupal:sync:db sync:db
*
* @validateDrushConfig
* @executeInVm
*/
public function syncDb() {
$local_alias = '@' . $this->getConfigValue('drush.aliases.local');
Expand Down
2 changes: 2 additions & 0 deletions src/Robo/Commands/Tests/BehatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function initialize() {
* @validateBehatIsConfigured
* @validateVmConfig
* @launchWebServer
* @executeInVm
*/
public function behat() {
// Log config for debugging purposes.
Expand Down Expand Up @@ -125,6 +126,7 @@ public function behat() {
* @aliases tbd tests:behat:definitions
*
* @validateMySqlAvailable
* @executeInVm
*/
public function behatDefinitions($options = ['mode' => 'l']) {
$task = $this->taskBehat($this->getConfigValue('composer.bin') . '/behat')
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Commands/Tests/SecurityUpdatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SecurityUpdatesCommand extends BltTasks {
*
* @command tests:security:check:updates
* @aliases tscu security tests:security-updates
* @executeInVm
*/
public function testsSecurityUpdates() {
$result = $this->taskDrush()
Expand Down
37 changes: 37 additions & 0 deletions src/Robo/Hooks/DrupalVmHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Acquia\Blt\Robo\Hooks;

use Acquia\Blt\Robo\BltTasks;
use Consolidation\AnnotatedCommand\AnnotationData;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Acquia\Blt\Robo\Exceptions\BltException;

/**
* This class defines hooks that provide user interaction.
*/
class DrupalVmHook extends BltTasks {

/**
* Ask whether user would like to execute on host machine.
*
* @hook interact @executeInVm
*/
public function interactExecuteOnHost(
InputInterface $input,
OutputInterface $output,
AnnotationData $annotationData
) {
if (!$this->getInspector()->isVmCli() && $this->getInspector()->isDrupalVmLocallyInitialized()) {
$this->logger->warning("Drupal VM is locally initialized, but you are not inside the VM.");
$this->logger->warning("You should execute all BLT commands from within Drupal VM.");
$this->logger->warning("Use <comment>vagrant ssh</comment> to enter the VM.");
$continue = $this->confirm("Do you want to continue and execute this command on the host machine?");
if (!$continue) {
throw new BltException("Command terminated by user.");
}
}
}

}
10 changes: 0 additions & 10 deletions src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,6 @@ protected function warnIfDrupalVmNotRunning() {
}
}

/**
* Emits a warning if Drupal VM is initialized but user is not on VM CLI.
*/
protected function warnIfNonInDrupalVm() {
if (!$this->isVmCli() && $this->isDrupalVmLocallyInitialized()) {
$this->logger->warning("Drupal VM is locally initialized, but you are not inside the VM. You should execute all BLT commands from within Drupal VM. Use <comment>vagrant ssh</comment> to enter the VM.");
}
}

/**
* Issues warnings to user if their local environment is mis-configured.
*
Expand All @@ -785,7 +776,6 @@ public function issueEnvironmentWarnings($command_name) {
];
if (!in_array($command_name, $exclude_commands)) {
$this->warnIfDrupalVmNotRunning();
$this->warnIfNonInDrupalVm();
}

$this->warningsIssued = TRUE;
Expand Down

0 comments on commit 69a360f

Please sign in to comment.