mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-09-08 14:28:57 +02:00
Merge
This commit is contained in:
@@ -59,6 +59,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
||||
*/
|
||||
const IN_PROGRESS = 'in_progress';
|
||||
|
||||
/**
|
||||
* Stage where possible throw Rollback Exception
|
||||
* @var array
|
||||
*/
|
||||
public $acceptedStagesToRollback = array(
|
||||
AbstractTask::STAGE_POST_RELEASE,
|
||||
AbstractTask::STAGE_POST_DEPLOY
|
||||
);
|
||||
|
||||
/**
|
||||
* Time the Deployment has Started
|
||||
* @var integer
|
||||
@@ -430,22 +439,46 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
||||
}
|
||||
}
|
||||
|
||||
protected function runRollbackTask(){
|
||||
protected function runRollbackTask(AbstractTask $task){
|
||||
$this->getConfig()->reload();
|
||||
$hosts = $this->getConfig()->getHosts();
|
||||
|
||||
if (count($hosts) == 0) {
|
||||
Console::output("",1,2);
|
||||
Console::output("Starting the <bold>rollback</bold>",1,1);
|
||||
|
||||
if(!in_array($task->getStage(), $this->acceptedStagesToRollback ) ) {
|
||||
$stagesString = implode(', ',$this->acceptedStagesToRollback);
|
||||
Console::output("<light_purple>Warning!</light_purple> <bold>Rollback during deployment can be called only at the stages: $stagesString <bold>",1);
|
||||
Console::output("<bold>Rollback:<bold> <red>ABORTING</red>",1,3);
|
||||
|
||||
} elseif (count($hosts) == 0) {
|
||||
Console::output('<light_purple>Warning!</light_purple> <bold>No hosts defined, unable to get releases.</bold>', 1, 3);
|
||||
|
||||
} else {
|
||||
$result = true;
|
||||
foreach ($hosts as $host) {
|
||||
$this->getConfig()->setHost($host);
|
||||
foreach ($hosts as $hostKey => $host) {
|
||||
$hostConfig = null;
|
||||
if (is_array($host)) {
|
||||
$hostConfig = $host;
|
||||
$host = $hostKey;
|
||||
}
|
||||
|
||||
// Set Host and Host Specific Config
|
||||
$this->getConfig()->setHost($host);
|
||||
$this->getConfig()->setHostConfig($hostConfig);
|
||||
$this->getConfig()->setReleaseId(-1);
|
||||
$task = Factory::get('releases/rollback', $this->getConfig());
|
||||
|
||||
$task = Factory::get(array(
|
||||
'name'=>'releases/rollback',
|
||||
'parameters' => array('inDeploy'=>true)
|
||||
),
|
||||
$this->getConfig(),
|
||||
false,
|
||||
$task->getStage()
|
||||
);
|
||||
$task->init();
|
||||
$result = $task->run() && $result;
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -486,8 +519,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
||||
$result = false;
|
||||
}
|
||||
} catch (RollbackException $e) {
|
||||
Console::output('<red>FAIL, Rollback started</red> [Message: ' . $e->getMessage() . ']', 0);
|
||||
$this->runRollbackTask();
|
||||
Console::output('<red>FAIL, Rollback catched</red> [Message: ' . $e->getMessage() . ']', 0);
|
||||
$this->runRollbackTask($task);
|
||||
$result = false;
|
||||
|
||||
} catch (ErrorWithMessageException $e) {
|
||||
|
||||
+32
-7
@@ -48,6 +48,12 @@ class Console
|
||||
*/
|
||||
private static $logEnabled = true;
|
||||
|
||||
/**
|
||||
* Enables or disables verbose logging
|
||||
* @var boolean
|
||||
*/
|
||||
private static $verboseLogEnabled = false;
|
||||
|
||||
/**
|
||||
* String Buffer for the screen output
|
||||
* @var string
|
||||
@@ -107,6 +113,8 @@ class Console
|
||||
self::$logEnabled = $config->general('logging', false);
|
||||
}
|
||||
|
||||
self::$verboseLogEnabled = self::isVerboseLoggingEnabled();
|
||||
|
||||
// Greetings
|
||||
if ($showGreetings) {
|
||||
if (!self::$logEnabled) {
|
||||
@@ -173,15 +181,17 @@ class Console
|
||||
{
|
||||
self::log(strip_tags($message));
|
||||
|
||||
self::$screenBuffer .= str_repeat("\t", $tabs)
|
||||
. strip_tags($message)
|
||||
. str_repeat(PHP_EOL, $newLine);
|
||||
if (!self::$verboseLogEnabled) {
|
||||
self::$screenBuffer .= str_repeat("\t", $tabs)
|
||||
. strip_tags($message)
|
||||
. str_repeat(PHP_EOL, $newLine);
|
||||
|
||||
$output = str_repeat("\t", $tabs)
|
||||
. Colors::color($message, self::$config)
|
||||
. str_repeat(PHP_EOL, $newLine);
|
||||
$output = str_repeat("\t", $tabs)
|
||||
. Colors::color($message, self::$config)
|
||||
. str_repeat(PHP_EOL, $newLine);
|
||||
|
||||
echo $output;
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,6 +237,10 @@ class Console
|
||||
|
||||
$message = date('Y-m-d H:i:s -- ') . $message;
|
||||
fwrite(self::$log, $message . PHP_EOL);
|
||||
|
||||
if (self::$verboseLogEnabled) {
|
||||
echo $message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,4 +300,15 @@ class Console
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if verbose logging is enabled
|
||||
* @return boolean
|
||||
*/
|
||||
protected static function isVerboseLoggingEnabled()
|
||||
{
|
||||
return self::$config->getParameter('verbose', false)
|
||||
|| self::$config->general('verbose_logging')
|
||||
|| self::$config->environmentConfig('verbose_logging', false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Task\BuiltIn\General;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Task for running multiple custom commands setting them manually
|
||||
*
|
||||
* Example of usage:
|
||||
*
|
||||
* tasks:
|
||||
* on-deploy:
|
||||
* - scm/force-update
|
||||
* - general/manually:
|
||||
* - find . -type d -exec chmod 755 {} \;
|
||||
* - find . -type f -exec chmod 644 {} \;
|
||||
* - chmod +x bin/console
|
||||
* - find var/logs -maxdepth 1 -type f -name '*.log' -exec chown apache:apache {} \;
|
||||
* - symfony2/cache-clear
|
||||
*
|
||||
* @author Samuel Chiriluta <samuel4x4@gmail.com>
|
||||
*/
|
||||
class ManuallyTask extends AbstractTask {
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Manually multiple custom tasks';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$result = true;
|
||||
|
||||
$commands = $this->getParameters();
|
||||
|
||||
foreach ($commands as $command)
|
||||
{
|
||||
$result = $result && $this->runCommand($command);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,12 +55,18 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
|
||||
$result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
|
||||
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
|
||||
|
||||
$inDeploy = $this->getParameter('inDeploy',false);
|
||||
|
||||
if (count($releases) == 0) {
|
||||
Console::output('Release are not available for <bold>' . $this->getConfig()->getHost() . '</bold> ... <red>FAIL</red>');
|
||||
|
||||
} else {
|
||||
rsort($releases);
|
||||
$deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', false);
|
||||
$deleteCurrent = $this->getConfig()->getParameter('deleteCurrent',
|
||||
$this->getConfig()->deployment('delete-on-rollback',
|
||||
$this->getConfig()->general('delete-on-rollback',false)
|
||||
)
|
||||
);
|
||||
|
||||
$releaseIsAvailable = false;
|
||||
if ($this->getReleaseId() == '') {
|
||||
|
||||
@@ -65,13 +65,13 @@ class ForceUpdateTask extends AbstractTask
|
||||
$remote = $this->getParameter('remote', 'origin');
|
||||
|
||||
$command = 'git fetch ' . $remote . ' ' . $branch;
|
||||
$result = $this->runCommandRemote($command);
|
||||
$result = $this->runCommand($command);
|
||||
|
||||
$command = 'git reset --hard ' . $remote . '/' . $branch;
|
||||
$result = $result && $this->runCommandRemote($command);
|
||||
$result = $result && $this->runCommand($command);
|
||||
|
||||
$command = 'git pull ' . $remote . ' ' . $branch;
|
||||
$result = $result && $this->runCommandRemote($command);
|
||||
$result = $result && $this->runCommand($command);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -79,7 +79,6 @@ class ForceUpdateTask extends AbstractTask
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->runCommandLocal($command);
|
||||
$this->getConfig()->reload();
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -14,8 +14,13 @@ use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask;
|
||||
|
||||
/**
|
||||
* Task for Clearing the Cache
|
||||
*
|
||||
* Example of usage:
|
||||
* symfony2/cache-clear: { env: dev }
|
||||
* symfony2/cache-clear: { env: dev, optional: --no-warmup }
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
* @author Samuel Chiriluta <samuel4x4@gmail.com>
|
||||
*/
|
||||
class CacheClearTask extends SymfonyAbstractTask
|
||||
{
|
||||
@@ -36,8 +41,10 @@ class CacheClearTask extends SymfonyAbstractTask
|
||||
{
|
||||
// Options
|
||||
$env = $this->getParameter('env', 'dev');
|
||||
$optional = $this->getParameter('optional', '');
|
||||
|
||||
$command = $this->getAppPath() . ' cache:clear --env=' . $env . ' ' . $optional;
|
||||
|
||||
$command = $this->getAppPath() . ' cache:clear --env=' . $env;
|
||||
$result = $this->runCommand($command);
|
||||
|
||||
return $result;
|
||||
|
||||
+3
-1
@@ -15,7 +15,7 @@ use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask;
|
||||
/**
|
||||
* Task for Doctrine migrations
|
||||
*/
|
||||
class DoctrineMigrate extends SymfonyAbstractTask
|
||||
class DoctrineMigrateTask extends SymfonyAbstractTask
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
@@ -34,7 +34,9 @@ class DoctrineMigrate extends SymfonyAbstractTask
|
||||
public function run()
|
||||
{
|
||||
$env = $this->getParameter('env', 'dev');
|
||||
|
||||
$command = $this->getAppPath() . ' doctrine:migrations:migrate -n --env=' . $env;
|
||||
|
||||
return $this->runCommand($command);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user