Browse Source

Merge branch 'develop'

1.0 1.0.3
Andrés Montañez 10 years ago
parent
commit
5199a915b6
  1. 6
      .gitignore
  2. 8
      Mage/Command/BuiltIn/AddCommand.php
  3. 2
      Mage/Command/BuiltIn/CompileCommand.php
  4. 87
      Mage/Command/BuiltIn/DeployCommand.php
  5. 8
      Mage/Command/BuiltIn/InitCommand.php
  6. 2
      Mage/Command/BuiltIn/InstallCommand.php
  7. 8
      Mage/Command/BuiltIn/ListCommand.php
  8. 21
      Mage/Command/BuiltIn/ReleasesCommand.php
  9. 19
      Mage/Command/BuiltIn/RollbackCommand.php
  10. 3
      Mage/Command/BuiltIn/UpdateCommand.php
  11. 6
      Mage/Command/BuiltIn/UpgradeCommand.php
  12. 3
      Mage/Command/BuiltIn/VersionCommand.php
  13. 1
      Mage/Command/Factory.php
  14. 32
      Mage/Config.php
  15. 17
      Mage/Console.php
  16. 2
      Mage/Console/Colors.php
  17. 2
      Mage/Mailer.php
  18. 6
      Mage/Task/AbstractTask.php
  19. 4
      Mage/Task/BuiltIn/Deployment/ReleaseTask.php
  20. 2
      Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php
  21. 1
      Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php
  22. 15
      Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php
  23. 39
      Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php
  24. 22
      Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php
  25. 26
      Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php
  26. 45
      Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php
  27. 11
      Mage/Task/BuiltIn/Releases/ListTask.php
  28. 15
      Mage/Task/BuiltIn/Releases/RollbackTask.php
  29. 9
      Mage/Task/BuiltIn/Scm/CloneTask.php
  30. 87
      Mage/Task/BuiltIn/Scm/ForceUpdateTask.php
  31. 40
      Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php
  32. 1
      Mage/Task/Factory.php
  33. 23
      Mage/Task/RollbackException.php
  34. 1
      Mage/Yaml/Parser.php
  35. 4
      bin/mage
  36. 16
      box.json
  37. 14
      docs/example-config/.mage/config/environment/ioncube.yml.txt
  38. 23
      docs/example-config/.mage/config/environment/production.yml
  39. 38
      docs/example-config/.mage/config/environment/production.yml.advanced.txt
  40. 1
      docs/example-config/.mage/tasks/SampleTaskRollbackAware.php
  41. 8
      docs/example-config/.mage/tasks/TaskWithParameters.php

6
.gitignore vendored

