mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-09-13 12:40:18 +02:00
- factored constants out;
- fixed bug: "releases list" command would die checking for unnecessary --release parameter; - console prints log file name if if logging is enabled
This commit is contained in:
parent
e7cad31681
commit
11bdd68fff
@ -30,7 +30,15 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
||||||
{
|
{
|
||||||
/**
|
const DEFAULT_RELEASE_IS_ENABLED = false;
|
||||||
|
const DEPLOY_STRATEGY_DISABLED = 'disabled';
|
||||||
|
const DEPLOY_STRATEGY_RSYNC = 'rsync';
|
||||||
|
const DEPLOY_STRATEGY_TARGZ = 'targz';
|
||||||
|
const DEPLOY_STRATEGY_GIT_REBASE = 'git-rebase';
|
||||||
|
const DEPLOY_STRATEGY_GUESS = 'guess';
|
||||||
|
const DEFAULT_DEPLOY_STRATEGY = self::DEPLOY_STRATEGY_GUESS;
|
||||||
|
|
||||||
|
/**
|
||||||
* Deploy has Failed
|
* Deploy has Failed
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -523,24 +531,24 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
protected function chooseDeployStrategy()
|
protected function chooseDeployStrategy()
|
||||||
{
|
{
|
||||||
// Guess a Deploy Strategy
|
// Guess a Deploy Strategy
|
||||||
switch ($this->getConfig()->deployment('strategy', 'guess')) {
|
switch ($this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY)) {
|
||||||
case 'disabled':
|
case self::DEPLOY_STRATEGY_DISABLED:
|
||||||
$deployStrategy = 'deployment/strategy/disabled';
|
$deployStrategy = 'deployment/strategy/disabled';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'rsync':
|
case self::DEPLOY_STRATEGY_RSYNC:
|
||||||
$deployStrategy = 'deployment/strategy/rsync';
|
$deployStrategy = 'deployment/strategy/rsync';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'targz':
|
case self::DEPLOY_STRATEGY_TARGZ:
|
||||||
$deployStrategy = 'deployment/strategy/tar-gz';
|
$deployStrategy = 'deployment/strategy/tar-gz';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'git-rebase':
|
case self::DEPLOY_STRATEGY_GIT_REBASE:
|
||||||
$deployStrategy = 'deployment/strategy/git-rebase';
|
$deployStrategy = 'deployment/strategy/git-rebase';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'guess':
|
case self::DEPLOY_STRATEGY_GUESS:
|
||||||
default:
|
default:
|
||||||
if ($this->getConfig()->release('enabled', false) == true) {
|
if ($this->getConfig()->release('enabled', false) == true) {
|
||||||
$deployStrategy = 'deployment/strategy/tar-gz';
|
$deployStrategy = 'deployment/strategy/tar-gz';
|
||||||
@ -558,10 +566,12 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
protected function chooseReleaseStrategy()
|
protected function chooseReleaseStrategy()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->getConfig()->release('enabled', false) === true) {
|
if ($this->getConfig()->release('enabled', self::DEFAULT_RELEASE_IS_ENABLED)
|
||||||
$strategy = 'deployment/strategy/disabled';
|
&& $this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY) !== self::DEPLOY_STRATEGY_DISABLED
|
||||||
} else {
|
) {
|
||||||
$strategy = 'deployment/release';
|
$strategy = 'deployment/release';
|
||||||
|
} else {
|
||||||
|
$strategy = 'deployment/strategy/disabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $strategy;
|
return $strategy;
|
||||||
|
@ -28,44 +28,51 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
|
$subCommand = $this->getConfig()->getArgument(1);
|
||||||
Console::output('<red>This release is mandatory.</red>', 1, 2);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$subcommand = $this->getConfig()->getArgument(1);
|
|
||||||
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
|
||||||
if (file_exists($lockFile) && ($subcommand == 'rollback')) {
|
|
||||||
Console::output('<red>This environment is locked!</red>', 1, 2);
|
|
||||||
echo file_get_contents($lockFile);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run Tasks for Deployment
|
// Run Tasks for Deployment
|
||||||
$hosts = $this->getConfig()->getHosts();
|
$hosts = $this->getConfig()->getHosts();
|
||||||
|
|
||||||
if (count($hosts) == 0) {
|
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> <dark_gray>No hosts defined, unable to get releases.</dark_gray>',
|
||||||
|
1, 3
|
||||||
|
);
|
||||||
|
|
||||||
} else {
|
return false;
|
||||||
foreach ($hosts as $host) {
|
}
|
||||||
$this->getConfig()->setHost($host);
|
|
||||||
|
|
||||||
switch ($subcommand) {
|
foreach ($hosts as $host) {
|
||||||
case 'list':
|
$this->getConfig()->setHost($host);
|
||||||
$task = Factory::get('releases/list', $this->getConfig());
|
|
||||||
$task->init();
|
|
||||||
$result = $task->run();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'rollback':
|
switch ($subCommand) {
|
||||||
$releaseId = $this->getConfig()->getParameter('release', '');
|
case 'list':
|
||||||
$task = Factory::get('releases/rollback', $this->getConfig());
|
$task = Factory::get('releases/list', $this->getConfig());
|
||||||
$task->init();
|
$task->init();
|
||||||
$task->setRelease($releaseId);
|
$result = $task->run();
|
||||||
$result = $task->run();
|
break;
|
||||||
break;
|
|
||||||
|
case 'rollback':
|
||||||
|
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
|
||||||
|
Console::output('<red>Missing required releaseid.</red>', 1, 2);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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 false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$releaseId = $this->getConfig()->getParameter('release', '');
|
||||||
|
$task = Factory::get('releases/rollback', $this->getConfig());
|
||||||
|
$task->init();
|
||||||
|
$task->setRelease($releaseId);
|
||||||
|
$result = $task->run();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,11 @@ class Console
|
|||||||
$showGreetings = false;
|
$showGreetings = false;
|
||||||
} else {
|
} else {
|
||||||
self::$logEnabled = $config->general('logging', false);
|
self::$logEnabled = $config->general('logging', false);
|
||||||
|
if(self::$logEnabled)
|
||||||
|
{
|
||||||
|
self::log("Logging enabled");
|
||||||
|
self::output('<red> Logging enabled: ' . self::getLogFile() . '</red>', 1, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greetings
|
// Greetings
|
||||||
|
Loading…
Reference in New Issue
Block a user