Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle-S committed May 4, 2018
2 parents 15308d1 + 8bc3cf1 commit c6e00f8
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/AbstractRoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,26 @@ protected function deployTask(

protected function currentReleaseHasRobo($worker, AbstractAuth $auth, $remote)
{
$currentProjectRoot = $remote['currentdir'] . '/..';
$currentProjectRoot = $this->getCurrentProjectRoot($worker, $auth, $remote);
return $this->taskSsh($worker, $auth)
->remoteDirectory($currentProjectRoot, true)
->exec('ls vendor/bin/robo | grep robo')
->run()
->wasSuccessful();
}

public function getCurrentProjectRoot($worker, AbstractAuth $auth, $remote)
{
$fullOutput = '';
$this->taskSsh($worker, $auth)
->remoteDirectory($remote['releasesdir'], true)
->exec('ls -1 | sort -r | head -1', function ($output) use (&$fullOutput) {
$fullOutput .= $output;
})
->run();
return $remote['releasesdir'] . '/' . substr($fullOutput, 0, (strpos($fullOutput, "\n") ?: strlen($fullOutput)));
}

/**
* Check if a site is already installed
*
Expand Down Expand Up @@ -331,7 +343,7 @@ protected function postSymlinkTask($worker, AbstractAuth $auth, $remote)
*/
protected function preSymlinkTask($worker, AbstractAuth $auth, $remote)
{
$projectRoot = $remote['webdir'] . '/..';
$projectRoot = $remote['rootdir'];
$collection = $this->collectionBuilder();
$collection->taskSsh($worker, $auth)
->remoteDirectory($projectRoot, true)
Expand Down Expand Up @@ -644,7 +656,7 @@ protected function backupTask(
$opts['data'] = true;
}
$backupDir = $remote['backupsdir'] . '/' . $remote['time'];
$currentProjectRoot = $remote['currentdir'] . '/..';
$currentProjectRoot = $this->getCurrentProjectRoot($worker, $auth, $remote);

$collection = $this->collectionBuilder();
$collection->taskSsh($worker, $auth)
Expand Down Expand Up @@ -731,7 +743,7 @@ protected function restoreBackupTask(
$opts['data'] = true;
}

$currentProjectRoot = $remote['currentdir'] . '/..';
$currentProjectRoot = $this->getCurrentProjectRoot($worker, $auth, $remote);
$backupDir = $remote['backupsdir'] . '/' . $remote['time'];

$collection = $this->collectionBuilder();
Expand Down Expand Up @@ -940,9 +952,8 @@ protected function pushPackageTask($worker, AbstractAuth $auth, $remote, $archiv
*/
protected function switchPreviousTask($worker, AbstractAuth $auth, $remote)
{
$currentProjectRoot = $remote['currentdir'] . '/..';
return $this->taskSsh($worker, $auth)
->remoteDirectory($currentProjectRoot, true)
->remoteDirectory($remote['rootdir'], true)
->exec(
'vendor/bin/robo digipolis:switch-previous '
. $remote['releasesdir']
Expand All @@ -967,12 +978,11 @@ protected function switchPreviousTask($worker, AbstractAuth $auth, $remote)
*/
protected function removeFailedRelease($worker, AbstractAuth $auth, $remote, $releaseDirname = null)
{
$currentProjectRoot = $remote['currentdir'] . '/..';
$releaseDir = is_null($releaseDirname)
? $remote['releasesdir'] . '/' . $remote['time']
: $releaseDirname;
return $this->taskSsh($worker, $auth)
->remoteDirectory($currentProjectRoot, true)
->remoteDirectory($remote['rootdir'], true)
->exec('chown -R ' . $remote['user'] . ':' . $remote['user'] . ' ' . $releaseDir)
->exec('chmod -R a+rwx ' . $releaseDir)
->exec('rm -rf ' . $releaseDir);
Expand Down Expand Up @@ -1016,13 +1026,12 @@ protected function symlinksTask($worker, AbstractAuth $auth, $remote)
*/
protected function clearOpCacheTask($worker, AbstractAuth $auth, $remote)
{
$currentProjectRoot = $remote['currentdir'] . '/..';
$clearOpcache = 'vendor/bin/robo digipolis:clear-op-cache ' . $remote['opcache']['env'];
if (isset($remote['opcache']['host'])) {
$clearOpcache .= ' --host=' . $remote['opcache']['host'];
}
return $this->taskSsh($worker, $auth)
->remoteDirectory($currentProjectRoot, true)
->remoteDirectory($remote['rootdir'], true)
->exec($clearOpcache);
}

Expand All @@ -1041,10 +1050,9 @@ protected function clearOpCacheTask($worker, AbstractAuth $auth, $remote)
*/
protected function cleanDirsTask($worker, AbstractAuth $auth, $remote)
{
$currentProjectRoot = $remote['currentdir'] . '/..';
$cleandirLimit = isset($remote['cleandir_limit']) ? max(1, $remote['cleandir_limit']) : '';
return $this->taskSsh($worker, $auth)
->remoteDirectory($currentProjectRoot, true)
->remoteDirectory($remote['rootdir'], true)
->timeout(30)
->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['releasesdir'] . (!empty($cleandirLimit) ? ':' . $cleandirLimit : ''))
->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['backupsdir'] . (!empty($cleandirLimit) ? ':' . ($cleandirLimit - 1) : ''));
Expand Down

0 comments on commit c6e00f8

Please sign in to comment.