mirror of https://github.com/hauke68/Magallanes
Andrés Montañez
11 years ago
57 changed files with 1797 additions and 974 deletions
@ -0,0 +1,54 @@ |
|||||||
|
<?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\Command; |
||||||
|
|
||||||
|
use Mage\Config; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract Class for a Magallanes Command |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
abstract class AbstractCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Instance of the loaded Configuration. |
||||||
|
* |
||||||
|
* @var Mage\Config |
||||||
|
*/ |
||||||
|
protected $config = null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Runs the Command |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract function run(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the Loaded Configuration. |
||||||
|
* |
||||||
|
* @param Config $config |
||||||
|
*/ |
||||||
|
public function setConfig(Config $config) |
||||||
|
{ |
||||||
|
$this->config = $config; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the Loaded Configuration. |
||||||
|
* |
||||||
|
* @return Config |
||||||
|
*/ |
||||||
|
public function getConfig() |
||||||
|
{ |
||||||
|
return $this->config; |
||||||
|
} |
||||||
|
} |
@ -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_Command_BuiltIn_Compile |
|
||||||
* |
|
||||||
* @author Ismael Ambrosi<ismaambrosi@gmail.com> |
|
||||||
*/ |
|
||||||
class Mage_Command_BuiltIn_Compile |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
{ |
|
||||||
/** |
|
||||||
* @see Mage_Compile::compile() |
|
||||||
*/ |
|
||||||
public function run () |
|
||||||
{ |
|
||||||
Mage_Console::output('Compiling <dark_gray>Magallanes</dark_gray>... ', 1, 0); |
|
||||||
|
|
||||||
$compiler = new Mage_Compiler(); |
|
||||||
$compiler->compile(); |
|
||||||
|
|
||||||
Mage_Console::output('Mage compiled successfully'); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,38 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Console; |
||||||
|
use Mage\Compiler; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Command for Compile Magallanes into a PHAR executable |
||||||
|
* |
||||||
|
* @author Ismael Ambrosi<ismaambrosi@gmail.com> |
||||||
|
*/ |
||||||
|
class CompileCommand extends AbstractCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @see \Mage\Compile::compile() |
||||||
|
*/ |
||||||
|
public function run () |
||||||
|
{ |
||||||
|
Console::output('Compiling <dark_gray>Magallanes</dark_gray>... ', 1, 0); |
||||||
|
|
||||||
|
$compiler = new Compiler; |
||||||
|
$compiler->compile(); |
||||||
|
|
||||||
|
Console::output('Mage compiled successfully'); |
||||||
|
} |
||||||
|
} |
@ -1,51 +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_Command_BuiltIn_List |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
{ |
|
||||||
public function run() |
|
||||||
{ |
|
||||||
$subCommand = $this->getConfig()->getArgument(1); |
|
||||||
|
|
||||||
try { |
|
||||||
switch ($subCommand) { |
|
||||||
case 'environments': |
|
||||||
$this->_environment(); |
|
||||||
break; |
|
||||||
} |
|
||||||
} catch (Exception $e) { |
|
||||||
Mage_Console::output('<red>' . $e->getMessage() . '</red>', 1, 2); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private function _environment() |
|
||||||
{ |
|
||||||
$environments = array(); |
|
||||||
$content = scandir('.mage/config/environment/'); |
|
||||||
foreach ($content as $file) { |
|
||||||
if (strpos($file, '.yml') !== false) { |
|
||||||
$environments[] = str_replace('.yml', '', $file); |
|
||||||
} |
|
||||||
} |
|
||||||
sort($environments); |
|
||||||
|
|
||||||
if (count($environments) > 0) { |
|
||||||
Mage_Console::output('<dark_gray>These are your configured environments:</dark_gray>', 1, 1); |
|
||||||
foreach ($environments as $environment) { |
|
||||||
Mage_Console::output('* <light_red>' . $environment . '</light_red>', 2, 1); |
|
||||||
} |
|
||||||
Mage_Console::output('', 1, 1); |
|
||||||
|
|
||||||
} else { |
|
||||||
Mage_Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,76 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Adds elements to the Configuration. |
||||||
|
* Currently elements allowed to add: |
||||||
|
* - environments |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class ListCommand extends AbstractCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Command for Listing Configuration Elements |
||||||
|
* @see \Mage\Command\AbstractCommand::run() |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
$subCommand = $this->getConfig()->getArgument(1); |
||||||
|
|
||||||
|
try { |
||||||
|
switch ($subCommand) { |
||||||
|
case 'environments': |
||||||
|
$this->listEnvironments(); |
||||||
|
break; |
||||||
|
|
||||||
|
default; |
||||||
|
throw new Exception('The Type of Elements to List is needed.'); |
||||||
|
break; |
||||||
|
} |
||||||
|
} catch (Exception $e) { |
||||||
|
Console::output('<red>' . $e->getMessage() . '</red>', 1, 2); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Lists the Environments |
||||||
|
*/ |
||||||
|
protected function listEnvironments() |
||||||
|
{ |
||||||
|
$environments = array(); |
||||||
|
$content = scandir('.mage/config/environment/'); |
||||||
|
foreach ($content as $file) { |
||||||
|
if (strpos($file, '.yml') !== false) { |
||||||
|
$environments[] = str_replace('.yml', '', $file); |
||||||
|
} |
||||||
|
} |
||||||
|
sort($environments); |
||||||
|
|
||||||
|
if (count($environments) > 0) { |
||||||
|
Console::output('<dark_gray>These are your configured environments:</dark_gray>', 1, 1); |
||||||
|
foreach ($environments as $environment) { |
||||||
|
Console::output('* <light_red>' . $environment . '</light_red>', 2, 1); |
||||||
|
} |
||||||
|
Console::output('', 1, 1); |
||||||
|
|
||||||
|
} else { |
||||||
|
Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,23 +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_Command_BuiltIn_Lock |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
implements Mage_Command_RequiresEnvironment |
|
||||||
{ |
|
||||||
public function run() |
|
||||||
{ |
|
||||||
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; |
|
||||||
file_put_contents($lockFile, 'Locked environment at date: ' . date('Y-m-d H:i:s')); |
|
||||||
|
|
||||||
Mage_Console::output('Locked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,38 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Command\RequiresEnvironment; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Command for Locking the Deployment to an Environment |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class LockCommand extends AbstractCommand implements RequiresEnvironment |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Locks the Deployment to a Environment |
||||||
|
* @see \Mage\Command\AbstractCommand::run() |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; |
||||||
|
file_put_contents($lockFile, 'Locked environment at date: ' . date('Y-m-d H:i:s')); |
||||||
|
|
||||||
|
Console::output('Locked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,25 +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_Command_BuiltIn_Unlock |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
implements Mage_Command_RequiresEnvironment |
|
||||||
{ |
|
||||||
public function run() |
|
||||||
{ |
|
||||||
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; |
|
||||||
if (file_exists($lockFile)) { |
|
||||||
@unlink($lockFile); |
|
||||||
} |
|
||||||
|
|
||||||
Mage_Console::output('Unlocked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,41 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Command\RequiresEnvironment; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Command for Unlocking an Environment |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class UnlockCommand |
||||||
|
extends AbstractCommand implements RequiresEnvironment |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Unlocks an Environment |
||||||
|
* @see \Mage\Command\AbstractCommand::run() |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; |
||||||
|
if (file_exists($lockFile)) { |
||||||
|
@unlink($lockFile); |
||||||
|
} |
||||||
|
|
||||||
|
Console::output('Unlocked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,29 +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_Command_BuiltIn_Update |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
{ |
|
||||||
public function run() |
|
||||||
{ |
|
||||||
$task = Mage_Task_Factory::get('scm/update', $this->getConfig()); |
|
||||||
$task->init(); |
|
||||||
|
|
||||||
Mage_Console::output('Updating application via ' . $task->getName() . ' ... ', 1, 0); |
|
||||||
$result = $task->run(); |
|
||||||
|
|
||||||
if ($result == true) { |
|
||||||
Mage_Console::output('<green>OK</green>' . PHP_EOL, 0); |
|
||||||
} else { |
|
||||||
Mage_Console::output('<red>FAIL</red>' . PHP_EOL, 0); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,45 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Task\Factory; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Updates the SCM Base Code |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class UpdateCommand extends AbstractCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Updates the SCM Base Code |
||||||
|
* @see \Mage\Command\AbstractCommand::run() |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
$task = Factory::get('scm/update', $this->getConfig()); |
||||||
|
$task->init(); |
||||||
|
|
||||||
|
Console::output('Updating application via ' . $task->getName() . ' ... ', 1, 0); |
||||||
|
$result = $task->run(); |
||||||
|
|
||||||
|
if ($result == true) { |
||||||
|
Console::output('<green>OK</green>' . PHP_EOL, 0); |
||||||
|
} else { |
||||||
|
Console::output('<red>FAIL</red>' . PHP_EOL, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,124 +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_Command_BuiltIn_Upgrade |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
{ |
|
||||||
const DOWNLOAD = 'https://github.com/andres-montanez/Magallanes/tarball/stable'; |
|
||||||
|
|
||||||
public function run () |
|
||||||
{ |
|
||||||
Mage_Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0); |
|
||||||
|
|
||||||
$user = ''; |
|
||||||
// Check if user is root |
|
||||||
Mage_Console::executeCommand('whoami', $user); |
|
||||||
if ($user != 'root') { |
|
||||||
Mage_Console::output('<red>FAIL</red>', 0, 1); |
|
||||||
Mage_Console::output('You need to be the <dark_gray>root</dark_gray> user to perform the upgrade.', 2); |
|
||||||
|
|
||||||
} else { |
|
||||||
// Download Package |
|
||||||
$tarball = file_get_contents(self::DOWNLOAD); |
|
||||||
$tarballFile = tempnam('/tmp', 'magallanes_download'); |
|
||||||
rename($tarballFile, $tarballFile . '.tar.gz'); |
|
||||||
$tarballFile .= '.tar.gz'; |
|
||||||
file_put_contents($tarballFile, $tarball); |
|
||||||
|
|
||||||
// Unpackage |
|
||||||
if (file_exists('/tmp/__magallanesDownload')) { |
|
||||||
Mage_Console::executeCommand('rm -rf /tmp/__magallanesDownload'); |
|
||||||
} |
|
||||||
Mage_Console::executeCommand('mkdir /tmp/__magallanesDownload'); |
|
||||||
Mage_Console::executeCommand('cd /tmp/__magallanesDownload && tar xfz ' . $tarballFile); |
|
||||||
Mage_Console::executeCommand('rm -f ' . $tarballFile); |
|
||||||
|
|
||||||
// Find Package |
|
||||||
$tarballDir = opendir('/tmp/__magallanesDownload'); |
|
||||||
while (($file = readdir($tarballDir)) == true) { |
|
||||||
if ($file == '.' || $file == '..') { |
|
||||||
continue; |
|
||||||
} else { |
|
||||||
$packageDir = $file; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Get Version |
|
||||||
$version = false; |
|
||||||
if (file_exists('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage')) { |
|
||||||
list(, $version) = file('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage'); |
|
||||||
$version = trim(str_replace('#VERSION:', '', $version)); |
|
||||||
} |
|
||||||
|
|
||||||
if ($version != false) { |
|
||||||
$versionCompare = version_compare(MAGALLANES_VERSION, $version); |
|
||||||
if ($versionCompare == 0) { |
|
||||||
Mage_Console::output('<yellow>SKIP</yellow>', 0, 1); |
|
||||||
Mage_Console::output('Your current version is up to date.', 2); |
|
||||||
|
|
||||||
} else if ($versionCompare > 0) { |
|
||||||
Mage_Console::output('<yellow>SKIP</yellow>', 0, 1); |
|
||||||
Mage_Console::output('Your current version is newer.', 2); |
|
||||||
|
|
||||||
} else { |
|
||||||
$this->_recursiveCopy('/tmp/__magallanesDownload/' . $packageDir, '/opt/magallanes-' . $version); |
|
||||||
unlink('/opt/magallanes'); |
|
||||||
symlink('/opt/magallanes-' . $version, '/opt/magallanes'); |
|
||||||
chmod('/opt/magallanes/bin/mage', 0755); |
|
||||||
|
|
||||||
Mage_Console::output('<green>OK</green>', 0, 1); |
|
||||||
} |
|
||||||
|
|
||||||
} else { |
|
||||||
Mage_Console::output('<red>FAIL</red>', 0, 1); |
|
||||||
Mage_Console::output('Corrupted download.', 2); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private function _recursiveCopy ($from, $to) |
|
||||||
{ |
|
||||||
if (is_dir($from)) { |
|
||||||
mkdir($to); |
|
||||||
$files = scandir($from); |
|
||||||
|
|
||||||
if (count($files) > 0) { |
|
||||||
foreach ($files as $file) { |
|
||||||
if (strpos($file, '.') === 0) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
if (is_dir($from . DIRECTORY_SEPARATOR . $file)) { |
|
||||||
$this->_recursiveCopy( |
|
||||||
$from . DIRECTORY_SEPARATOR . $file, |
|
||||||
$to . DIRECTORY_SEPARATOR . $file |
|
||||||
); |
|
||||||
|
|
||||||
} else { |
|
||||||
copy( |
|
||||||
$from . DIRECTORY_SEPARATOR . $file, |
|
||||||
$to . DIRECTORY_SEPARATOR . $file |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return true; |
|
||||||
|
|
||||||
} elseif (is_file($from)) { |
|
||||||
return copy($from, $to); |
|
||||||
|
|
||||||
} else { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,107 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Upgrades the Magallanes Version on the Local System |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class UpgradeCommand extends InstallCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* GIT Source for downloading |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
const DOWNLOAD = 'https://github.com/andres-montanez/Magallanes/tarball/stable'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Command for Upgrading Magallanes |
||||||
|
* @see \Mage\Command\BuiltIn\InstallCommand::run() |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0); |
||||||
|
|
||||||
|
$user = ''; |
||||||
|
// Check if user is root |
||||||
|
Console::executeCommand('whoami', $user); |
||||||
|
if ($user != 'root') { |
||||||
|
Console::output('<red>FAIL</red>', 0, 1); |
||||||
|
Console::output('You need to be the <dark_gray>root</dark_gray> user to perform the upgrade.', 2); |
||||||
|
|
||||||
|
} else { |
||||||
|
// Download Package |
||||||
|
$tarball = file_get_contents(self::DOWNLOAD); |
||||||
|
$tarballFile = tempnam('/tmp', 'magallanes_download'); |
||||||
|
rename($tarballFile, $tarballFile . '.tar.gz'); |
||||||
|
$tarballFile .= '.tar.gz'; |
||||||
|
file_put_contents($tarballFile, $tarball); |
||||||
|
|
||||||
|
// Unpackage |
||||||
|
if (file_exists('/tmp/__magallanesDownload')) { |
||||||
|
Console::executeCommand('rm -rf /tmp/__magallanesDownload'); |
||||||
|
} |
||||||
|
Console::executeCommand('mkdir /tmp/__magallanesDownload'); |
||||||
|
Console::executeCommand('cd /tmp/__magallanesDownload && tar xfz ' . $tarballFile); |
||||||
|
Console::executeCommand('rm -f ' . $tarballFile); |
||||||
|
|
||||||
|
// Find Package |
||||||
|
$tarballDir = opendir('/tmp/__magallanesDownload'); |
||||||
|
while (($file = readdir($tarballDir)) == true) { |
||||||
|
if ($file == '.' || $file == '..') { |
||||||
|
continue; |
||||||
|
} else { |
||||||
|
$packageDir = $file; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Get Version |
||||||
|
$version = false; |
||||||
|
if (file_exists('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage')) { |
||||||
|
list(, $version) = file('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage'); |
||||||
|
$version = trim(str_replace('#VERSION:', '', $version)); |
||||||
|
} |
||||||
|
|
||||||
|
if ($version != false) { |
||||||
|
$versionCompare = version_compare(MAGALLANES_VERSION, $version); |
||||||
|
if ($versionCompare == 0) { |
||||||
|
Console::output('<yellow>SKIP</yellow>', 0, 1); |
||||||
|
Console::output('Your current version is up to date.', 2); |
||||||
|
|
||||||
|
} else if ($versionCompare > 0) { |
||||||
|
Console::output('<yellow>SKIP</yellow>', 0, 1); |
||||||
|
Console::output('Your current version is newer.', 2); |
||||||
|
|
||||||
|
} else { |
||||||
|
$this->recursiveCopy('/tmp/__magallanesDownload/' . $packageDir, '/opt/magallanes-' . $version); |
||||||
|
unlink('/opt/magallanes'); |
||||||
|
symlink('/opt/magallanes-' . $version, '/opt/magallanes'); |
||||||
|
chmod('/opt/magallanes/bin/mage', 0755); |
||||||
|
|
||||||
|
Console::output('<green>OK</green>', 0, 1); |
||||||
|
} |
||||||
|
|
||||||
|
} else { |
||||||
|
Console::output('<red>FAIL</red>', 0, 1); |
||||||
|
Console::output('Corrupted download.', 2); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -1,19 +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_Command_BuiltIn_Version |
|
||||||
extends Mage_Command_CommandAbstract |
|
||||||
{ |
|
||||||
public function run() |
|
||||||
{ |
|
||||||
Mage_Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,34 @@ |
|||||||
|
<?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\Command\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Command\AbstractCommand; |
||||||
|
use Mage\Console; |
||||||
|
|
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Command for displaying the Version of Magallanes |
||||||
|
* |
||||||
|
* @author Andrés Montañez <andres@andresmontanez.com> |
||||||
|
*/ |
||||||
|
class VersionCommand extends AbstractCommand |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Display the Magallanes Version |
||||||
|
* @see \Mage\Command\AbstractCommand::run() |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,30 +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_Command_CommandAbstract |
|
||||||
{ |
|
||||||
protected $_config = null; |
|
||||||
|
|
||||||
public abstract function run(); |
|
||||||
|
|
||||||
public function setConfig(Mage_Config $config) |
|
||||||
{ |
|
||||||
$this->_config = $config; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @return Mage_Config |
|
||||||
*/ |
|
||||||
public function getConfig() |
|
||||||
{ |
|
||||||
return $this->_config; |
|
||||||
} |
|
||||||
} |
|
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue