mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-28 10:08:56 +02:00
Big refactoring. Use of Namespaces and codestyles. PSR-0, PSR-1, PSR-2.
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
<?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;
|
||||
|
||||
use Mage\Console;
|
||||
use Mage\Config;
|
||||
use Mage\Task\ErrorWithMessageException;
|
||||
use Mage\Task\SkipException;
|
||||
use Mage\Task\Releases\IsReleaseAware;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Abstract Class for a Magallanes Task
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
abstract class AbstractTask
|
||||
{
|
||||
/**
|
||||
* Configuration
|
||||
* @var Config;
|
||||
*/
|
||||
protected $config = null;
|
||||
|
||||
/**
|
||||
* Indicates if the Task is running in a Rollback
|
||||
* @var boolean
|
||||
*/
|
||||
protected $inRollback = false;
|
||||
|
||||
/**
|
||||
* Indicates the Stage the Task is running ing
|
||||
* @var string
|
||||
*/
|
||||
protected $stage = null;
|
||||
|
||||
/**
|
||||
* Extra parameters
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters = array();
|
||||
|
||||
/**
|
||||
* Returns the Title of the Task
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getName();
|
||||
|
||||
/**
|
||||
* Runs the task
|
||||
*
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
* @throws ErrorWithMessageException
|
||||
* @throws SkipException
|
||||
*/
|
||||
public abstract function run();
|
||||
|
||||
/**
|
||||
* Task Constructor
|
||||
*
|
||||
* @param Config $config
|
||||
* @param boolean $inRollback
|
||||
* @param string $stage
|
||||
* @param array $parameters
|
||||
*/
|
||||
public final function __construct(Config $config, $inRollback = false, $stage = null, $parameters = array())
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->inRollback = $inRollback;
|
||||
$this->stage = $stage;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the Task is running in a Rollback operation
|
||||
* @return boolean
|
||||
*/
|
||||
public function inRollback()
|
||||
{
|
||||
return $this->inRollback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Stage of the Deployment:
|
||||
* - pre-deploy
|
||||
* - deploy
|
||||
* - post-deploy
|
||||
* - post-release
|
||||
* @return string
|
||||
*/
|
||||
public function getStage()
|
||||
{
|
||||
return $this->stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Configuration
|
||||
* @return Config;
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Task, optional to implement
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Parameter, or a default if not found
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameter($name, $default = null)
|
||||
{
|
||||
return $this->getConfig()->getParameter($name, $default, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a Shell Command Locally
|
||||
* @param string $command
|
||||
* @param string $output
|
||||
* @return boolean
|
||||
*/
|
||||
protected final function runCommandLocal($command, &$output = null)
|
||||
{
|
||||
return Console::executeCommand($command, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a Shell Command on the Remote Host
|
||||
* @param string $command
|
||||
* @param string $output
|
||||
* @return boolean
|
||||
*/
|
||||
protected final function runCommandRemote($command, &$output = null)
|
||||
{
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
if ($this instanceOf IsReleaseAware) {
|
||||
$releasesDirectory = '';
|
||||
|
||||
} else {
|
||||
$releasesDirectory = '/'
|
||||
. $this->getConfig()->release('directory', 'releases')
|
||||
. '/'
|
||||
. $this->getConfig()->getReleaseId();
|
||||
}
|
||||
|
||||
} else {
|
||||
$releasesDirectory = '';
|
||||
}
|
||||
|
||||
$localCommand = 'ssh -p ' . $this->getConfig()->getHostPort() . ' '
|
||||
. '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
|
||||
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ' '
|
||||
. '"cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && '
|
||||
. str_replace('"', '\"', $command) . '"';
|
||||
|
||||
return $this->runCommandLocal($localCommand, $output);
|
||||
}
|
||||
}
|
||||
+28
-6
@@ -8,15 +8,34 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Deployment_Release
|
||||
extends Mage_Task_TaskAbstract
|
||||
implements Mage_Task_Releases_BuiltIn, Mage_Task_Releases_SkipOnOverride
|
||||
namespace Mage\Task\BuiltIn\Deployment;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\Releases\IsReleaseAware;
|
||||
use Mage\Task\Releases\SkipOnOverride;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Releasing a Deploy
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Releasing [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a Deployment: points the current symbolic link to the release directory
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
@@ -29,9 +48,9 @@ class Mage_Task_BuiltIn_Deployment_Release
|
||||
|
||||
$currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
|
||||
|
||||
// Fetch the user and group from base directory
|
||||
// Fetch the user and group from base directory; defaults usergroup to 33:33
|
||||
$userGroup = '33:33';
|
||||
$resultFetch = $this->_runRemoteCommand('ls -ld . | awk \'{print \$3":"\$4}\'', $userGroup);
|
||||
$resultFetch = $this->runCommandRemote('ls -ld . | awk \'{print \$3":"\$4}\'', $userGroup);
|
||||
|
||||
// Remove symlink if exists; create new symlink and change owners
|
||||
$command = 'rm -f ' . $symlink
|
||||
@@ -41,7 +60,10 @@ class Mage_Task_BuiltIn_Deployment_Release
|
||||
. 'chown -h ' . $userGroup . ' ' . $symlink
|
||||
. ' && '
|
||||
. 'chown -R ' . $userGroup . ' ' . $currentCopy;
|
||||
$result = $this->_runRemoteCommand($command);
|
||||
$result = $this->runCommandRemote($command);
|
||||
|
||||
// Set Directory Releases to same owner
|
||||
$result = $this->runCommandRemote('chown ' . $userGroup . ' ' . $releasesDirectory);
|
||||
|
||||
return $result;
|
||||
|
||||
+36
-11
@@ -8,10 +8,24 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
extends Mage_Task_TaskAbstract
|
||||
implements Mage_Task_Releases_BuiltIn
|
||||
namespace Mage\Task\BuiltIn\Deployment;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\Releases\IsReleaseAware;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Sync the Local Code to the Remote Hosts via RSYNC
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class RsyncTask extends AbstractTask implements IsReleaseAware
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
@@ -25,13 +39,17 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the Local Code to the Remote Host
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$overrideRelease = $this->getParameter('overrideRelease', false);
|
||||
|
||||
if ($overrideRelease == true) {
|
||||
$releaseToOverride = false;
|
||||
$resultFetch = $this->_runRemoteCommand('ls -ld current | cut -d"/" -f2', $releaseToOverride);
|
||||
$resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
|
||||
if (is_numeric($releaseToOverride)) {
|
||||
$this->getConfig()->setReleaseId($releaseToOverride);
|
||||
}
|
||||
@@ -41,7 +59,9 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
'.git',
|
||||
'.svn',
|
||||
'.mage',
|
||||
'.gitignore'
|
||||
'.gitignore',
|
||||
'.gitkeep',
|
||||
'nohup.out'
|
||||
);
|
||||
|
||||
// Look for User Excludes
|
||||
@@ -55,16 +75,16 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
|
||||
. '/' . $releasesDirectory
|
||||
. '/' . $this->getConfig()->getReleaseId();
|
||||
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
|
||||
$this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
|
||||
}
|
||||
|
||||
$command = 'rsync -avz '
|
||||
. '--rsh="ssh -p' . $this->getConfig()->getHostPort() . '" '
|
||||
. $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
|
||||
. $this->excludes(array_merge($excludes, $userExcludes)) . ' '
|
||||
. $this->getConfig()->deployment('from') . ' '
|
||||
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
// Count Releases
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
@@ -78,7 +98,7 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
$maxReleases = $this->getConfig()->release('max', false);
|
||||
if (($maxReleases !== false) && ($maxReleases > 0)) {
|
||||
$releasesList = '';
|
||||
$countReleasesFetch = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $releasesList);
|
||||
$countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList);
|
||||
$releasesList = trim($releasesList);
|
||||
|
||||
if ($releasesList != '') {
|
||||
@@ -93,7 +113,7 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
$directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete;
|
||||
if ($directoryToDelete != '/') {
|
||||
$command = 'rm -rf ' . $directoryToDelete;
|
||||
$result = $result && $this->_runRemoteCommand($command);
|
||||
$result = $result && $this->runCommandRemote($command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +124,12 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _excludes(Array $excludes)
|
||||
/**
|
||||
* Generates the Excludes for rsync
|
||||
* @param array $excludes
|
||||
* @return string
|
||||
*/
|
||||
protected function excludes(Array $excludes)
|
||||
{
|
||||
$excludesRsync = '';
|
||||
foreach ($excludes as $exclude) {
|
||||
@@ -8,35 +8,52 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Releases_List
|
||||
extends Mage_Task_TaskAbstract
|
||||
implements Mage_Task_Releases_BuiltIn
|
||||
namespace Mage\Task\BuiltIn\Releases;
|
||||
|
||||
use Mage\Console;
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\Releases\IsReleaseAware;
|
||||
|
||||
use DateTime;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Listing Available Releases on an Environment
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class ListTask extends AbstractTask implements IsReleaseAware
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'Listing releases [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* List the Available Releases on an Environment
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
|
||||
$symlink = $this->getConfig()->release('symlink', 'current');
|
||||
|
||||
Mage_Console::output('Releases available on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
Console::output('Releases available on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
|
||||
// Get Releases
|
||||
$output = '';
|
||||
$result = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $output);
|
||||
$result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
|
||||
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
|
||||
|
||||
// Get Current
|
||||
$result = $this->_runRemoteCommand('ls -l ' . $symlink, $output);
|
||||
$result = $this->runCommandRemote('ls -l ' . $symlink, $output);
|
||||
$currentRelease = explode('/', $output);
|
||||
$currentRelease = trim(array_pop($currentRelease));
|
||||
|
||||
if (count($releases) == 0) {
|
||||
Mage_Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
|
||||
Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
|
||||
} else {
|
||||
rsort($releases);
|
||||
$releases = array_slice($releases, 0, 10);
|
||||
@@ -61,25 +78,30 @@ class Mage_Task_BuiltIn_Releases_List
|
||||
$isCurrent = ' <- current';
|
||||
}
|
||||
|
||||
$dateDiff = $this->_dateDiff($releaseDate);
|
||||
$dateDiff = $this->dateDiff($releaseDate);
|
||||
|
||||
Mage_Console::output(
|
||||
Console::output(
|
||||
'Release: <purple>' . $release . '</purple> '
|
||||
. '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
|
||||
. '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $dateDiff . $isCurrent, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Mage_Console::output('');
|
||||
Console::output('');
|
||||
return $result;
|
||||
|
||||
} else {
|
||||
Mage_Console::output('');
|
||||
Console::output('');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function _dateDiff($releaseDate)
|
||||
/**
|
||||
* Calculates a Human Readable Time Difference
|
||||
* @param string $releaseDate
|
||||
* @return string
|
||||
*/
|
||||
protected function dateDiff($releaseDate)
|
||||
{
|
||||
$textDiff = '';
|
||||
$releaseDate = new DateTime($releaseDate);
|
||||
+61
-26
@@ -8,28 +8,62 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Releases_Rollback
|
||||
extends Mage_Task_TaskAbstract
|
||||
implements Mage_Task_Releases_BuiltIn
|
||||
{
|
||||
private $_release = null;
|
||||
namespace Mage\Task\BuiltIn\Releases;
|
||||
|
||||
use Mage\Console;
|
||||
use Mage\Task\Factory;
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\Releases\BuiltIn as ReleaseTask;
|
||||
use Mage\Task\Releases\RollbackAware;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Performing a Rollback Operation
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class RollbackTask extends AbstractTask implements ReleaseTask
|
||||
{
|
||||
/**
|
||||
* The Relase ID to Rollback To
|
||||
* @var integer
|
||||
*/
|
||||
protected $release = null;
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Rollback release [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Release ID to Rollback To
|
||||
* @param integer $releaseId
|
||||
* @return \Mage\Task\BuiltIn\Releases\RollbackTask
|
||||
*/
|
||||
public function setRelease($releaseId)
|
||||
{
|
||||
$this->_release = $releaseId;
|
||||
$this->release = $releaseId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the Release ID to Rollback To
|
||||
* @return integer
|
||||
*/
|
||||
public function getRelease()
|
||||
{
|
||||
return $this->_release;
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a Rollback Operation
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ($this->getConfig()->release('enabled', false) == true) {
|
||||
@@ -37,11 +71,11 @@ class Mage_Task_BuiltIn_Releases_Rollback
|
||||
$symlink = $this->getConfig()->release('symlink', 'current');
|
||||
|
||||
$output = '';
|
||||
$result = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $output);
|
||||
$result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
|
||||
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
|
||||
|
||||
if (count($releases) == 0) {
|
||||
Mage_Console::output('Release are not available for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
|
||||
Console::output('Release are not available for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
|
||||
|
||||
} else {
|
||||
rsort($releases);
|
||||
@@ -65,10 +99,10 @@ class Mage_Task_BuiltIn_Releases_Rollback
|
||||
}
|
||||
|
||||
if (!$releaseIsAvailable) {
|
||||
Mage_Console::output('Release <dark_gray>' . $this->getRelease() . '</dark_gray> is invalid or unavailable for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
|
||||
Console::output('Release <dark_gray>' . $this->getRelease() . '</dark_gray> is invalid or unavailable for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
|
||||
|
||||
} else {
|
||||
Mage_Console::output('Rollback release on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
Console::output('Rollback release on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
$rollbackTo = $releasesDirectory . '/' . $releaseId;
|
||||
|
||||
// Tasks
|
||||
@@ -78,48 +112,48 @@ class Mage_Task_BuiltIn_Releases_Rollback
|
||||
$this->getConfig()->setReleaseId($releaseId);
|
||||
|
||||
if (count($tasksToRun) == 0) {
|
||||
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> skipped!', 1, 3);
|
||||
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
|
||||
Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> skipped!', 1, 3);
|
||||
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskData) {
|
||||
$task = Mage_Task_Factory::get($taskData, $this->getConfig(), true, 'deploy');
|
||||
$task = Factory::get($taskData, $this->getConfig(), true, 'deploy');
|
||||
$task->init();
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
|
||||
if ($task instanceOf Mage_Task_Releases_RollbackAware) {
|
||||
if ($task instanceOf RollbackAware) {
|
||||
$tasks++;
|
||||
$result = $task->run();
|
||||
|
||||
if ($result == true) {
|
||||
Mage_Console::output('<green>OK</green>', 0);
|
||||
Console::output('<green>OK</green>', 0);
|
||||
$completedTasks++;
|
||||
} else {
|
||||
Mage_Console::output('<red>FAIL</red>', 0);
|
||||
Console::output('<red>FAIL</red>', 0);
|
||||
}
|
||||
} else {
|
||||
Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Changing Release
|
||||
Mage_Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
|
||||
Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
|
||||
|
||||
$userGroup = '';
|
||||
$resultFetch = $this->_runRemoteCommand('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup);
|
||||
$resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup);
|
||||
$command = 'rm -f ' . $symlink
|
||||
. ' && '
|
||||
. 'ln -sf ' . $rollbackTo . ' ' . $symlink
|
||||
. ' && '
|
||||
. 'chown -h ' . $userGroup . ' ' . $symlink;
|
||||
$result = $this->_runRemoteCommand($command);
|
||||
$result = $this->runCommandRemote($command);
|
||||
|
||||
if ($result) {
|
||||
Mage_Console::output('<green>OK</green>', 0);
|
||||
Console::output('<green>OK</green>', 0);
|
||||
$completedTasks++;
|
||||
} else {
|
||||
Mage_Console::output('<red>FAIL</red>', 0);
|
||||
Console::output('<red>FAIL</red>', 0);
|
||||
}
|
||||
|
||||
if ($completedTasks == $tasks) {
|
||||
@@ -128,11 +162,12 @@ class Mage_Task_BuiltIn_Releases_Rollback
|
||||
$tasksColor = 'red';
|
||||
}
|
||||
|
||||
Mage_Console::output('Release rollback on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Console::output('Release rollback on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
+50
-20
@@ -8,30 +8,61 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Scm_ChangeBranch
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
protected static $startingBranch = 'master';
|
||||
private $_name = 'SCM Changing branch [built-in]';
|
||||
namespace Mage\Task\BuiltIn\Scm;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\SkipException;
|
||||
use Mage\Task\ErrorWithMessageException;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Changing the Branch of the SCM
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class ChangeBranchTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* Branch the executiong began with
|
||||
* @var string
|
||||
*/
|
||||
protected static $startingBranch = 'master';
|
||||
|
||||
/**
|
||||
* Name of the Task
|
||||
* @var string
|
||||
*/
|
||||
private $name = 'SCM Changing branch [built-in]';
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
switch ($this->getConfig()->general('scm')) {
|
||||
case 'git':
|
||||
$this->_name = 'SCM Changing branch (GIT) [built-in]';
|
||||
break;
|
||||
$scmType = $this->getConfig()->general('scm');
|
||||
|
||||
case 'svn':
|
||||
$this->_name = 'SCM Changing branch (Subversion) [built-in]';
|
||||
switch ($scmType) {
|
||||
case 'git':
|
||||
$this->name = 'SCM Changing branch (GIT) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the Branch of the SCM
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$scmConfig = $this->getConfig()->general('scm', array());
|
||||
@@ -39,41 +70,40 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
|
||||
case 'git':
|
||||
if ($this->getParameter('_changeBranchRevert', false)) {
|
||||
$command = 'git checkout ' . self::$startingBranch;
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
} else {
|
||||
$command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
|
||||
$currentBranch = 'master';
|
||||
$result = $this->_runLocalCommand($command, $currentBranch);
|
||||
$result = $this->runCommandLocal($command, $currentBranch);
|
||||
|
||||
$scmData = $this->getConfig()->deployment('scm', false);
|
||||
|
||||
if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
|
||||
$command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
|
||||
$isBranchTracked = '';
|
||||
$result = $this->_runLocalCommand($command, $isBranchTracked);
|
||||
$result = $this->runCommandLocal($command, $isBranchTracked);
|
||||
|
||||
if ($isBranchTracked == '') {
|
||||
throw new Mage_Task_ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
|
||||
throw new ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
|
||||
}
|
||||
|
||||
$branch = $this->getParameter('branch', $scmData['branch']);
|
||||
$command = 'git checkout ' . $branch;
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
self::$startingBranch = $currentBranch;
|
||||
} else {
|
||||
throw new Mage_Task_SkipException;
|
||||
throw new SkipException;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Mage_Task_SkipException;
|
||||
throw new SkipException;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->getConfig()->reload();
|
||||
|
||||
return $result;
|
||||
@@ -1,61 +0,0 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Scm_Clone
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
private $_name = 'SCM Clone [built-in]';
|
||||
private $_source = null;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_source = $this->getConfig()->deployment('source');
|
||||
switch ($this->_source['type']) {
|
||||
case 'git':
|
||||
$this->_name = 'SCM Clone (GIT) [built-in]';
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
$this->_name = 'SCM Clone (Subversion) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->_runLocalCommand('mkdir -p ' . $this->_source['temporal']);
|
||||
switch ($this->_source['type']) {
|
||||
case 'git':
|
||||
// Clone Repo
|
||||
$command = 'cd ' . $this->_source['temporal'] . ' ; '
|
||||
. 'git clone ' . $this->_source['repository'] . ' . ';
|
||||
$result = $this->_runLocalCommand($command);
|
||||
|
||||
// Checkout Branch
|
||||
$command = 'cd ' . $this->_source['temporal'] . ' ; '
|
||||
. 'git checkout ' . $this->_source['from'];
|
||||
$result = $result && $this->_runLocalCommand($command);
|
||||
|
||||
$this->getConfig()->setFrom($this->_source['temporal']);
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
throw new Mage_Task_SkipException;
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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\Scm;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\SkipException;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Clonning a Repository
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class CloneTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* Name of the Task
|
||||
* @var string
|
||||
*/
|
||||
private $name = 'SCM Clone [built-in]';
|
||||
|
||||
/**
|
||||
* Source of the Repo
|
||||
* @var string
|
||||
*/
|
||||
private $source = null;
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->source = $this->getConfig()->deployment('source');
|
||||
switch ($this->source['type']) {
|
||||
case 'git':
|
||||
$this->name = 'SCM Clone (GIT) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Repository
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->runCommandLocal('mkdir -p ' . $this->source['temporal']);
|
||||
switch ($this->source['type']) {
|
||||
case 'git':
|
||||
// Clone Repo
|
||||
$command = 'cd ' . $this->source['temporal'] . ' ; '
|
||||
. 'git clone ' . $this->source['repository'] . ' . ';
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
// Checkout Branch
|
||||
$command = 'cd ' . $this->source['temporal'] . ' ; '
|
||||
. 'git checkout ' . $this->source['from'];
|
||||
$result = $result && $this->runCommandLocal($command);
|
||||
|
||||
$this->getConfig()->setFrom($this->source['temporal']);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SkipException;
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Scm_RemoveClone
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
private $_name = 'SCM Remove Clone [built-in]';
|
||||
private $_source = null;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_source = $this->getConfig()->deployment('source');
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->_runLocalCommand('rm -rf ' . $this->_source['temporal']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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\Scm;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\SkipException;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Removing an used Cloned Repository
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class RemoveCloneTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* Name of the Task
|
||||
* @var string
|
||||
*/
|
||||
private $name = 'SCM Remove Clone [built-in]';
|
||||
|
||||
/**
|
||||
* Source of the Repo
|
||||
* @var string
|
||||
*/
|
||||
private $source = null;
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->source = $this->getConfig()->deployment('source');
|
||||
switch ($this->source['type']) {
|
||||
case 'git':
|
||||
$this->name = 'SCM Remove Clone (GIT) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->runCommandLocal('rm -rf ' . $this->source['temporal']);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Scm_Update
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
private $_name = 'SCM Update [built-in]';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
switch ($this->getConfig()->general('scm')) {
|
||||
case 'git':
|
||||
$this->_name = 'SCM Update (GIT) [built-in]';
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
$this->_name = 'SCM Update (Subversion) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
switch ($this->getConfig()->general('scm')) {
|
||||
case 'git':
|
||||
$command = 'git pull';
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
$command = 'svn update';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Mage_Task_SkipException;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$this->getConfig()->reload();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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\Scm;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\SkipException;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Updating a Working Copy
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class UpdateTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* Name of the Task
|
||||
* @var string
|
||||
*/
|
||||
private $name = 'SCM Update [built-in]';
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
switch ($this->getConfig()->general('scm')) {
|
||||
case 'git':
|
||||
$this->name = 'SCM Update (GIT) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Working Copy
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
switch ($this->getConfig()->general('scm')) {
|
||||
case 'git':
|
||||
$command = 'git pull';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SkipException;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->runCommandLocal($command);
|
||||
$this->getConfig()->reload();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+21
-3
@@ -8,21 +8,39 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Symfony2_AsseticDump
|
||||
extends Mage_Task_TaskAbstract
|
||||
namespace Mage\Task\BuiltIn\Symfony2;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Dumping Assetics
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class AsseticDumpTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Symfony v2 - Assetic Dump [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps Assetics
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Options
|
||||
$env = $this->getParameter('env', 'dev');
|
||||
|
||||
$command = 'app/console assetic:dump --env=' . $env;
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
+21
-3
@@ -8,14 +8,32 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Symfony2_AssetsInstall
|
||||
extends Mage_Task_TaskAbstract
|
||||
namespace Mage\Task\BuiltIn\Symfony2;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Installing Assets
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class AssetsInstallTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Symfony v2 - Assets Install [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs Assets
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Options
|
||||
@@ -29,7 +47,7 @@ class Mage_Task_BuiltIn_Symfony2_AssetsInstall
|
||||
}
|
||||
|
||||
$command = 'app/console assets:install ' . ($symlink ? '--symlink' : '') . ' ' . ($relative ? '--relative' : '') . ' --env=' . $env . ' ' . $target;
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
+21
-3
@@ -8,21 +8,39 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Symfony2_CacheClear
|
||||
extends Mage_Task_TaskAbstract
|
||||
namespace Mage\Task\BuiltIn\Symfony2;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Clearing the Cache
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class CacheClearTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Symfony v2 - Cache Clear [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Cache
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Options
|
||||
$env = $this->getParameter('env', 'dev');
|
||||
|
||||
$command = 'app/console cache:clear --env=' . $env;
|
||||
$result = $this->_runLocalCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
+21
-3
@@ -8,21 +8,39 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_BuiltIn_Symfony2_CacheWarmup
|
||||
extends Mage_Task_TaskAbstract
|
||||
namespace Mage\Task\BuiltIn\Symfony2;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for Warming Up the Cache
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class CacheWarmupTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Symfony v2 - Cache Warmup [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Warms Up Cache
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Options
|
||||
$env = $this->getParameter('env', 'dev');
|
||||
|
||||
$command = 'app/console cache:warmup --env=' . $env;
|
||||
$result = $this->runCommand($command);
|
||||
$result = $this->runCommandLocal($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -8,8 +8,15 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_ErrorWithMessageException
|
||||
extends Exception
|
||||
{
|
||||
namespace Mage\Task;
|
||||
|
||||
}
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Exception that indicates that the Task has an Error and also a Message indicating the Error
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class ErrorWithMessageException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
+32
-11
@@ -8,16 +8,29 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_Factory
|
||||
namespace Mage\Task;
|
||||
|
||||
use Mage\Config;
|
||||
use Mage\Autoload;
|
||||
use Mage\Task\ErrorWithMessageException;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task Factory
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Gets an instance of a Task.
|
||||
*
|
||||
* @param string|array $taskData
|
||||
* @param boolean $inRollback
|
||||
* @return Mage_Task_TaskAbstract
|
||||
* @return \Mage\Task\AbstractTask
|
||||
*/
|
||||
public static function get($taskData, Mage_Config $taskConfig, $inRollback = false, $stage = null)
|
||||
public static function get($taskData, Config $taskConfig, $inRollback = false, $stage = null)
|
||||
{
|
||||
if (is_array($taskData)) {
|
||||
$taskName = $taskData['name'];
|
||||
@@ -32,17 +45,25 @@ class Mage_Task_Factory
|
||||
$taskName = str_replace(' ', '', $taskName);
|
||||
|
||||
if (strpos($taskName, '/') === false) {
|
||||
Mage_Autoload::loadUserTask($taskName);
|
||||
$className = 'Task_' . ucfirst($taskName);
|
||||
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
|
||||
Autoload::loadUserTask($taskName);
|
||||
$className = 'Task\\' . ucfirst($taskName);
|
||||
|
||||
} else {
|
||||
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
|
||||
$className = 'Mage_Task_BuiltIn_' . $taskName;
|
||||
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
|
||||
$taskName = str_replace(' ', '\\', ucwords(str_replace('/', ' ', $taskName)));
|
||||
$className = 'Mage\\Task\\BuiltIn\\' . $taskName . 'Task';
|
||||
}
|
||||
|
||||
|
||||
if (class_exists($className) || Autoload::isLoadable($className)) {
|
||||
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
|
||||
} else {
|
||||
throw new ErrorWithMessageException('The Task "' . $taskName . '" doesn\'t exists.');
|
||||
}
|
||||
|
||||
if (!($instance instanceOf AbstractTask)) {
|
||||
throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\Task\AbstractTask.');
|
||||
}
|
||||
|
||||
assert($instance instanceOf Mage_Task_TaskAbstract);
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,13 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
interface Mage_Task_Releases_BuiltIn
|
||||
namespace Mage\Task\Releases;
|
||||
|
||||
/**
|
||||
* Indicates that the Task is Relase Aware/Dependant
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
interface IsReleaseAware
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,13 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
interface Mage_Task_Releases_RollbackAware
|
||||
namespace Mage\Task\Releases;
|
||||
|
||||
/**
|
||||
* Indicates that the Task is Aware of Rollbacks
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
interface RollbackAware
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
interface Mage_Task_Releases_SkipOnOverride
|
||||
namespace Mage\Task\Releases;
|
||||
|
||||
/**
|
||||
* Indicates that the Task will be Skipped on Relase Override
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
interface SkipOnOverride
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,15 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Task_SkipException
|
||||
extends Exception
|
||||
{
|
||||
namespace Mage\Task;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Exception that indicates that the Task was Skipped
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class SkipException extends Exception
|
||||
{
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
abstract class Mage_Task_TaskAbstract
|
||||
{
|
||||
protected $_config = null;
|
||||
protected $_inRollback = false;
|
||||
protected $_stage = null;
|
||||
protected $_parameters = array();
|
||||
|
||||
public abstract function getName();
|
||||
|
||||
public abstract function run();
|
||||
|
||||
public final function __construct(Mage_Config $config, $inRollback = false, $stage = null, $parameters = array())
|
||||
{
|
||||
$this->_config = $config;
|
||||
$this->_inRollback = $inRollback;
|
||||
$this->_stage = $stage;
|
||||
$this->_parameters = $parameters;
|
||||
}
|
||||
|
||||
public function inRollback()
|
||||
{
|
||||
return $this->_inRollback;
|
||||
}
|
||||
|
||||
public function getStage()
|
||||
{
|
||||
return $this->_stage;
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the a parameter
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameter($name, $default = null)
|
||||
{
|
||||
return $this->getConfig()->getParameter($name, $default, $this->_parameters);
|
||||
}
|
||||
|
||||
protected final function runCommand($command, &$output = null)
|
||||
{
|
||||
if ($this->getStage() == 'deploy') {
|
||||
return $this->_runRemoteCommand($command, $output);
|
||||
} else {
|
||||
return $this->_runLocalCommand($command, $output);
|
||||
}
|
||||
}
|
||||
|
||||
protected final function _runLocalCommand($command, &$output = null)
|
||||
{
|
||||
return Mage_Console::executeCommand($command, $output);
|
||||
}
|
||||
|
||||
protected final function _runRemoteCommand($command, &$output = null)
|
||||
{
|
||||
if ($this->_config->release('enabled', false) == true) {
|
||||
if ($this instanceOf Mage_Task_Releases_BuiltIn) {
|
||||
$releasesDirectory = '';
|
||||
|
||||
} else {
|
||||
$releasesDirectory = '/'
|
||||
. $this->_config->release('directory', 'releases')
|
||||
. '/'
|
||||
. $this->_config->getReleaseId();
|
||||
}
|
||||
|
||||
} else {
|
||||
$releasesDirectory = '';
|
||||
}
|
||||
|
||||
$localCommand = 'ssh -p ' . $this->_config->getHostPort() . ' '
|
||||
. '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
|
||||
. $this->_config->deployment('user') . '@' . $this->_config->getHostName() . ' '
|
||||
. '"cd ' . rtrim($this->_config->deployment('to'), '/') . $releasesDirectory . ' && '
|
||||
. str_replace('"', '\"', $command) . '"';
|
||||
|
||||
return $this->_runLocalCommand($localCommand, $output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user