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:
@@ -8,9 +8,27 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Command_BuiltIn_Add
|
||||
extends Mage_Command_CommandAbstract
|
||||
namespace Mage\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Console;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Command for Adding elements to the Configuration.
|
||||
* Currently elements allowed to add:
|
||||
* - environments
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class AddCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* Adds new Configuration Elements
|
||||
* @see \Mage\Command\AbstractCommand::run()
|
||||
* @throws Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$subCommand = $this->getConfig()->getArgument(1);
|
||||
@@ -18,15 +36,24 @@ class Mage_Command_BuiltIn_Add
|
||||
try {
|
||||
switch ($subCommand) {
|
||||
case 'environment':
|
||||
$this->_environment();
|
||||
$this->addEnvironment();
|
||||
break;
|
||||
|
||||
default;
|
||||
throw new Exception('The Type of Add is needed.');
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Mage_Console::output('<red>' . $e->getMessage() . '</red>', 1, 2);
|
||||
} catch (Exception $exception) {
|
||||
Console::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private function _environment()
|
||||
/**
|
||||
* Adds an Environment
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function addEnvironment()
|
||||
{
|
||||
$withReleases = $this->getConfig()->getParameter('enableReleases', false);
|
||||
$environmentName = strtolower($this->getConfig()->getParameter('name'));
|
||||
@@ -41,7 +68,7 @@ class Mage_Command_BuiltIn_Add
|
||||
throw new Exception('The environment already exists.');
|
||||
}
|
||||
|
||||
Mage_Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
|
||||
Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
|
||||
|
||||
$releasesConfig = 'releases:' . PHP_EOL
|
||||
. ' enabled: true' . PHP_EOL
|
||||
@@ -67,10 +94,10 @@ class Mage_Command_BuiltIn_Add
|
||||
$result = file_put_contents($environmentConfigFile, $baseConfig);
|
||||
|
||||
if ($result) {
|
||||
Mage_Console::output('<light_green>Success!!</light_green> Environment config file for <dark_gray>' . $environmentName . '</dark_gray> created successfully at <blue>' . $environmentConfigFile . '</blue>');
|
||||
Mage_Console::output('<dark_gray>So please! Review and adjust its configuration.</dark_gray>', 2, 2);
|
||||
Console::output('<light_green>Success!!</light_green> Environment config file for <dark_gray>' . $environmentName . '</dark_gray> created successfully at <blue>' . $environmentConfigFile . '</blue>');
|
||||
Console::output('<dark_gray>So please! Review and adjust its configuration.</dark_gray>', 2, 2);
|
||||
} else {
|
||||
Mage_Console::output('<light_red>Error!!</light_red> Unable to create config file for environment called <dark_gray>' . $environmentName . '</dark_gray>', 1, 2);
|
||||
Console::output('<light_red>Error!!</light_red> Unable to create config file for environment called <dark_gray>' . $environmentName . '</dark_gray>', 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -8,42 +8,96 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Command_BuiltIn_Deploy
|
||||
extends Mage_Command_CommandAbstract
|
||||
implements Mage_Command_RequiresEnvironment
|
||||
namespace Mage\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Command\RequiresEnvironment;
|
||||
use Mage\Task\Factory;
|
||||
use Mage\Task\Releases\SkipOnOverride;
|
||||
use Mage\Task\ErrorWithMessageException;
|
||||
use Mage\Task\SkipException;
|
||||
use Mage\Console;
|
||||
use Mage\Config;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Command for Deploying
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
||||
{
|
||||
/**
|
||||
* Deploy has Failed
|
||||
* @var string
|
||||
*/
|
||||
const FAILED = 'failed';
|
||||
|
||||
/**
|
||||
* Deploy has Succeded
|
||||
* @var string
|
||||
*/
|
||||
const SUCCEDED = 'succeded';
|
||||
|
||||
/**
|
||||
* Deploy is in progress
|
||||
* @var string
|
||||
*/
|
||||
const IN_PROGRESS = 'in_progress';
|
||||
|
||||
private $_startTime = null;
|
||||
private $_startTimeHosts = null;
|
||||
private $_endTimeHosts = null;
|
||||
private $_hostsCount = 0;
|
||||
/**
|
||||
* Time the Deployment has Started
|
||||
* @var integer
|
||||
*/
|
||||
protected $startTime = null;
|
||||
|
||||
private static $_deployStatus = 'in_progress';
|
||||
/**
|
||||
* Time the Deployment has Started to the current Host
|
||||
* @var integer
|
||||
*/
|
||||
protected $startTimeHosts = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Time the Deployment to the Hosts has Finished
|
||||
* @var integer
|
||||
*/
|
||||
protected $endTimeHosts = null;
|
||||
|
||||
/**
|
||||
* Quantity of Hosts to Deploy to.
|
||||
* @var integer
|
||||
*/
|
||||
protected $hostsCount = 0;
|
||||
|
||||
protected static $deployStatus = 'in_progress';
|
||||
|
||||
/**
|
||||
* Returns the Status of the Deployment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getStatus()
|
||||
{
|
||||
return self::$_deployStatus;
|
||||
return self::$deployStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploys the Application
|
||||
* @see \Mage\Command\AbstractCommand::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Check if Environment is not Locked
|
||||
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
||||
if (file_exists($lockFile)) {
|
||||
Mage_Console::output('<red>This environment is locked!</red>', 1, 2);
|
||||
Console::output('<red>This environment is locked!</red>', 1, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for running instance and Lock
|
||||
if (file_exists('.mage/~working.lock')) {
|
||||
Mage_Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
|
||||
Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
|
||||
return;
|
||||
} else {
|
||||
touch('.mage/~working.lock');
|
||||
@@ -54,48 +108,48 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$failedTasks = 0;
|
||||
|
||||
// Deploy Summary
|
||||
Mage_Console::output('<dark_gray>Deploy summary</dark_gray>', 1, 1);
|
||||
Console::output('<dark_gray>Deploy summary</dark_gray>', 1, 1);
|
||||
|
||||
// Deploy Summary - Environment
|
||||
Mage_Console::output('<dark_gray>Environment:</dark_gray> <purple>' . $this->getConfig()->getEnvironment() . '</purple>', 2, 1);
|
||||
Console::output('<dark_gray>Environment:</dark_gray> <purple>' . $this->getConfig()->getEnvironment() . '</purple>', 2, 1);
|
||||
|
||||
// Deploy Summary - Releases
|
||||
if ($this->getConfig()->release('enabled', false)) {
|
||||
Mage_Console::output('<dark_gray>Release ID:</dark_gray> <purple>' . $this->getConfig()->getReleaseId() . '</purple>', 2, 1);
|
||||
Console::output('<dark_gray>Release ID:</dark_gray> <purple>' . $this->getConfig()->getReleaseId() . '</purple>', 2, 1);
|
||||
}
|
||||
|
||||
// Deploy Summary - SCM
|
||||
if ($this->getConfig()->deployment('scm', false)) {
|
||||
$scmConfig = $this->getConfig()->deployment('scm');
|
||||
if (isset($scmConfig['branch'])) {
|
||||
Mage_Console::output('<dark_gray>SCM Branch:</dark_gray> <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
|
||||
Console::output('<dark_gray>SCM Branch:</dark_gray> <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Deploy Summary - Separator Line
|
||||
Mage_Console::output('', 0, 1);
|
||||
Console::output('', 0, 1);
|
||||
|
||||
$this->_startTime = time();
|
||||
$this->startTime = time();
|
||||
|
||||
// Run Pre-Deployment Tasks
|
||||
$this->_runNonDeploymentTasks('pre-deploy', $this->getConfig(), 'Pre-Deployment');
|
||||
$this->runNonDeploymentTasks('pre-deploy', $this->getConfig(), 'Pre-Deployment');
|
||||
|
||||
// Run Tasks for Deployment
|
||||
$hosts = $this->getConfig()->getHosts();
|
||||
$this->_hostsCount = count($hosts);
|
||||
$this->hostsCount = count($hosts);
|
||||
|
||||
if ($this->_hostsCount == 0) {
|
||||
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
|
||||
if ($this->hostsCount == 0) {
|
||||
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
|
||||
|
||||
} else {
|
||||
$this->_startTimeHosts = time();
|
||||
foreach ($hosts as $_hostKey => $host) {
|
||||
$this->startTimeHosts = time();
|
||||
foreach ($hosts as $hostKey => $host) {
|
||||
|
||||
// Check if Host has specific configuration
|
||||
$hostConfig = null;
|
||||
if (is_array($host)) {
|
||||
$hostConfig = $host;
|
||||
$host = $_hostKey;
|
||||
$host = $hostKey;
|
||||
}
|
||||
|
||||
// Set Host and Host Specific Config
|
||||
@@ -106,21 +160,21 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
Mage_Console::output('Deploying to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
Console::output('Deploying to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
|
||||
|
||||
$tasksToRun = $this->getConfig()->getTasks();
|
||||
array_unshift($tasksToRun, 'deployment/rsync');
|
||||
|
||||
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>' . $host . '</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>' . $host . '</dark_gray> skipped!', 1, 3);
|
||||
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskData) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskData, $this->getConfig(), false, 'deploy');
|
||||
$task = Factory::get($taskData, $this->getConfig(), false, 'deploy');
|
||||
|
||||
if ($this->_runTask($task)) {
|
||||
if ($this->runTask($task)) {
|
||||
$completedTasks++;
|
||||
} else {
|
||||
$failedTasks++;
|
||||
@@ -133,34 +187,34 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$tasksColor = 'red';
|
||||
}
|
||||
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
|
||||
// Reset Host Config
|
||||
$this->getConfig()->setHostConfig(null);
|
||||
}
|
||||
$this->_endTimeHosts = time();
|
||||
$this->endTimeHosts = time();
|
||||
|
||||
if ($failedTasks > 0) {
|
||||
self::$_deployStatus = self::FAILED;
|
||||
Mage_Console::output('A total of <dark_gray>' . $failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
|
||||
self::$deployStatus = self::FAILED;
|
||||
Console::output('A total of <dark_gray>' . $failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
|
||||
} else {
|
||||
self::$_deployStatus = self::SUCCEDED;
|
||||
self::$deployStatus = self::SUCCEDED;
|
||||
}
|
||||
|
||||
// Releasing
|
||||
if (self::$_deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) == true) {
|
||||
if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) == true) {
|
||||
// Execute the Releases
|
||||
Mage_Console::output('Starting the <dark_gray>Releaseing</dark_gray>');
|
||||
Console::output('Starting the <dark_gray>Releaseing</dark_gray>');
|
||||
foreach ($hosts as $host) {
|
||||
$this->getConfig()->setHost($host);
|
||||
$task = Mage_Task_Factory::get('deployment/release', $this->getConfig(), false, 'deploy');
|
||||
$task = Factory::get('deployment/release', $this->getConfig(), false, 'deploy');
|
||||
|
||||
if ($this->_runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
|
||||
if ($this->runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
|
||||
$completedTasks++;
|
||||
}
|
||||
}
|
||||
Mage_Console::output('Finished the <dark_gray>Releaseing</dark_gray>', 1, 3);
|
||||
Console::output('Finished the <dark_gray>Releaseing</dark_gray>', 1, 3);
|
||||
|
||||
// Execute the Post-Release Tasks
|
||||
foreach ($hosts as $host) {
|
||||
@@ -170,12 +224,12 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$completedTasks = 0;
|
||||
|
||||
if (count($tasksToRun) > 0) {
|
||||
Mage_Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
|
||||
Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
|
||||
|
||||
foreach ($tasksToRun as $task) {
|
||||
$task = Mage_Task_Factory::get($task, $this->getConfig(), false, 'post-release');
|
||||
$task = Factory::get($task, $this->getConfig(), false, 'post-release');
|
||||
|
||||
if ($this->_runTask($task)) {
|
||||
if ($this->runTask($task)) {
|
||||
$completedTasks++;
|
||||
}
|
||||
}
|
||||
@@ -185,30 +239,30 @@ class Mage_Command_BuiltIn_Deploy
|
||||
} else {
|
||||
$tasksColor = 'red';
|
||||
}
|
||||
Mage_Console::output('Finished <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Console::output('Finished <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run Post-Deployment Tasks
|
||||
$this->_runNonDeploymentTasks('post-deploy', $this->getConfig(), 'Post-Deployment');
|
||||
$this->runNonDeploymentTasks('post-deploy', $this->getConfig(), 'Post-Deployment');
|
||||
|
||||
// Time Information Hosts
|
||||
if ($this->_hostsCount > 0) {
|
||||
$timeTextHost = $this->_transcurredTime($this->_endTimeHosts - $this->_startTimeHosts);
|
||||
Mage_Console::output('Time for deployment: <dark_gray>' . $timeTextHost . '</dark_gray>.');
|
||||
if ($this->hostsCount > 0) {
|
||||
$timeTextHost = $this->transcurredTime($this->endTimeHosts - $this->startTimeHosts);
|
||||
Console::output('Time for deployment: <dark_gray>' . $timeTextHost . '</dark_gray>.');
|
||||
|
||||
$timeTextPerHost = $this->_transcurredTime(round(($this->_endTimeHosts - $this->_startTimeHosts) / $this->_hostsCount));
|
||||
Mage_Console::output('Average time per host: <dark_gray>' . $timeTextPerHost . '</dark_gray>.');
|
||||
$timeTextPerHost = $this->transcurredTime(round(($this->endTimeHosts - $this->startTimeHosts) / $this->hostsCount));
|
||||
Console::output('Average time per host: <dark_gray>' . $timeTextPerHost . '</dark_gray>.');
|
||||
}
|
||||
|
||||
// Time Information General
|
||||
$timeText = $this->_transcurredTime(time() - $this->_startTime);
|
||||
Mage_Console::output('Total time: <dark_gray>' . $timeText . '</dark_gray>.', 1, 2);
|
||||
$timeText = $this->transcurredTime(time() - $this->startTime);
|
||||
Console::output('Total time: <dark_gray>' . $timeText . '</dark_gray>.', 1, 2);
|
||||
|
||||
// Send Notifications
|
||||
$this->_sendNotification();
|
||||
$this->sendNotification();
|
||||
|
||||
// Unlock
|
||||
if (file_exists('.mage/~working.lock')) {
|
||||
@@ -220,22 +274,22 @@ class Mage_Command_BuiltIn_Deploy
|
||||
* Execute Pre and Post Deployment Tasks
|
||||
*
|
||||
* @param string $stage
|
||||
* @param Mage_Config $config
|
||||
* @param Config $config
|
||||
* @param string $title
|
||||
*/
|
||||
private function _runNonDeploymentTasks($stage, Mage_Config $config, $title)
|
||||
protected function runNonDeploymentTasks($stage, Config $config, $title)
|
||||
{
|
||||
$tasksToRun = $config->getTasks($stage);
|
||||
|
||||
// PreDeployment Hook
|
||||
if ($stage == 'pre-deploy') {
|
||||
// Look for Remote Source
|
||||
if (is_array($this->_config->deployment('source', null))) {
|
||||
if (is_array($config->deployment('source', null))) {
|
||||
array_unshift($tasksToRun, 'scm/clone');
|
||||
}
|
||||
|
||||
// Change Branch
|
||||
if ($this->getConfig()->deployment('scm', false)) {
|
||||
if ($config->deployment('scm', false)) {
|
||||
array_unshift($tasksToRun, 'scm/change-branch');
|
||||
}
|
||||
}
|
||||
@@ -243,36 +297,36 @@ class Mage_Command_BuiltIn_Deploy
|
||||
// PostDeployment Hook
|
||||
if ($stage == 'post-deploy') {
|
||||
// If Deploy failed, clear post deploy tasks
|
||||
if (self::$_deployStatus == self::FAILED) {
|
||||
if (self::$deployStatus == self::FAILED) {
|
||||
$tasksToRun = array();
|
||||
}
|
||||
|
||||
// Change Branch Back
|
||||
if ($this->getConfig()->deployment('scm', false)) {
|
||||
if ($config->deployment('scm', false)) {
|
||||
array_unshift($tasksToRun, 'scm/change-branch');
|
||||
$config->addParameter('_changeBranchRevert');
|
||||
}
|
||||
|
||||
// Remove Remote Source
|
||||
if (is_array($this->_config->deployment('source', null))) {
|
||||
if (is_array($config->deployment('source', null))) {
|
||||
array_push($tasksToRun, 'scm/remove-clone');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($tasksToRun) == 0) {
|
||||
Mage_Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
|
||||
Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
|
||||
|
||||
} else {
|
||||
Mage_Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
|
||||
Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
|
||||
|
||||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
foreach ($tasksToRun as $taskData) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskData, $config, false, $stage);
|
||||
$task = Factory::get($taskData, $config, false, $stage);
|
||||
|
||||
if ($this->_runTask($task)) {
|
||||
if ($this->runTask($task)) {
|
||||
$completedTasks++;
|
||||
}
|
||||
}
|
||||
@@ -283,21 +337,28 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$tasksColor = 'red';
|
||||
}
|
||||
|
||||
Mage_Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
}
|
||||
|
||||
private function _runTask($task, $title = null)
|
||||
/**
|
||||
* Runs a Task
|
||||
*
|
||||
* @param string $task
|
||||
* @param string $title
|
||||
* @return boolean
|
||||
*/
|
||||
protected function runTask($task, $title = null)
|
||||
{
|
||||
$task->init();
|
||||
|
||||
if ($title == null) {
|
||||
$title = 'Running <purple>' . $task->getName() . '</purple> ... ';
|
||||
}
|
||||
Mage_Console::output($title, 2, 0);
|
||||
Console::output($title, 2, 0);
|
||||
|
||||
$runTask = true;
|
||||
if (($task instanceOf Mage_Task_Releases_SkipOnOverride) && $this->getConfig()->getParameter('overrideRelease', false)) {
|
||||
if (($task instanceOf SkipOnOverride) && $this->getConfig()->getParameter('overrideRelease', false)) {
|
||||
$runTask == false;
|
||||
}
|
||||
|
||||
@@ -307,27 +368,27 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$result = $task->run();
|
||||
|
||||
if ($result == true) {
|
||||
Mage_Console::output('<green>OK</green>', 0);
|
||||
Console::output('<green>OK</green>', 0);
|
||||
$result = true;
|
||||
|
||||
} else {
|
||||
Mage_Console::output('<red>FAIL</red>', 0);
|
||||
Console::output('<red>FAIL</red>', 0);
|
||||
$result = false;
|
||||
}
|
||||
} catch (Mage_Task_ErrorWithMessageException $e) {
|
||||
Mage_Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
|
||||
} catch (ErrorWithMessageException $e) {
|
||||
Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
|
||||
$result = false;
|
||||
|
||||
} catch (Mage_Task_SkipException $e) {
|
||||
Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
} catch (SkipException $e) {
|
||||
Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
$result = true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
Mage_Console::output('<red>FAIL</red>', 0);
|
||||
Console::output('<red>FAIL</red>', 0);
|
||||
$result = false;
|
||||
}
|
||||
} else {
|
||||
Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
Console::output('<yellow>SKIPPED</yellow>', 0);
|
||||
$result = true;
|
||||
}
|
||||
|
||||
@@ -336,10 +397,11 @@ class Mage_Command_BuiltIn_Deploy
|
||||
|
||||
/**
|
||||
* Humanize Transcurred time
|
||||
*
|
||||
* @param integer $time
|
||||
* @return string
|
||||
*/
|
||||
private function _transcurredTime($time)
|
||||
protected function transcurredTime($time)
|
||||
{
|
||||
$hours = floor($time / 3600);
|
||||
$minutes = floor(($time - ($hours * 3600)) / 60);
|
||||
@@ -354,7 +416,7 @@ class Mage_Command_BuiltIn_Deploy
|
||||
$timeText[] = $minutes . ' minutes';
|
||||
}
|
||||
|
||||
if ($seconds > 0) {
|
||||
if ($seconds >= 0) {
|
||||
$timeText[] = $seconds . ' seconds';
|
||||
}
|
||||
|
||||
@@ -364,7 +426,7 @@ class Mage_Command_BuiltIn_Deploy
|
||||
/**
|
||||
* Send Email Notification if enabled
|
||||
*/
|
||||
private function _sendNotification()
|
||||
protected function sendNotification()
|
||||
{
|
||||
$projectName = $this->getConfig()->general('name', false);
|
||||
$projectEmail = $this->getConfig()->general('email', false);
|
||||
@@ -375,4 +437,5 @@ class Mage_Command_BuiltIn_Deploy
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,27 +8,34 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Command_BuiltIn_Init
|
||||
extends Mage_Command_CommandAbstract
|
||||
{
|
||||
protected $generalTemplate = <<<'YML'
|
||||
# global settings
|
||||
name: %projectName%
|
||||
email: %notificationEmail%
|
||||
notifications: %notificationEnabled%
|
||||
logging: %loggingEnabled%
|
||||
maxlogs: %maxlogs%
|
||||
YML;
|
||||
namespace Mage\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Console;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Initializes a Magallanes Configuration into a Proyect
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class InitCommand extends AbstractCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Command for Initalize a new Configuration Proyect
|
||||
* @see \Mage\Command\AbstractCommand::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$configDir = '.mage';
|
||||
|
||||
Mage_Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
|
||||
Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
|
||||
|
||||
// Check if there is already a config dir
|
||||
if (file_exists($configDir)) {
|
||||
Mage_Console::output('<light_red>Error!!</light_red> Already exists <dark_gray>.mage</dark_gray> directory.', 1, 2);
|
||||
Console::output('<light_red>Error!!</light_red> Already exists <dark_gray>.mage</dark_gray> directory.', 1, 2);
|
||||
} else {
|
||||
$results = array();
|
||||
$results[] = mkdir($configDir);
|
||||
@@ -42,14 +49,18 @@ YML;
|
||||
$results[] = file_put_contents($configDir . '/config/general.yml', $this->getGeneralConfig());
|
||||
|
||||
if (!in_array(false, $results)) {
|
||||
Mage_Console::output('<light_green>Success!!</light_green> The configuration for <dark_gray>Magallanes</dark_gray> has been generated at <blue>.mage</blue> directory.');
|
||||
Mage_Console::output('<dark_gray>Please!! Review and adjust the configuration.</dark_gray>', 2, 2);
|
||||
Console::output('<light_green>Success!!</light_green> The configuration for <dark_gray>Magallanes</dark_gray> has been generated at <blue>.mage</blue> directory.');
|
||||
Console::output('<dark_gray>Please!! Review and adjust the configuration.</dark_gray>', 2, 2);
|
||||
} else {
|
||||
Mage_Console::output('<light_red>Error!!</light_red> Unable to generate the configuration.', 1, 2);
|
||||
Console::output('<light_red>Error!!</light_red> Unable to generate the configuration.', 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Global Configuration
|
||||
* @return string
|
||||
*/
|
||||
protected function getGeneralConfig()
|
||||
{
|
||||
// Assamble Global Settings
|
||||
@@ -77,4 +88,20 @@ YML;
|
||||
|
||||
return $globalSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the YAML Template for the Global Configuration
|
||||
* @return string
|
||||
*/
|
||||
protected function getGeneralConfigTemplate()
|
||||
{
|
||||
$template = '# global settings' . PHP_EOL
|
||||
. 'name: %projectName%' . PHP_EOL
|
||||
. 'email: %notificationEmail%' . PHP_EOL
|
||||
. 'notifications: %notificationEnabled%' . PHP_EOL
|
||||
. 'logging: %loggingEnabled%' . PHP_EOL
|
||||
. 'maxlogs: %maxlogs%' . PHP_EOL;
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,27 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Command_BuiltIn_Install
|
||||
extends Mage_Command_CommandAbstract
|
||||
namespace Mage\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Console;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Installs Magallanes in the Local System
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class InstallCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* Installs Magallanes
|
||||
* @see \Mage\Command\AbstractCommand::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Mage_Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||
Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||
|
||||
// Vars
|
||||
$installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes');
|
||||
@@ -25,11 +40,11 @@ class Mage_Command_BuiltIn_Install
|
||||
|
||||
// Check if install dir is available
|
||||
if (!is_dir($baseDir) || !is_writable($baseDir)) {
|
||||
Mage_Console::output('<red>Failure: install directory is invalid.</red>', 0, 2);
|
||||
Console::output('<red>Failure: install directory is invalid.</red>', 0, 2);
|
||||
|
||||
// Chck if it is a system wide install the user is root
|
||||
} else if ($systemWide && (getenv('LOGNAME') != 'root')) {
|
||||
Mage_Console::output('<red>Failure: you have to be root to perform a system wide install.</red>', 0, 2);
|
||||
Console::output('<red>Failure: you have to be root to perform a system wide install.</red>', 0, 2);
|
||||
|
||||
} else {
|
||||
$destinationDir = $baseDir . '/' . $installDir;
|
||||
@@ -38,7 +53,7 @@ class Mage_Command_BuiltIn_Install
|
||||
}
|
||||
|
||||
// Copy
|
||||
$this->_recursiveCopy('./', $destinationDir . '/' . MAGALLANES_VERSION);
|
||||
$this->recursiveCopy('./', $destinationDir . '/' . MAGALLANES_VERSION);
|
||||
|
||||
// Check if there is already a symlink
|
||||
if (file_exists($destinationDir . '/' . 'latest')
|
||||
@@ -59,11 +74,17 @@ class Mage_Command_BuiltIn_Install
|
||||
}
|
||||
}
|
||||
|
||||
Mage_Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||
Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private function _recursiveCopy($from, $to)
|
||||
/**
|
||||
* Copy Files
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return boolean
|
||||
*/
|
||||
protected function recursiveCopy($from, $to)
|
||||
{
|
||||
if (is_dir($from)) {
|
||||
mkdir($to);
|
||||
@@ -76,7 +97,7 @@ class Mage_Command_BuiltIn_Install
|
||||
}
|
||||
|
||||
if (is_dir($from . DIRECTORY_SEPARATOR . $file)) {
|
||||
$this->_recursiveCopy(
|
||||
$this->recursiveCopy(
|
||||
$from . DIRECTORY_SEPARATOR . $file,
|
||||
$to . DIRECTORY_SEPARATOR . $file
|
||||
);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,18 +8,34 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Mage_Command_BuiltIn_Releases
|
||||
extends Mage_Command_CommandAbstract
|
||||
implements Mage_Command_RequiresEnvironment
|
||||
{
|
||||
private $_release = null;
|
||||
namespace Mage\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Command\RequiresEnvironment;
|
||||
use Mage\Task\Factory;
|
||||
use Mage\Console;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Command for Managing the Releases
|
||||
*
|
||||
* @author Andrés Montañez <andres@andresmontanez.com>
|
||||
*/
|
||||
class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
||||
{
|
||||
private $release = null;
|
||||
|
||||
/**
|
||||
* List the Releases, Rollback to a Release
|
||||
* @see \Mage\Command\AbstractCommand::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$subcommand = $this->getConfig()->getArgument(1);
|
||||
$lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
||||
if (file_exists($lockFile) && ($subcommand == 'rollback')) {
|
||||
Mage_Console::output('<red>This environment is locked!</red>', 0, 2);
|
||||
Console::output('<red>This environment is locked!</red>', 0, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,7 +43,7 @@ class Mage_Command_BuiltIn_Releases
|
||||
$hosts = $this->getConfig()->getHosts();
|
||||
|
||||
if (count($hosts) == 0) {
|
||||
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
|
||||
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
|
||||
|
||||
} else {
|
||||
foreach ($hosts as $host) {
|
||||
@@ -35,14 +51,14 @@ class Mage_Command_BuiltIn_Releases
|
||||
|
||||
switch ($subcommand) {
|
||||
case 'list':
|
||||
$task = Mage_Task_Factory::get('releases/list', $this->getConfig());
|
||||
$task = Factory::get('releases/list', $this->getConfig());
|
||||
$task->init();
|
||||
$result = $task->run();
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
$releaseId = $this->getConfig()->getParameter('release', '');
|
||||
$task = Mage_Task_Factory::get('releases/rollback', $this->getConfig());
|
||||
$task = Factory::get('releases/rollback', $this->getConfig());
|
||||
$task->init();
|
||||
$task->setRelease($releaseId);
|
||||
$result = $task->run();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user