Skip to content

Commit

Permalink
Remove drush-aliases SSH calls to find the absolute app root
Browse files Browse the repository at this point in the history
This was done for dedicated (Enterprise) environments (whose absolute app root
was not /app). Drush now supports relative paths (since 9.6.2) so this is
unnecessary.

Users whose dedicated (Enterprise) sites are on old versions of Drush 9 (i.e.
between 9.0.0 and 9.6.2) are advised to upgrade Drush to at least 9.6.2. 9.7.1
is the latest version at the time of writing.

See the Drush fix in drush-ops/drush#4019
  • Loading branch information
pjcdawkins committed Nov 2, 2019
1 parent 40aa3f5 commit f40d9d4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 58 deletions.
25 changes: 0 additions & 25 deletions src/Command/Local/LocalDrushAliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->debug('Fetching deployment information for environment: ' . $environment->id);
$this->api()->getCurrentDeployment($environment);
}

if ($environment->deployment_target === 'local') {
continue;
}
foreach ($apps as $app) {
$sshUrl = $environment->getSshUrl($app->getName());
if (empty($sshUrl)) {
continue;
}
try {
$appRoot = $envVarsService->getEnvVar('APP_DIR', new RemoteHost($sshUrl, $ssh, $shell));
} catch (\Symfony\Component\Process\Exception\RuntimeException $e) {
$this->stdErr->writeln(sprintf(
'Unable to find app root for environment %s, app %s',
$this->api()->getEnvironmentLabel($environment, 'comment'),
'<comment>' . $app->getName() . '</comment>'
));
$this->stdErr->writeln($e->getMessage());
continue;
}
if (!empty($appRoot)) {
$this->debug(sprintf('App root for %s: %s', $sshUrl, $appRoot));
$drush->setCachedAppRoot($sshUrl, $appRoot);
}
}
}

$drush->createAliases($project, $projectRoot, $environments, $current_group);
Expand Down
22 changes: 0 additions & 22 deletions src/Service/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class Drush
/** @var string|null */
protected $executable;

/** @var string[] */
protected $cachedAppRoots = [];

/**
* @param Config|null $config
* @param Shell|null $shellHelper
Expand Down Expand Up @@ -70,25 +67,6 @@ public function getHomeDir()
return $this->homeDir ?: Filesystem::getHomeDirectory();
}

/**
* @param string $sshUrl
* @param string $enterpriseAppRoot
*/
public function setCachedAppRoot($sshUrl, $enterpriseAppRoot)
{
$this->cachedAppRoots[$sshUrl] = $enterpriseAppRoot;
}

/**
* @param string $sshUrl
*
* @return string
*/
public function getCachedAppRoot($sshUrl)
{
return isset($this->cachedAppRoots[$sshUrl]) ? $this->cachedAppRoots[$sshUrl] : false;
}

/**
* Find the global Drush configuration directory.
*
Expand Down
12 changes: 1 addition & 11 deletions src/SiteAlias/DrushAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,9 @@ protected function generateRemoteAlias(Environment $environment, LocalApplicatio
'options' => [
$this->getAutoRemoveKey() => true,
],
'root' => $app->getDocumentRoot(),
];

// For most environments, we know the application root directory is
// '/app'. It's different in Enterprise environments.
if ($environment->deployment_target !== 'local') {
$appRoot = $this->drush->getCachedAppRoot($sshUrl);
if ($appRoot) {
$alias['root'] = rtrim($appRoot, '/') . '/' . $app->getDocumentRoot();
}
} else {
$alias['root'] = '/app/' . $app->getDocumentRoot();
}

list($alias['user'], $alias['host']) = explode('@', $sshUrl, 2);

if ($url = $this->drush->getSiteUrl($environment, $app)) {
Expand Down

0 comments on commit f40d9d4

Please sign in to comment.