Verify if environment is defined. Verify that rollback has release point.

This commit is contained in:
Andrés Montañez 2012-09-19 18:53:14 -03:00
parent 7d8bf35df4
commit d63ca9cc04
4 changed files with 171 additions and 141 deletions

View file

@ -7,13 +7,13 @@ class Mage_Config
private $_general = null; private $_general = null;
private $_host = null; private $_host = null;
private $_releaseId = null; private $_releaseId = null;
public function loadEnvironment($environment) public function loadEnvironment($environment)
{ {
if (($environment != '') && file_exists('.mage/config/environment/' . $environment . '.yml')) { 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; $this->_environmentName = $environment;
// Create temporal directory for clone // Create temporal directory for clone
if (isset($this->_environment['deployment']['source']) && is_array($this->_environment['deployment']['source'])) { if (isset($this->_environment['deployment']['source']) && is_array($this->_environment['deployment']['source'])) {
if (trim($this->_environment['deployment']['source']['temporal']) == '') { if (trim($this->_environment['deployment']['source']['temporal']) == '') {
@ -22,34 +22,40 @@ class Mage_Config
$newTemporal = rtrim($this->_environment['deployment']['source']['temporal'], '/') $newTemporal = rtrim($this->_environment['deployment']['source']['temporal'], '/')
. '/' . md5(microtime()) . '/'; . '/' . md5(microtime()) . '/';
$this->_environment['deployment']['source']['temporal'] = $newTemporal; $this->_environment['deployment']['source']['temporal'] = $newTemporal;
} }
return true;
} else if (($environment != '') && !file_exists('.mage/config/environment/' . $environment . '.yml')) {
return false;
} }
return true;
} }
public function loadSCM() public function loadSCM()
{ {
if (file_exists('.mage/config/scm.yml')) { if (file_exists('.mage/config/scm.yml')) {
$this->_scm = spyc_load_file('.mage/config/scm.yml'); $this->_scm = spyc_load_file('.mage/config/scm.yml');
} }
} }
public function loadGeneral() public function loadGeneral()
{ {
if (file_exists('.mage/config/general.yml')) { if (file_exists('.mage/config/general.yml')) {
$this->_general = spyc_load_file('.mage/config/general.yml'); $this->_general = spyc_load_file('.mage/config/general.yml');
} }
} }
public function getEnvironment() public function getEnvironment()
{ {
return $this->_environment; return $this->_environment;
} }
public function getEnvironmentName() public function getEnvironmentName()
{ {
return $this->_environmentName; return $this->_environmentName;
} }
public function getSCM() public function getSCM()
{ {
return $this->_scm; return $this->_scm;
@ -59,64 +65,64 @@ class Mage_Config
{ {
return $this->_global; return $this->_global;
} }
public function getHosts() public function getHosts()
{ {
$config = $this->getEnvironment(); $config = $this->getEnvironment();
$hosts = array(); $hosts = array();
if (isset($config['hosts'])) { if (isset($config['hosts'])) {
if (is_array($config['hosts'])) { if (is_array($config['hosts'])) {
$hosts = (array) $config['hosts']; $hosts = (array) $config['hosts'];
} else if (is_string($config['hosts'])) { } else if (is_string($config['hosts'])) {
$fileContent = fopen($config['hosts'], 'r'); $fileContent = fopen($config['hosts'], 'r');
while (($host = fgets($fileContent)) == true) { while (($host = fgets($fileContent)) == true) {
$host = trim($host); $host = trim($host);
if ($host != '') { if ($host != '') {
$hosts[] = $host; $hosts[] = $host;
} }
} }
} }
} }
return $hosts; return $hosts;
} }
public function setHost($host) public function setHost($host)
{ {
$this->_host = $host; $this->_host = $host;
return $this; return $this;
} }
public function getHostName() public function getHostName()
{ {
$info = explode(':', $this->_host); $info = explode(':', $this->_host);
return $info[0]; return $info[0];
} }
public function getHostPort() public function getHostPort()
{ {
$info = explode(':', $this->_host); $info = explode(':', $this->_host);
$info[] = $this->deployment('port', '22'); $info[] = $this->deployment('port', '22');
return $info[1]; return $info[1];
} }
public function getHost() public function getHost()
{ {
return $this->_host; return $this->_host;
} }
public function setReleaseId($id) public function setReleaseId($id)
{ {
$this->_releaseId = $id; $this->_releaseId = $id;
return $this; return $this;
} }
public function getReleaseId() public function getReleaseId()
{ {
return $this->_releaseId; return $this->_releaseId;
} }
public function getTasks($stage = 'on-deploy') public function getTasks($stage = 'on-deploy')
{ {
switch ($stage) { switch ($stage) {
@ -124,24 +130,24 @@ class Mage_Config
$type = 'tasks'; $type = 'tasks';
$stage = 'pre-deploy'; $stage = 'pre-deploy';
break; break;
case 'post-deploy': case 'post-deploy':
$type = 'tasks'; $type = 'tasks';
$stage = 'post-deploy'; $stage = 'post-deploy';
break; break;
case 'post-release': case 'post-release':
$type = 'releases'; $type = 'releases';
$stage = 'post-release'; $stage = 'post-release';
break; break;
case 'on-deploy': case 'on-deploy':
default: default:
$type = 'tasks'; $type = 'tasks';
$stage = 'on-deploy'; $stage = 'on-deploy';
break; break;
} }
$tasks = array(); $tasks = array();
$config = $this->getEnvironment(); $config = $this->getEnvironment();
@ -151,17 +157,17 @@ class Mage_Config
return $tasks; return $tasks;
} }
public function getConfig($host = false) public function getConfig($host = false)
{ {
$taskConfig = array(); $taskConfig = array();
$taskConfig['deploy'] = $this->getEnvironment(); $taskConfig['deploy'] = $this->getEnvironment();
$taskConfig['deploy']['host'] = $host; $taskConfig['deploy']['host'] = $host;
$taskConfig['scm'] = $this->getSCM(); $taskConfig['scm'] = $this->getSCM();
unset($taskConfig['deploy']['tasks']); unset($taskConfig['deploy']['tasks']);
unset($taskConfig['deploy']['hosts']); unset($taskConfig['deploy']['hosts']);
return $taskConfig; return $taskConfig;
} }
@ -170,7 +176,7 @@ class Mage_Config
$this->_environment['deployment']['from'] = $from; $this->_environment['deployment']['from'] = $from;
return $this; return $this;
} }
public function deployment($option, $default = false) public function deployment($option, $default = false)
{ {
$options = $this->getEnvironment(); $options = $this->getEnvironment();
@ -178,13 +184,13 @@ class Mage_Config
if (is_array($default) && ($options['deployment'][$option] == '')) { if (is_array($default) && ($options['deployment'][$option] == '')) {
return $default; return $default;
} else { } else {
return $options['deployment'][$option]; return $options['deployment'][$option];
} }
} else { } else {
return $default; return $default;
} }
} }
public function release($option, $default = false) public function release($option, $default = false)
{ {
$options = $this->getEnvironment(); $options = $this->getEnvironment();
@ -198,7 +204,7 @@ class Mage_Config
return $default; return $default;
} }
} }
public function scm($option, $default = false) public function scm($option, $default = false)
{ {
$options = $this->_scm; $options = $this->_scm;
@ -213,7 +219,7 @@ class Mage_Config
return $default; return $default;
} }
} }
public function general($option, $default = false) public function general($option, $default = false)
{ {
$options = $this->_general; $options = $this->_general;
@ -227,7 +233,7 @@ class Mage_Config
return $default; return $default;
} }
} }
public function mail($option, $default = false) public function mail($option, $default = false)
{ {
$options = $this->_general; $options = $this->_general;

View file

@ -9,13 +9,13 @@ class Mage_Console
private static $_logEnabled = true; private static $_logEnabled = true;
private static $_screenBuffer = ''; private static $_screenBuffer = '';
private static $_commandsOutput = ''; private static $_commandsOutput = '';
public function setArgs($args) public function setArgs($args)
{ {
$this->_args = $args; $this->_args = $args;
array_shift($this->_args); array_shift($this->_args);
} }
public function parse() public function parse()
{ {
if (count($this->_args) == 0) { if (count($this->_args) == 0) {
@ -27,7 +27,7 @@ class Mage_Console
} else if ($this->_args[0] == 'releases') { } else if ($this->_args[0] == 'releases') {
$this->_action = 'releases'; $this->_action = 'releases';
} else if ($this->_args[0] == 'update') { } else if ($this->_args[0] == 'update') {
$this->_action = 'update'; $this->_action = 'update';
@ -36,20 +36,20 @@ class Mage_Console
} else if ($this->_args[0] == 'add') { } else if ($this->_args[0] == 'add') {
$this->_action = 'add'; $this->_action = 'add';
} else if ($this->_args[0] == 'install') { } else if ($this->_args[0] == 'install') {
$this->_action = 'install'; $this->_action = 'install';
} else if ($this->_args[0] == 'upgrade') { } else if ($this->_args[0] == 'upgrade') {
$this->_action = 'upgrade'; $this->_action = 'upgrade';
} else if ($this->_args[0] == 'version') { } else if ($this->_args[0] == 'version') {
$this->_action = 'version'; $this->_action = 'version';
} else if ($this->_args[0] == 'init') { } else if ($this->_args[0] == 'init') {
$this->_action = 'init'; $this->_action = 'init';
} }
foreach ($this->_args as $argument) { foreach ($this->_args as $argument) {
if (preg_match('/to:[\w]+/i', $argument)) { if (preg_match('/to:[\w]+/i', $argument)) {
$this->_environment = str_replace('to:', '', $argument); $this->_environment = str_replace('to:', '', $argument);
@ -64,17 +64,17 @@ class Mage_Console
} }
} }
} }
public function getAction() public function getAction()
{ {
return $this->_action; return $this->_action;
} }
public function getEnvironment() public function getEnvironment()
{ {
return $this->_environment; return $this->_environment;
} }
public static function getActionOption($name, $default = false) public static function getActionOption($name, $default = false)
{ {
if (isset(self::$_actionOptions[$name])) { if (isset(self::$_actionOptions[$name])) {
@ -83,22 +83,22 @@ class Mage_Console
return $default; return $default;
} }
} }
public static function output($message, $tabs = 1, $newLine = 1) public static function output($message, $tabs = 1, $newLine = 1)
{ {
self::log(strip_tags($message)); self::log(strip_tags($message));
self::$_screenBuffer .= str_repeat("\t", $tabs) self::$_screenBuffer .= str_repeat("\t", $tabs)
. strip_tags($message) . strip_tags($message)
. str_repeat(PHP_EOL, $newLine); . str_repeat(PHP_EOL, $newLine);
$output = str_repeat("\t", $tabs) $output = str_repeat("\t", $tabs)
. Mage_Console_Colors::color($message) . Mage_Console_Colors::color($message)
. str_repeat(PHP_EOL, $newLine); . str_repeat(PHP_EOL, $newLine);
echo $output; echo $output;
} }
public static function executeCommand($command, &$output = null) public static function executeCommand($command, &$output = null)
{ {
self::log('---------------------------------'); self::log('---------------------------------');
@ -108,24 +108,24 @@ class Mage_Console
$log = array(); $log = array();
exec($command . ' 2>&1', $log, $return); exec($command . ' 2>&1', $log, $return);
$log = implode(PHP_EOL, $log); $log = implode(PHP_EOL, $log);
if (!$return) { if (!$return) {
$output = trim($log); $output = trim($log);
} }
self::$_commandsOutput .= PHP_EOL . trim($log) . PHP_EOL; self::$_commandsOutput .= PHP_EOL . trim($log) . PHP_EOL;
self::log($log); self::log($log);
self::log('---------------------------------'); self::log('---------------------------------');
return !$return; return !$return;
} }
public function run() public function run()
{ {
// Load Config // Load Config
$config = new Mage_Config; $config = new Mage_Config;
$config->loadGeneral(); $config->loadGeneral();
$config->loadEnvironment($this->getEnvironment()); $environmentOk = $config->loadEnvironment($this->getEnvironment());
$config->loadSCM(); $config->loadSCM();
// Logging // Logging
@ -136,59 +136,72 @@ class Mage_Console
} else { } else {
self::$_logEnabled = $config->general('logging', false); self::$_logEnabled = $config->general('logging', false);
} }
// Grettings // Grettings
if ($showGrettings) { if ($showGrettings) {
Mage_Console::output('Starting <blue>Magallanes</blue>', 0, 2); Mage_Console::output('Starting <blue>Magallanes</blue>', 0, 2);
} }
switch ($this->getAction()) { if (!$environmentOk) {
case 'deploy': Mage_Console::output('<red>You have selected an invalid environment</red>', 0, 2);
$task = new Mage_Task_Deploy;
$task->run($config);
break;
case 'releases':
$task = new Mage_Task_Releases;
switch ($this->_args[1]) {
case 'list':
$task->setAction($this->_args[1]);
break;
case 'rollback': } else {
$task->setAction($this->_args[1]); switch ($this->getAction()) {
$task->setRelease($this->_args[2]); case 'deploy':
break; $task = new Mage_Task_Deploy;
} $task->run($config);
$task->run($config); break;
break;
case 'update'; case 'releases':
$task = new Mage_Task_Releases;
if (!isset($this->_args[1])) {
Mage_Console::output('<red>You must indicate a task</red>', 0, 2);
break;
}
switch ($this->_args[1]) {
case 'list':
$task->setAction($this->_args[1]);
break;
case 'rollback':
if (!isset($this->_args[2])) {
Mage_Console::output('<red>You must indicate a release point</red>', 0, 2);
break 2;
}
$task->setAction($this->_args[1]);
$task->setRelease($this->_args[2]);
break;
}
$task->run($config);
break;
case 'update';
$task = new Mage_Task_Update; $task = new Mage_Task_Update;
$task->run($config); $task->run($config);
break; break;
case 'compile'; case 'compile';
$task = new Mage_Task_Compile; $task = new Mage_Task_Compile;
$task->run($config); $task->run($config);
break; break;
case 'install'; case 'install';
$task = new Mage_Task_Install; $task = new Mage_Task_Install;
$task->run(); $task->run();
break; break;
case 'upgrade'; case 'upgrade';
$task = new Mage_Task_Upgrade; $task = new Mage_Task_Upgrade;
$task->run(); $task->run();
break; break;
case 'init'; case 'init';
$task = new Mage_Task_Init; $task = new Mage_Task_Init;
$task->run(); $task->run();
break; break;
case 'add'; case 'add';
switch ($this->_args[1]) { switch ($this->_args[1]) {
case 'environment': case 'environment':
if (isset($this->_args[3]) && ($this->_args[3] == '--with-releases')) { if (isset($this->_args[3]) && ($this->_args[3] == '--with-releases')) {
@ -202,35 +215,36 @@ class Mage_Console
break; break;
} }
break; break;
case 'version'; case 'version';
$this->showVersion(); $this->showVersion();
break; break;
default: default:
Mage_Console::output('<red>Invalid action</red>', 0, 2); Mage_Console::output('<red>Invalid action</red>', 0, 2);
break; break;
}
} }
if ($showGrettings) { if ($showGrettings) {
Mage_Console::output('Finished <blue>Magallanes</blue>', 0, 2); Mage_Console::output('Finished <blue>Magallanes</blue>', 0, 2);
} }
} }
public function showVersion() public function showVersion()
{ {
Mage_Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2); Mage_Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2);
} }
public static function log($message, $continuation = false) public static function log($message, $continuation = false)
{ {
if (self::$_logEnabled) { if (self::$_logEnabled) {
if (self::$_log == null) { if (self::$_log == null) {
self::$_log = fopen('.mage/logs/log-' . date('Ymd-His') . '.log', 'w'); self::$_log = fopen('.mage/logs/log-' . date('Ymd-His') . '.log', 'w');
} }
$message = date('Y-m-d H:i:s -- ') . $message; $message = date('Y-m-d H:i:s -- ') . $message;
fwrite(self::$_log, $message . PHP_EOL); fwrite(self::$_log, $message . PHP_EOL);
} }
} }
} }

