mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-23 16:12:11 +02:00
New version. Added getters to config and task.
New concept of "stage" where the task runs.
This commit is contained in:
parent
de772028bb
commit
3f0efc1a42
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
class Mage_Config
|
||||
{
|
||||
private $_environmentName = null;
|
||||
private $_environment = null;
|
||||
private $_scm = null;
|
||||
private $_general = null;
|
||||
|
@ -10,7 +11,8 @@ class Mage_Config
|
|||
public function loadEnvironment($environment)
|
||||
{
|
||||
if (($environment != '') && file_exists('.mage/config/environment/' . $environment . '.yml')) {
|
||||
$this->_environment = spyc_load_file('.mage/config/environment/' . $environment . '.yml');
|
||||
$this->_environment = spyc_load_file('.mage/config/environment/' . $environment . '.yml');
|
||||
$this->_environmentName = $environment;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +35,11 @@ class Mage_Config
|
|||
return $this->_environment;
|
||||
}
|
||||
|
||||
public function getEnvironmentName()
|
||||
{
|
||||
return $this->_environmentName;
|
||||
}
|
||||
|
||||
public function getSCM()
|
||||
{
|
||||
return $this->_scm;
|
||||
|
|
|
@ -16,10 +16,13 @@ class Mage_Task_BuiltIn_Deployment_Releases
|
|||
|
||||
$currentCopy = $releasesDirectory . '/' . $this->_config->getReleaseId();
|
||||
|
||||
$userGroup = '';
|
||||
$resultFetch = $this->_runRemoteCommand('ls -ld ' . $symlink . ' | awk \'{print \$3\":\"\$4}\'', $userGroup);
|
||||
// Fetch the user and group from base directory
|
||||
$userGroup = '33:33';
|
||||
$resultFetch = $this->_runRemoteCommand('ls -ld . | awk \'{print \$3\":\"\$4}\'', $userGroup);
|
||||
|
||||
// Remove symlink if exists; create new symlink and change owners
|
||||
$command = 'rm -f ' . $symlink
|
||||
. ' && '
|
||||
. ' ; '
|
||||
. 'ln -sf ' . $currentCopy . ' ' . $symlink
|
||||
. ' && '
|
||||
. 'chown -h ' . $userGroup . ' ' . $symlink
|
||||
|
|
|
@ -73,7 +73,7 @@ class Mage_Task_BuiltIn_Releases_Rollback
|
|||
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskName) {
|
||||
$task = Mage_Task_Factory::get($taskName, $this->_config, true);
|
||||
$task = Mage_Task_Factory::get($taskName, $this->_config, true, 'deploy');
|
||||
$task->init();
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class Mage_Task_Deploy
|
|||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
Mage_Console::output('Deploying to <dark_gray>' . $config->getHostName() . '</dark_gray>');
|
||||
Mage_Console::output('Deploying to <dark_gray>' . $config->getHost() . '</dark_gray>');
|
||||
|
||||
$tasksToRun = $config->getTasks();
|
||||
array_unshift($tasksToRun, 'deployment/rsync');
|
||||
|
@ -40,12 +40,12 @@ class Mage_Task_Deploy
|
|||
|
||||
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>' . $config->getHostName() . '</dark_gray> skipped!', 1, 3);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $config->getHost() . '</dark_gray> skipped!', 1, 3);
|
||||
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskName) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskName, $config);
|
||||
$task = Mage_Task_Factory::get($taskName, $config, false, 'deploy');
|
||||
$task->init();
|
||||
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
|
@ -65,7 +65,7 @@ class Mage_Task_Deploy
|
|||
$tasksColor = 'red';
|
||||
}
|
||||
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $config->getHostName() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $config->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class Mage_Task_Deploy
|
|||
|
||||
foreach ($tasksToRun as $taskName) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskName, $config);
|
||||
$task = Mage_Task_Factory::get($taskName, $config, false, $stage);
|
||||
$task->init();
|
||||
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, 0);
|
||||
|
|
|
@ -8,7 +8,7 @@ class Mage_Task_Factory
|
|||
* @param boolean $inRollback
|
||||
* @return Mage_Task_TaskAbstract
|
||||
*/
|
||||
public static function get($taskName, Mage_Config $taskConfig, $inRollback = false)
|
||||
public static function get($taskName, Mage_Config $taskConfig, $inRollback = false, $stage = null)
|
||||
{
|
||||
$instance = null;
|
||||
$taskName = ucwords(str_replace('-', ' ', $taskName));
|
||||
|
@ -17,12 +17,12 @@ class Mage_Task_Factory
|
|||
if (strpos($taskName, '/') === false) {
|
||||
Mage_Autoload::loadUserTask($taskName);
|
||||
$className = 'Task_' . ucfirst($taskName);
|
||||
$instance = new $className($taskConfig, $inRollback);
|
||||
$instance = new $className($taskConfig, $inRollback, $stage);
|
||||
|
||||
} else {
|
||||
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
|
||||
$className = 'Mage_Task_BuiltIn_' . $taskName;
|
||||
$instance = new $className($taskConfig, $inRollback);
|
||||
$instance = new $className($taskConfig, $inRollback, $stage);
|
||||
}
|
||||
|
||||
assert($instance instanceOf Mage_Task_TaskAbstract);
|
||||
|
|
|
@ -17,7 +17,7 @@ class Mage_Task_Init
|
|||
$results[] = mkdir($configDir . '/tasks');
|
||||
$results[] = mkdir($configDir . '/config');
|
||||
$results[] = mkdir($configDir . '/config/environment');
|
||||
$results[] = file_put_contents($configDir . '/config/global.yml', '#global settings' . PHP_EOL . PHP_EOL);
|
||||
$results[] = file_put_contents($configDir . '/config/general.yml', '#global settings' . PHP_EOL . PHP_EOL);
|
||||
$results[] = file_put_contents($configDir . '/config/scm.yml', '#scm settings' . PHP_EOL . PHP_EOL);
|
||||
|
||||
if (!in_array(false, $results)) {
|
||||
|
|
|
@ -3,15 +3,17 @@ abstract class Mage_Task_TaskAbstract
|
|||
{
|
||||
protected $_config = null;
|
||||
protected $_inRollback = false;
|
||||
protected $_stage = null;
|
||||
|
||||
public abstract function getName();
|
||||
|
||||
public abstract function run();
|
||||
|
||||
public final function __construct(Mage_Config $config, $inRollback = false)
|
||||
public final function __construct(Mage_Config $config, $inRollback = false, $stage = null)
|
||||
{
|
||||
$this->_config = $config;
|
||||
$this->_inRollback = $inRollback;
|
||||
$this->_stage = $stage;
|
||||
}
|
||||
|
||||
public function inRollback()
|
||||
|
@ -19,6 +21,16 @@ abstract class Mage_Task_TaskAbstract
|
|||
return $this->_inRollback;
|
||||
}
|
||||
|
||||
public function getStage()
|
||||
{
|
||||
return $this->_stage;
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
|
2
bin/mage
2
bin/mage
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
#VERSION:0.9.7
|
||||
#VERSION:0.9.8
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIR=$(dirname $SCRIPT)
|
||||
|
|
|
@ -24,7 +24,7 @@ date_default_timezone_set('UTC');
|
|||
|
||||
$baseDir = dirname(dirname(__FILE__));
|
||||
|
||||
define('MAGALLANES_VERSION', '0.9.7');
|
||||
define('MAGALLANES_VERSION', '0.9.8');
|
||||
|
||||
require_once $baseDir . '/Mage/spyc.php';
|
||||
require_once $baseDir . '/Mage/Autoload.php';
|
||||
|
|
Loading…
Reference in a new issue