@ -1,9 +1,5 @@
.settings
.settings/*
.project
.buildpath
.idea
vendor
mage.phar
# OS generated files # // GitHub Recommendation
######################

8
Mage/Command/BuiltIn/AddCommand.php

@ -68,7 +68,7 @@ class AddCommand extends AbstractCommand
throw new Exception('The environment already exists.');
}
Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
Console::output('Adding new environment: <bold>' . $environmentName . '</bold>');
$releasesConfig = 'releases:' . PHP_EOL
. ' enabled: true' . PHP_EOL
@ -93,10 +93,10 @@ class AddCommand extends AbstractCommand
$result = file_put_contents($environmentConfigFile, $baseConfig);
if ($result) {
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);
Console::output('<light_green>Success!!</light_green> Environment config file for <bold>' . $environmentName . '</bold> created successfully at <blue>' . $environmentConfigFile . '</blue>');
Console::output('<bold>So please! Review and adjust its configuration.</bold>', 2, 2);
} else {
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 <bold>' . $environmentName . '</bold>', 1, 2);
}
}
}

2
Mage/Command/BuiltIn/CompileCommand.php

@ -28,7 +28,7 @@ class CompileCommand extends AbstractCommand
{
if (ini_get('phar.readonly')) {
Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);
return 300;
return 200;
}
$compiler = new Compiler;

87
Mage/Command/BuiltIn/DeployCommand.php

@ -3,6 +3,7 @@
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
* (c) Alex V Kotelnikov <gudron@gudron.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -16,6 +17,7 @@ use Mage\Task\Factory;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\SkipOnOverride;
use Mage\Task\ErrorWithMessageException;
use Mage\Task\RollbackException;
use Mage\Task\SkipException;
use Mage\Console;
use Mage\Config;
@ -109,20 +111,20 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
*/
public function run()
{
$exitCode = 1000;
$exitCode = 240;
// Check if Environment is not Locked
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
if (file_exists($lockFile)) {
Console::output('<red>This environment is locked!</red>', 1, 2);
echo file_get_contents($lockFile);
return 1010;
return 231;
}
// Check for running instance and Lock
if (file_exists(getcwd() . '/.mage/~working.lock')) {
Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
return 1020;
return 230;
} else {
touch(getcwd() . '/.mage/~working.lock');
}
@ -131,21 +133,21 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$this->getConfig()->setReleaseId(date('YmdHis'));
// Deploy Summary
Console::output('<dark_gray>Deploy summary</dark_gray>', 1, 1);
Console::output('<bold>Deploy summary</bold>', 1, 1);
// Deploy Summary - Environment
Console::output('<dark_gray>Environment:</dark_gray> <purple>' . $this->getConfig()->getEnvironment() . '</purple>', 2, 1);
Console::output('<bold>Environment:</bold> <purple>' . $this->getConfig()->getEnvironment() . '</purple>', 2, 1);
// Deploy Summary - Releases
if ($this->getConfig()->release('enabled', false)) {
Console::output('<dark_gray>Release ID:</dark_gray> <purple>' . $this->getConfig()->getReleaseId() . '</purple>', 2, 1);
Console::output('<bold>Release ID:</bold> <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'])) {
Console::output('<dark_gray>SCM Branch:</dark_gray> <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
Console::output('<bold>SCM Branch:</bold> <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
}
}
@ -160,7 +162,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
// Check Status
if (self::$failedTasks > 0) {
self::$deployStatus = self::FAILED;
Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
Console::output('A total of <bold>' . self::$failedTasks . '</bold> deployment tasks failed: <red>ABORTING</red>', 1, 2);
} else {
// Run Deployment Tasks
@ -169,7 +171,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
// Check Status
if (self::$failedTasks > 0) {
self::$deployStatus = self::FAILED;
Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
Console::output('A total of <bold>' . self::$failedTasks . '</bold> deployment tasks failed: <red>ABORTING</red>', 1, 2);
}
// Run Post-Deployment Tasks
@ -179,15 +181,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
// Time Information Hosts
if ($this->hostsCount > 0) {
$timeTextHost = $this->transcurredTime($this->endTimeHosts - $this->startTimeHosts);
Console::output('Time for deployment: <dark_gray>' . $timeTextHost . '</dark_gray>.');
Console::output('Time for deployment: <bold>' . $timeTextHost . '</bold>.');
$timeTextPerHost = $this->transcurredTime(round(($this->endTimeHosts - $this->startTimeHosts) / $this->hostsCount));
Console::output('Average time per host: <dark_gray>' . $timeTextPerHost . '</dark_gray>.');
Console::output('Average time per host: <bold>' . $timeTextPerHost . '</bold>.');
}
// Time Information General
$timeText = $this->transcurredTime(time() - $this->startTime);
Console::output('Total time: <dark_gray>' . $timeText . '</dark_gray>.', 1, 2);
Console::output('Total time: <bold>' . $timeText . '</bold>.', 1, 2);
// Send Notifications
$this->sendNotification(self::$failedTasks > 0 ? false : true);
@ -249,10 +251,10 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
}
if (count($tasksToRun) == 0) {
Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
Console::output('<bold>No </bold><light_cyan>' . $title . '</light_cyan> <bold>tasks defined.</bold>', 1, 3);
} else {
Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
Console::output('Starting <bold>' . $title . '</bold> tasks:');
$tasks = 0;
$completedTasks = 0;
@ -274,7 +276,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$tasksColor = 'red';
}
Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
Console::output('Finished <bold>' . $title . '</bold> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
}
}
@ -290,7 +292,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
self::$failedTasks = 0;
if ($this->hostsCount == 0) {
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
Console::output('<light_purple>Warning!</light_purple> <bold>No hosts defined, skipping deployment tasks.</bold>', 1, 3);
} else {
$this->startTimeHosts = time();
@ -311,7 +313,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$tasks = 0;
$completedTasks = 0;
Console::output('Deploying to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
Console::output('Deploying to <bold>' . $this->getConfig()->getHost() . '</bold>');
$tasksToRun = $this->getConfig()->getTasks();
@ -320,8 +322,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
array_unshift($tasksToRun, $deployStrategy);
if (count($tasksToRun) == 0) {
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);
Console::output('<light_purple>Warning!</light_purple> <bold>No </bold><light_cyan>Deployment</light_cyan> <bold>tasks defined.</bold>', 2);
Console::output('Deployment to <bold>' . $host . '</bold> skipped!', 1, 3);
} else {
foreach ($tasksToRun as $taskData) {
@ -341,7 +343,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$tasksColor = 'red';
}
Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
Console::output('Deployment to <bold>' . $this->getConfig()->getHost() . '</bold> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
}
// Reset Host Config
@ -356,9 +358,9 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
}
// 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
Console::output('Starting the <dark_gray>Releasing</dark_gray>');
Console::output('Starting the <bold>Releasing</bold>');
$completedTasks = 0;
foreach ($hosts as $hostKey => $host) {
@ -382,7 +384,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
// Reset Host Config
$this->getConfig()->setHostConfig(null);
}
Console::output('Finished the <dark_gray>Releasing</dark_gray>', 1, 3);
Console::output('Finished the <bold>Releasing</bold>', 1, 3);
// Execute the Post-Release Tasks
foreach ($hosts as $hostKey => $host) {
@ -403,7 +405,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$completedTasks = 0;
if (count($tasksToRun) > 0) {
Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
Console::output('Starting <bold>Post-Release</bold> tasks for <bold>' . $host . '</bold>:');
foreach ($tasksToRun as $task) {
$task = Factory::get($task, $this->getConfig(), false, AbstractTask::STAGE_POST_RELEASE);
@ -418,7 +420,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
} else {
$tasksColor = 'red';
}
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 <bold>Post-Release</bold> tasks for <bold>' . $host . '</bold>: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
}
// Reset Host Config
@ -428,6 +430,28 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
}
}
protected function runRollbackTask(){
$this->getConfig()->reload();
$hosts = $this->getConfig()->getHosts();
if (count($hosts) == 0) {
Console::output('<light_purple>Warning!</light_purple> <bold>No hosts defined, unable to get releases.</bold>', 1, 3);
} else {
$result = true;
foreach ($hosts as $host) {
$this->getConfig()->setHost($host);
$this->getConfig()->setReleaseId(-1);
$task = Factory::get('releases/rollback', $this->getConfig());
$task->init();
$result = $task->run() && $result;
}
return $result;
}
return false;
}
/**
* Runs a Task
*
@ -439,7 +463,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
{
$task->init();
if ($title == null) {
if ($title === null) {
$title = 'Running <purple>' . $task->getName() . '</purple> ... ';
}
Console::output($title, 2, 0);
@ -449,11 +473,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$runTask = false;
}
if ($runTask == true) {
if ($runTask === true) {
try {
$result = $task->run();
if ($result == true) {
if ($result === true) {
Console::output('<green>OK</green>', 0);
$result = true;
@ -461,6 +485,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
Console::output('<red>FAIL</red>', 0);
$result = false;
}
} catch (RollbackException $e) {
Console::output('<red>FAIL, Rollback started</red> [Message: ' . $e->getMessage() . ']', 0);
$this->runRollbackTask();
$result = false;
} catch (ErrorWithMessageException $e) {
Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
$result = false;
@ -564,7 +593,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
case self::DEPLOY_STRATEGY_GUESS:
default:
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$deployStrategy = 'deployment/strategy/tar-gz';
} else {
$deployStrategy = 'deployment/strategy/rsync';

8
Mage/Command/BuiltIn/InitCommand.php

@ -30,11 +30,11 @@ class InitCommand extends AbstractCommand
$exitCode = 50;
$configDir = getcwd() . '/.mage';
Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
Console::output('Initiating managing process for application with <bold>Magallanes</bold>');
// Check if there is already a config dir
if (file_exists($configDir)) {
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 <bold>.mage</bold> directory.', 1, 2);
} else {
$results = array();
$results[] = mkdir($configDir);
@ -48,8 +48,8 @@ class InitCommand extends AbstractCommand
$results[] = file_put_contents($configDir . '/config/general.yml', $this->getGeneralConfig());
if (!in_array(false, $results)) {
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);
Console::output('<light_green>Success!!</light_green> The configuration for <bold>Magallanes</bold> has been generated at <blue>.mage</blue> directory.');
Console::output('<bold>Please!! Review and adjust the configuration.</bold>', 2, 2);
$exitCode = 0;
} else {

2
Mage/Command/BuiltIn/InstallCommand.php

@ -27,7 +27,7 @@ class InstallCommand extends AbstractCommand
public function run()
{
$exitCode = 88;
Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
Console::output('Installing <bold>Magallanes</bold>... ', 1, 0);
// Vars
$installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes');

8
Mage/Command/BuiltIn/ListCommand.php

@ -31,7 +31,7 @@ class ListCommand extends AbstractCommand
*/
public function run()
{
$exitCode = 600;
$exitCode = 221;
$subCommand = $this->getConfig()->getArgument(1);
try {
@ -56,7 +56,7 @@ class ListCommand extends AbstractCommand
*/
protected function listEnvironments()
{
$exitCode = 600;
$exitCode = 220;
$environments = array();
$content = scandir(getcwd() . '/.mage/config/environment/');
foreach ($content as $file) {
@ -67,7 +67,7 @@ class ListCommand extends AbstractCommand
sort($environments);
if (count($environments) > 0) {
Console::output('<dark_gray>These are your configured environments:</dark_gray>', 1, 1);
Console::output('<bold>These are your configured environments:</bold>', 1, 1);
foreach ($environments as $environment) {
Console::output('* <light_red>' . $environment . '</light_red>', 2, 1);
}
@ -75,7 +75,7 @@ class ListCommand extends AbstractCommand
$exitCode = 0;
} else {
Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2);
Console::output('<bold>You don\'t have any environment configured.</bold>', 1, 2);
}
return $exitCode;

21
Mage/Command/BuiltIn/ReleasesCommand.php

@ -28,7 +28,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
*/
public function run()
{
$exitCode = 400;
$exitCode = 100;
$subCommand = $this->getConfig()->getArgument(1);
// Run Tasks for Deployment
@ -36,16 +36,25 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
if (count($hosts) == 0) {
Console::output(
'<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>',
'<light_purple>Warning!</light_purple> <bold>No hosts defined, unable to get releases.</bold>',
1, 3
);
return 401;
return 101;
}
$result = true;
foreach ($hosts as $host) {
foreach ($hosts as $hostKey => $host) {
// Check if Host has specific configuration
$hostConfig = null;
if (is_array($host)) {
$hostConfig = $host;
$host = $hostKey;
}
// Set Host and Host Specific Config
$this->getConfig()->setHost($host);
$this->getConfig()->setHostConfig($hostConfig);
switch ($subCommand) {
case 'list':
@ -58,7 +67,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
Console::output('<red>Missing required releaseid.</red>', 1, 2);
return 410;
return 102;
}
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
@ -66,7 +75,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
Console::output('<red>This environment is locked!</red>', 1, 2);
echo file_get_contents($lockFile);
return 420;
return 103;
}
$releaseId = $this->getConfig()->getParameter('release', '');

19
Mage/Command/BuiltIn/RollbackCommand.php

@ -28,31 +28,40 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment
*/
public function run()
{
$exitCode = 450;
$exitCode = 105;
$releaseId = $this->getConfig()->getArgument(1);
if (!is_numeric($releaseId)) {
Console::output('<red>This release is mandatory.</red>', 1, 2);
return 451;
return 104;
}
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
if (file_exists($lockFile)) {
Console::output('<red>This environment is locked!</red>', 1, 2);
echo file_get_contents($lockFile);
return 20;
return 106;
}
// Run Tasks for Deployment
$hosts = $this->getConfig()->getHosts();
if (count($hosts) == 0) {
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> <bold>No hosts defined, unable to get releases.</bold>', 1, 3);
} else {
$result = true;
foreach ($hosts as $host) {
foreach ($hosts as $hostKey => $host) {
// Check if Host has specific configuration
$hostConfig = null;
if (is_array($host)) {
$hostConfig = $host;
$host = $hostKey;
}
// Set Host and Host Specific Config
$this->getConfig()->setHost($host);
$this->getConfig()->setHostConfig($hostConfig);
$this->getConfig()->setReleaseId($releaseId);
$task = Factory::get('releases/rollback', $this->getConfig());

3
Mage/Command/BuiltIn/UpdateCommand.php

@ -35,7 +35,7 @@ class UpdateCommand extends AbstractCommand
Console::output('Updating application via ' . $task->getName() . ' ... ', 1, 0);
$result = $task->run();
if ($result == true) {
if ($result === true) {
Console::output('<green>OK</green>' . PHP_EOL, 0);
$exitCode = 0;
@ -45,5 +45,4 @@ class UpdateCommand extends AbstractCommand
return $exitCode;
}
}

6
Mage/Command/BuiltIn/UpgradeCommand.php

@ -38,8 +38,8 @@ class UpgradeCommand extends AbstractCommand
*/
public function run()
{
$exitCode = 100;
Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0);
$exitCode = 99;
Console::output('Upgrading <bold>Magallanes</bold> ... ', 1, 0);
$user = '';
// Check if user is root
@ -49,7 +49,7 @@ class UpgradeCommand extends AbstractCommand
if ($user != 'root' && $user != $owner) {
Console::output('<red>FAIL</red>', 0, 1);
Console::output('You need to be the <dark_gray>' . $owner . '</dark_gray> user to perform the upgrade, or <dark_gray>root</dark_gray>.', 2);
Console::output('You need to be the <bold>' . $owner . '</bold> user to perform the upgrade, or <bold>root</bold>.', 2);
} else {
// Check version

3
Mage/Command/BuiltIn/VersionCommand.php

@ -26,9 +26,8 @@ class VersionCommand extends AbstractCommand
*/
public function run()
{
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION . '</dark_gray>', 0, 2);
Console::output('Running <blue>Magallanes</blue> version <bold>' . MAGALLANES_VERSION . '</bold>', 0, 2);
return 0;
}
}

1
Mage/Command/Factory.php

@ -12,7 +12,6 @@ namespace Mage\Command;
use Mage\Command\AbstractCommand;
use Mage\Config;
use Mage\Autoload;
use Exception;

32
Mage/Config.php

@ -13,7 +13,6 @@ namespace Mage;
use Mage\Config\ConfigNotFoundException;
use Mage\Config\RequiredConfigNotFoundException;
use Mage\Console;
use Mage\Yaml\Exception\RuntimeException;
use Mage\Yaml\Yaml;
use Exception;
@ -121,29 +120,6 @@ class Config
return $this->parseConfigFile($filePath);
}
/**
* Obviously this method is a HACK. It was refactored from ::loadEnvironment()
* TODO Please put it to SCM functionality.
*
* @param array $settings
*
* @return array
*/
protected function updateSCMTempDir(array $settings)
{
// Create temporal directory for clone
if (isset($settings['deployment']['source']) && is_array($settings['deployment']['source'])) {
if (trim($settings['deployment']['source']['temporal']) == '') {
$settings['deployment']['source']['temporal'] = sys_get_temp_dir();
}
$settings['deployment']['source']['temporal']
= rtrim($settings['deployment']['source']['temporal'], '/') . '/' . md5(microtime()) . '/';
}
return $settings;
}
/**
* Loads the Environment configuration
* @param $filePath string
@ -156,9 +132,6 @@ class Config
$settings = $this->parseConfigFile($filePath);
//this is a HACK in the old code - no time to remove it now, so I factored it out in own method
$settings = $this->updateSCMTempDir($settings);
return $settings;
}
@ -490,6 +463,11 @@ class Config
}
}
public function setSourceTemporal($directory)
{
$this->environmentConfig['deployment']['source']['temporal'] = $directory;
}
/**
* Returns Releasing Options
*

17
Mage/Console.php

@ -26,7 +26,6 @@ use SplFileInfo;
class Console
{
/**
* TODO refactor into own static class
* @var array
*/
public static $paramsNotRequiringEnvironment = array('install' => 'install', 'upgrade' => 'upgrade', 'version' => 'version');
@ -116,11 +115,10 @@ class Console
} else {
self::output('Starting <blue>Magallanes</blue>', 0, 1);
self::log("Logging enabled");
self::output('<dark_gray>Logging enabled:</dark_gray> <purple>' . self::getLogFile() . '</purple>', 1, 2);
self::output('<bold>Logging enabled:</bold> <purple>' . self::getLogFile() . '</purple>', 1, 2);
}
}
// Run Command - Check if there is a Configuration Error
if ($configError !== false) {
self::output('<red>' . $configError . '</red>', 1, 2);
@ -131,12 +129,21 @@ class Console
$command = Factory::get($commandName, $config);
if ($command instanceOf RequiresEnvironment) {
if ($config->getEnvironment() == false) {
if ($config->getEnvironment() === false) {
throw new Exception('You must specify an environment for this command.');
}
}
// Run the Command
$exitCode = $command->run();
// Check for errors
if (is_int($exitCode) && $exitCode !== 0) {
throw new Exception('Command execution failed with following exit code: ' . $exitCode, $exitCode);
} elseif (is_bool($exitCode) && !$exitCode) {
$exitCode = 1;
throw new Exception('Command execution failed.', $exitCode);
}
} catch (Exception $exception) {
self::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
}
@ -213,7 +220,7 @@ class Console
public static function log($message)
{
if (self::$logEnabled) {
if (self::$log == null) {
if (self::$log === null) {
self::$logFile = realpath(getcwd() . '/.mage/logs') . '/log-' . date('Ymd-His') . '.log';
self::$log = fopen(self::$logFile, 'w');
}

2
Mage/Console/Colors.php

@ -25,7 +25,7 @@ class Colors
*/
private static $foregroundColors = array(
'black' => '0;30',
'dark_gray' => '1;30',
'bold' => '1',
'blue' => '0;34',
'light_blue' => '1;34',
'green' => '0;32',

2
Mage/Mailer.php

@ -84,6 +84,6 @@ class Mailer
. $attachment . self::EOL
. '--Mage-mixed-' . $boundary . '--' . self::EOL;
@mail($this->address, $subject, $message, $headers);
mail($this->address, $subject, $message, $headers);
}
}

6
Mage/Task/AbstractTask.php

@ -181,7 +181,7 @@ abstract class AbstractTask
*/
protected final function runCommandRemote($command, &$output = null, $cdToDirectoryFirst = true)
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
if ($this instanceOf IsReleaseAware) {
$releasesDirectory = '';
@ -223,7 +223,7 @@ abstract class AbstractTask
*/
protected final function runCommand($command, &$output = null)
{
if ($this->getStage() == self::STAGE_DEPLOY) {
if ($this->getStage() == self::STAGE_DEPLOY || $this->getStage() == self::STAGE_POST_RELEASE) {
return $this->runCommandRemote($command, $output);
} else {
return $this->runCommandLocal($command, $output);
@ -238,7 +238,7 @@ abstract class AbstractTask
*/
protected function getReleasesAwareCommand($command)
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();

4
Mage/Task/BuiltIn/Deployment/ReleaseTask.php

@ -37,7 +37,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
public function run()
{
$resultFetch = false;
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
@ -107,7 +107,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
protected function cleanUpReleases()
{
// Count Releases
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');

2
Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php

@ -30,7 +30,7 @@ abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleas
$overrideRelease = $this->getParameter('overrideRelease', false);
$symlink = $this->getConfig()->release('symlink', 'current');
if ($overrideRelease == true) {
if ($overrideRelease === true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {

1
Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php

@ -38,5 +38,4 @@ class DisabledTask extends AbstractTask implements IsReleaseAware
{
throw new SkipException;
}
}

15
Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php

@ -10,7 +10,6 @@
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware;
/**
@ -35,20 +34,6 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
*/
public function run()
{
$this->checkOverrideRelease();
$excludes = $this->getExcludes();
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
. '/' . $releasesDirectory
. '/' . $this->getConfig()->getReleaseId();
$this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
}
$branch = $this->getParameter('branch', 'master');
$remote = $this->getParameter('remote', 'origin');

39
Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php

@ -42,7 +42,7 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware
{
$overrideRelease = $this->getParameter('overrideRelease', false);
if ($overrideRelease == true) {
if ($overrideRelease === true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {
@ -63,7 +63,7 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware
$userExcludes = $this->getConfig()->deployment('excludes', array());
$deployToDirectory = $this->getConfig()->deployment('to');
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
@ -97,39 +97,8 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware
$command = 'cd ' . $remoteCacheFolder . ' && /usr/bin/env git archive ' . $branch . ' | tar -x -C ' . $deployToDirectory . ' ' . $excludeCmd;
$result = $this->runCommandRemote($command) && $result;
// Count Releases
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
if (substr($symlink, 0, 1) == '/') {
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
}
$maxReleases = $this->getConfig()->release('max', false);
if (($maxReleases !== false) && ($maxReleases > 0)) {
$releasesList = '';
$countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList);
$releasesList = trim($releasesList);
if ($countReleasesFetch && $releasesList != '') {
$releasesList = explode(PHP_EOL, $releasesList);
if (count($releasesList) > $maxReleases) {
$releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId()));
sort($releasesToDelete);
$releasesToDeleteCount = count($releasesToDelete) - $maxReleases;
$releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1);
foreach ($releasesToDelete as $releaseIdToDelete) {
$directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete;
if ($directoryToDelete != '/') {
$command = 'rm -rf ' . $directoryToDelete;
$result = $result && $this->runCommandRemote($command);
}
}
}
}
}
if ($result) {
$this->cleanUpReleases();
}
return $result;

22
Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php

@ -27,8 +27,8 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
*/
public function getName()
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->getParameter('overrideRelease', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
if ($this->getConfig()->getParameter('overrideRelease', false) === true) {
return 'Deploy via Rsync (with Releases override) [built-in]';
} else {
$rsync_copy = $this->getConfig()->deployment("rsync");
@ -52,10 +52,11 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$this->checkOverrideRelease();
$excludes = $this->getExcludes();
$excludesListFilePath = $this->getConfig()->deployment('excludes_file', '');
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
@ -95,6 +96,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
. $strategyFlags . ' '
. '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" '
. $this->excludes($excludes) . ' '
. $this->excludesListFile($excludesListFilePath) . ' '
. $this->getConfig()->deployment('from') . ' '
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
$result = $this->runCommandLocal($command);
@ -117,4 +119,18 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$excludesRsync = trim($excludesRsync);
return $excludesRsync;
}
/**
* Generates the Exclude from file for rsync
* @param string $excludesFile
* @return string
*/
protected function excludesListFile($excludesFile)
{
$excludesListFileRsync = '';
if(!empty($excludesFile) && file_exists($excludesFile) && is_file($excludesFile) && is_readable($excludesFile)) {
$excludesListFileRsync = ' --exclude-from=' . $excludesFile;
}
return $excludesListFileRsync;
}
}

26
Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php

@ -10,7 +10,6 @@
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Console;
use Mage\Task\BuiltIn\Deployment\Strategy\BaseStrategyTaskAbstract;
use Mage\Task\Releases\IsReleaseAware;
@ -27,8 +26,8 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
*/
public function getName()
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->getParameter('overrideRelease', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
if ($this->getConfig()->getParameter('overrideRelease', false) === true) {
return 'Deploy via TarGz (with Releases override) [built-in]';
} else {
return 'Deploy via TarGz (with Releases) [built-in]';
@ -47,10 +46,11 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$this->checkOverrideRelease();
$excludes = $this->getExcludes();
$excludesListFilePath = $this->getConfig()->deployment('excludes_file', '');;
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
. '/' . $releasesDirectory
@ -67,6 +67,8 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$excludeCmd .= ' --exclude=' . $excludeFile;
}
$excludeFromFileCmd = $this->excludesListFile($excludesListFilePath);
// Strategy Flags
$strategyFlags = $this->getConfig()->deployment('strategy_flags', $this->getConfig()->general('strategy_flags', array()));
if (isset($strategyFlags['targz']) && isset($strategyFlags['targz']['create'])) {
@ -75,7 +77,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$strategyFlags = '';
}
$command = 'tar cfzh' . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .';
$command = 'tar cfzh' . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . $excludeFromFileCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .';
$result = $this->runCommandLocal($command);
// Strategy Flags
@ -113,4 +115,18 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
return $result;
}
/**
* Generates the Exclude from file for rsync
* @param string $excludesFile
* @return string
*/
protected function excludesListFile($excludesFile)
{
$excludesListFileRsync = '';
if(!empty($excludesFile) && file_exists($excludesFile) && is_file($excludesFile) && is_readable($excludesFile)) {
$excludesListFileRsync = ' --exclude-from=' . $excludesFile;
}
return $excludesListFileRsync;
}
}

45
Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php

@ -8,6 +8,16 @@ use Mage\Task\SkipException;
class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
{
const LINKED_FOLDERS = 'linked_folders';
const LINKED_STRATEGY = 'linking_strategy';
const ABSOLUTE_LINKING = 'absolute';
const RELATIVE_LINKING = 'relative';
public $linkingStrategies = array(
self::ABSOLUTE_LINKING,
self::RELATIVE_LINKING
);
/**
* Returns the Title of the Task
* @return string
@ -25,25 +35,38 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
*/
public function run()
{
$linkedFiles = $this->getParameter('linked_files', []);
$linkedFolders = $this->getParameter('linked_folders', []);
$linkedFiles = $this->getParameter('linked_files', []);
$linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []);
$linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING);
$linkedEntities = array_merge($linkedFiles,$linkedFolders);
if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) {
throw new SkipException('No files and folders configured for sym-linking.');
}
$sharedFolderName = $this->getParameter('shared', 'shared');
$sharedFolderName = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName;
$sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName;
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
$releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
$currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
foreach ($linkedFolders as $folder) {
$command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder";
$this->runCommandRemote($command);
}
$currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId();
$relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/';
foreach ($linkedFiles as $folder) {
$command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder";
foreach ($linkedEntities as $ePath) {
if(is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies ) ) {
$entityPath = key($ePath);
} else {
$strategy = $linkingStrategy;
$entityPath = $ePath;
}
$sharedEntityLinkedPath = "$sharedFolderPath/$entityPath";
if($strategy==self::RELATIVE_LINKING) {
$parentFolderPath = dirname($entityPath);
$relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/';
$sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath;
}
$command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath";
$this->runCommandRemote($command);
}

11
Mage/Task/BuiltIn/Releases/ListTask.php

@ -34,11 +34,11 @@ class ListTask extends AbstractTask implements IsReleaseAware
*/
public function run()
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
Console::output('Releases available on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
Console::output('Releases available on <bold>' . $this->getConfig()->getHost() . '</bold>');
// Get Releases
$output = '';
@ -51,7 +51,7 @@ class ListTask extends AbstractTask implements IsReleaseAware
$currentRelease = trim(array_pop($currentRelease));
if (count($releases) == 0) {
Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
Console::output('<bold>No releases available</bold> ... ', 2);
} else {
rsort($releases);
$releases = array_slice($releases, 0, 10);
@ -80,8 +80,8 @@ class ListTask extends AbstractTask implements IsReleaseAware
Console::output(
'Release: <purple>' . $release . '</purple> '
. '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
. '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $dateDiff . $isCurrent, 2);
. '- Date: <bold>' . $releaseDate . '</bold> '
. '- Index: <bold>' . $releaseIndex . '</bold>' . $dateDiff . $isCurrent, 2);
}
}
@ -146,5 +146,4 @@ class ListTask extends AbstractTask implements IsReleaseAware
return $textDiff;
}
}

15
Mage/Task/BuiltIn/Releases/RollbackTask.php

@ -47,7 +47,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
*/
public function run()
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->release('enabled', false) === true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
@ -56,7 +56,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
if (count($releases) == 0) {
Console::output('Release are not available for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
Console::output('Release are not available for <bold>' . $this->getConfig()->getHost() . '</bold> ... <red>FAIL</red>');
} else {
rsort($releases);
@ -81,10 +81,10 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
}
if (!$releaseIsAvailable) {
Console::output('Release <dark_gray>' . $this->getReleaseId() . '</dark_gray> is invalid or unavailable for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
Console::output('Release <bold>' . $this->getReleaseId() . '</bold> is invalid or unavailable for <bold>' . $this->getConfig()->getHost() . '</bold> ... <red>FAIL</red>');
} else {
Console::output('Rollback release on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
Console::output('Rollback release on <bold>' . $this->getConfig()->getHost() . '</bold>');
$rollbackTo = $releasesDirectory . '/' . $releaseId;
// Get Current Release
@ -111,7 +111,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$tasks++;
$result = $task->run();
if ($result == true) {
if ($result === true) {
Console::output('<green>OK</green>', 0);
$completedTasks++;
} else {
@ -161,7 +161,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$tasks++;
$result = $task->run();
if ($result == true) {
if ($result === true) {
Console::output('<green>OK</green>', 0);
$completedTasks++;
} else {
@ -178,7 +178,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$tasksColor = 'red';
}
Console::output('Release rollback on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
Console::output('Release rollback on <bold>' . $this->getConfig()->getHost() . '</bold> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
}
}
@ -188,5 +188,4 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
return false;
}
}
}

9
Mage/Task/BuiltIn/Scm/CloneTask.php

@ -53,6 +53,15 @@ class CloneTask extends AbstractTask
$this->name = 'SCM Clone (GIT) [built-in]';
break;
}
// Create temporal directory for clone
if (is_array($this->source)) {
if (trim($this->source['temporal']) == '') {
$this->source['temporal'] = sys_get_temp_dir();
}
$this->source['temporal'] = rtrim($this->source['temporal'], '/') . '/' . md5(microtime()) . '/';
$this->getConfig()->setSourceTemporal($this->source['temporal']);
}
}
/**

87
Mage/Task/BuiltIn/Scm/ForceUpdateTask.php

@ -0,0 +1,87 @@
<?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;
/**
* Task for Force Updating a Working Copy
*
* 'git fetch' downloads the latest from remote without trying to merge or rebase anything.
* 'git reset' resets the master branch to what you just fetched.
* The '--hard' option changes all the files in your working tree to match the files in origin/master,
* so if you have any local changes, they will be lost.
*
* @author Samuel Chiriluta <samuel4x4@gmail.com>
*/
class ForceUpdateTask extends AbstractTask
{
/**
* Name of the Task
* @var string
*/
private $name = 'SCM Force 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 Force Update (GIT) [built-in]';
break;
}
}
/**
* Force Updates the Working Copy
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$branch = $this->getParameter('branch', 'master');
$remote = $this->getParameter('remote', 'origin');
$command = 'git fetch ' . $remote . ' ' . $branch;
$result = $this->runCommandRemote($command);
$command = 'git reset --hard ' . $remote . '/' . $branch;
$result = $result && $this->runCommandRemote($command);
$command = 'git pull ' . $remote . ' ' . $branch;
$result = $result && $this->runCommandRemote($command);
break;
default:
throw new SkipException;
break;
}
$result = $this->runCommandLocal($command);
$this->getConfig()->reload();
return $result;
}
}

40
Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php

@ -0,0 +1,40 @@
<?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\Symfony2;
use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask;
/**
* Task for Doctrine migrations
*/
class DoctrineMigrate extends SymfonyAbstractTask
{
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName()
{
return 'Symfony v2 - Migrate doctrine entities [built-in]';
}
/**
* Migrates Doctrine entities
*
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
$env = $this->getParameter('env', 'dev');
$command = $this->getAppPath() . ' doctrine:migrations:migrate -n --env=' . $env;
return $this->runCommand($command);
}
}

1
Mage/Task/Factory.php

@ -11,7 +11,6 @@
namespace Mage\Task;
use Mage\Config;
use Mage\Autoload;
use Exception;

23
Mage/Task/RollbackException.php

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Alex V Kotelnikov <gudron@gudron.me>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task;
use Exception;
/**
* Exception that indicates that the Task was Failed and rollback needed
*
* @author Alex V Kotelnikov <gudron@gudron.me>
*/
class RollbackException extends Exception
{
}

1
Mage/Yaml/Parser.php

@ -655,5 +655,4 @@ class Parser
{
return (0 === strpos($this->currentLine, '- '));
}
}

4
bin/mage

@ -13,7 +13,7 @@ date_default_timezone_set('UTC');
$baseDir = dirname(dirname(__FILE__));
define('MAGALLANES_VERSION', '1.0.2');
define('MAGALLANES_VERSION', '1.0.3');
define('MAGALLANES_DIRECTORY', $baseDir);
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
@ -32,4 +32,4 @@ array_shift($argv);
$console = new Mage\Console;
$exitCode = $console->run($argv);
exit($exitCode);
exit((integer) $exitCode);

16
box.json

@ -0,0 +1,16 @@
{
"files": ["LICENSE"],
"finder": [
{
"name": "*.php",
"exclude": [
"docs"
],
"in": "Mage"
}
],
"git-version": "git_tag",
"main": "bin/mage",
"output": "mage.phar",
"stub": true
}

14
docs/example-config/.mage/config/environment/ioncube.yml → docs/example-config/.mage/config/environment/ioncube.yml.txt

@ -10,11 +10,11 @@ deployment:
ioncube: test
releases:
enabled: true
symlink: current
directory: releases
enabled: true
symlink: current
directory: releases
hosts:
- localhost
- localhost
tasks:
pre-deploy:
- ioncube/encrypt
@ -27,9 +27,8 @@ ioncube:
encoder: ioncube_encoder54
checkencoding: true
checkignorepaths:
-/public/js/*
-/public/css/*
- /public/js/*
- /public/css/*
projfile: project.prj
project:
replace-target:
@ -57,7 +56,6 @@ ioncube:
- 'Comment 2'
- "(c) ACTweb 2013"
- "Draft Version"
loader-event:
- corrupt-file=Corupted files
- expired-file=System needs updated

23
docs/example-config/.mage/config/environment/production.yml

@ -2,11 +2,6 @@
deployment:
user: root
from: ./
# source:
# type: git
# repository: git://github.com/andres-montanez/Magallanes.git
# from: master
# temporal: /tmp/myAppClone
to: /var/www/vhosts/example.com/www
excludes:
- application/data/cache/twig/*
@ -16,25 +11,13 @@ releases:
symlink: current
directory: releases
hosts:
s01.example.com:22:
deployment:
user: nobody
s02.example.com:
deployment:
user: toor
to: /home/web/public
releases:
max: 10
tasks:
on-deploy:
- privileges
- s03.example.com
- s01.example.com
- s02.example.com
tasks:
pre-deploy:
- scm/update
on-deploy:
# - symfony2/cache-warmup: {env: prod}
- symfony2/cache-warmup: { env: prod }
- privileges
- sampleTask
- sampleTaskRollbackAware
#post-deploy:

38
docs/example-config/.mage/config/environment/production.yml.advanced.txt

@ -0,0 +1,38 @@
#production
deployment:
user: root
from: ./
# source:
# type: git
# repository: git://github.com/andres-montanez/Magallanes.git
# from: master
# temporal: /tmp/myAppClone
to: /var/www/vhosts/example.com/www
excludes:
- application/data/cache/twig/*
releases:
enabled: true
max: 5
symlink: current
directory: releases
hosts:
- s01.example.com
- s02.example.com
# s02.example.com:
# deployment:
# user: toor
# to: /home/web/public
# releases:
# max: 10
# tasks:
# on-deploy:
# - privileges
tasks:
pre-deploy:
- scm/update
on-deploy:
- symfony2/cache-warmup: { env: prod }
- privileges
- sampleTask
- sampleTaskRollbackAware
#post-deploy:

1
docs/example-config/.mage/tasks/SampleTaskRollbackAware.php

@ -20,3 +20,4 @@ class SampleTaskRollbackAware extends AbstractTask implements RollbackAware
return true;
}
}

8
docs/example-config/.mage/tasks/TaskWithParameters.php

@ -18,8 +18,10 @@ class TaskWithParameters extends AbstractTask
public function run()
{
//throw new Mage_Task_SkipException;
//return false;
return true;
if ($this->getParameter('booleanOption', false)) {
return true;
} else {
return false;
}
}
}
Loading…
Cancel
Save