View file

@ -7,26 +7,31 @@ class Mage_Task_Deploy
private $_startTimeHosts = null; private $_startTimeHosts = null;
private $_endTimeHosts = null; private $_endTimeHosts = null;
private $_hostsCount = 0; private $_hostsCount = 0;
public function __construct() public function __construct()
{ {
$this->_releaseId = date('YmdHis'); $this->_releaseId = date('YmdHis');
} }
public function run(Mage_Config $config) public function run(Mage_Config $config)
{ {
$this->_startTime = time(); $this->_startTime = time();
$this->_config = $config; $this->_config = $config;
if ($config->getEnvironment() == '') {
Mage_Console::output('<red>You must specify an environment</red>', 0, 2);
return;
}
// Run Pre-Deployment Tasks // Run Pre-Deployment Tasks
$this->_runNonDeploymentTasks('pre-deploy', $config, 'Pre-Deployment'); $this->_runNonDeploymentTasks('pre-deploy', $config, 'Pre-Deployment');
// Run Tasks for Deployment // Run Tasks for Deployment
$hosts = $config->getHosts(); $hosts = $config->getHosts();
if (count($hosts) == 0) { if (count($hosts) == 0) {
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3); Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
} else { } else {
$this->_startTimeHosts = time(); $this->_startTimeHosts = time();
foreach ($hosts as $host) { foreach ($hosts as $host) {
@ -34,9 +39,9 @@ class Mage_Task_Deploy
$config->setHost($host); $config->setHost($host);
$tasks = 0; $tasks = 0;
$completedTasks = 0; $completedTasks = 0;
Mage_Console::output('Deploying to <dark_gray>' . $config->getHost() . '</dark_gray>'); Mage_Console::output('Deploying to <dark_gray>' . $config->getHost() . '</dark_gray>');
$tasksToRun = $config->getTasks(); $tasksToRun = $config->getTasks();
array_unshift($tasksToRun, 'deployment/rsync'); array_unshift($tasksToRun, 'deployment/rsync');
@ -54,10 +59,10 @@ class Mage_Task_Deploy
$tasks++; $tasks++;
$task = Mage_Task_Factory::get($taskName, $config, false, 'deploy'); $task = Mage_Task_Factory::get($taskName, $config, false, 'deploy');
$task->init(); $task->init();
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false); Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
$result = $task->run(); $result = $task->run();
if ($result == true) { if ($result == true) {
Mage_Console::output('<green>OK</green>', 0); Mage_Console::output('<green>OK</green>', 0);
$completedTasks++; $completedTasks++;
@ -65,13 +70,13 @@ class Mage_Task_Deploy
Mage_Console::output('<red>FAIL</red>', 0); Mage_Console::output('<red>FAIL</red>', 0);
} }
} }
if ($completedTasks == $tasks) { if ($completedTasks == $tasks) {
$tasksColor = 'green'; $tasksColor = 'green';
} else { } else {
$tasksColor = 'red'; $tasksColor = 'red';
} }
Mage_Console::output('Deployment to <dark_gray>' . $config->getHost() . '</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);
} }
} }
@ -85,24 +90,24 @@ class Mage_Task_Deploy
if ($this->_hostsCount > 0) { if ($this->_hostsCount > 0) {
$timeTextHost = $this->_transcurredTime($this->_endTimeHosts - $this->_startTimeHosts); $timeTextHost = $this->_transcurredTime($this->_endTimeHosts - $this->_startTimeHosts);
Mage_Console::output('Time for deployment: <dark_gray>' . $timeTextHost . '</dark_gray>.'); Mage_Console::output('Time for deployment: <dark_gray>' . $timeTextHost . '</dark_gray>.');
$timeTextPerHost = $this->_transcurredTime(round(($this->_endTimeHosts - $this->_startTimeHosts) / $this->_hostsCount)); $timeTextPerHost = $this->_transcurredTime(round(($this->_endTimeHosts - $this->_startTimeHosts) / $this->_hostsCount));
Mage_Console::output('Average time per host: <dark_gray>' . $timeTextPerHost . '</dark_gray>.'); Mage_Console::output('Average time per host: <dark_gray>' . $timeTextPerHost . '</dark_gray>.');
} }
// Time Information General // Time Information General
$timeText = $this->_transcurredTime(time() - $this->_startTime); $timeText = $this->_transcurredTime(time() - $this->_startTime);
Mage_Console::output('Total time: <dark_gray>' . $timeText . '</dark_gray>.', 1, 2); Mage_Console::output('Total time: <dark_gray>' . $timeText . '</dark_gray>.', 1, 2);
} }
private function _runNonDeploymentTasks($stage, Mage_Config $config, $title) private function _runNonDeploymentTasks($stage, Mage_Config $config, $title)
{ {
$tasksToRun = $config->getTasks($stage); $tasksToRun = $config->getTasks($stage);
// Look for Remote Source // Look for Remote Source
if (is_array($this->_config->deployment('source', null))) { if (is_array($this->_config->deployment('source', null))) {
if ($stage == 'pre-deploy') { if ($stage == 'pre-deploy') {
array_unshift($tasksToRun, 'scm/clone'); array_unshift($tasksToRun, 'scm/clone');
} elseif ($stage == 'post-deploy') { } elseif ($stage == 'post-deploy') {
array_unshift($tasksToRun, 'scm/remove-clone'); array_unshift($tasksToRun, 'scm/remove-clone');
} }
@ -110,60 +115,60 @@ class Mage_Task_Deploy
if (count($tasksToRun) == 0) { 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); Mage_Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
} else { } else {
Mage_Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:'); Mage_Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
$tasks = 0; $tasks = 0;
$completedTasks = 0; $completedTasks = 0;
foreach ($tasksToRun as $taskName) { foreach ($tasksToRun as $taskName) {
$tasks++; $tasks++;
$task = Mage_Task_Factory::get($taskName, $config, false, $stage); $task = Mage_Task_Factory::get($taskName, $config, false, $stage);
$task->init(); $task->init();
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, 0); Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, 0);
$result = $task->run(); $result = $task->run();
if ($result == true) { if ($result == true) {
Mage_Console::output('<green>OK</green>', 0); Mage_Console::output('<green>OK</green>', 0);
$completedTasks++; $completedTasks++;
} else { } else {
Mage_Console::output('<red>FAIL</red>', 0); Mage_Console::output('<red>FAIL</red>', 0);
} }
} }
if ($completedTasks == $tasks) { if ($completedTasks == $tasks) {
$tasksColor = 'green'; $tasksColor = 'green';
} else { } else {
$tasksColor = 'red'; $tasksColor = 'red';
} }
Mage_Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3); Mage_Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
} }
} }
private function _transcurredTime($time) private function _transcurredTime($time)
{ {
$hours = floor($time / 3600); $hours = floor($time / 3600);
$minutes = floor(($time - ($hours * 3600)) / 60); $minutes = floor(($time - ($hours * 3600)) / 60);
$seconds = $time - ($minutes * 60) - ($hours * 3600); $seconds = $time - ($minutes * 60) - ($hours * 3600);
$timeText = array(); $timeText = array();
if ($hours > 0) { if ($hours > 0) {
$timeText[] = $hours . ' hours'; $timeText[] = $hours . ' hours';
} }
if ($minutes > 0) { if ($minutes > 0) {
$timeText[] = $minutes . ' minutes'; $timeText[] = $minutes . ' minutes';
} }
if ($seconds > 0) { if ($seconds > 0) {
$timeText[] = $seconds . ' seconds'; $timeText[] = $seconds . ' seconds';
} }
return implode(' ', $timeText); return implode(' ', $timeText);
} }
} }

View file

@ -4,39 +4,44 @@ class Mage_Task_Releases
private $_config = null; private $_config = null;
private $_action = null; private $_action = null;
private $_release = null; private $_release = null;
public function setAction($action) public function setAction($action)
{ {
$this->_action = $action; $this->_action = $action;
return $this; return $this;
} }
public function getAction() public function getAction()
{ {
return $this->_action; return $this->_action;
} }
public function setRelease($releaseId) public function setRelease($releaseId)
{ {
$this->_release = $releaseId; $this->_release = $releaseId;
return $this; return $this;
} }
public function getRelease() public function getRelease()
{ {
return $this->_release; return $this->_release;
} }
public function run(Mage_Config $config) public function run(Mage_Config $config)
{ {
$this->_config = $config; $this->_config = $config;
if ($config->getEnvironment() == '') {
Mage_Console::output('<red>You must specify an environment</red>', 0, 2);
return;
}
// Run Tasks for Deployment // Run Tasks for Deployment
$hosts = $config->getHosts(); $hosts = $config->getHosts();
if (count($hosts) == 0) { 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); Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
} else { } else {
foreach ($hosts as $host) { foreach ($hosts as $host) {
$config->setHost($host); $config->setHost($host);
@ -46,7 +51,7 @@ class Mage_Task_Releases
$task->init(); $task->init();
$result = $task->run(); $result = $task->run();
break; break;
case 'rollback': case 'rollback':
$task = Mage_Task_Factory::get('releases/rollback', $config); $task = Mage_Task_Factory::get('releases/rollback', $config);
$task->init(); $task->init();