mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-08-25 21:00:18 +02:00
New configuration usage. Changes on Releases Listing.
This commit is contained in:
parent
dd46e4d637
commit
2e35bfe129
@ -3,6 +3,8 @@ class Mage_Config
|
||||
{
|
||||
private $_environment = null;
|
||||
private $_scm = null;
|
||||
private $_host = null;
|
||||
private $_releaseId = null;
|
||||
|
||||
public function loadEnvironment($environment)
|
||||
{
|
||||
@ -40,6 +42,28 @@ class Mage_Config
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->_host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
public function setReleaseId($id)
|
||||
{
|
||||
$this->_releaseId = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReleaseId()
|
||||
{
|
||||
return $this->_releaseId;
|
||||
}
|
||||
|
||||
public function getTasks($stage = 'on-deploy')
|
||||
{
|
||||
switch ($stage) {
|
||||
@ -87,4 +111,34 @@ class Mage_Config
|
||||
|
||||
return $taskConfig;
|
||||
}
|
||||
|
||||
public function deployment($option, $default = false)
|
||||
{
|
||||
$options = $this->getEnvironment();
|
||||
if (isset($options['deployment'][$option])) {
|
||||
return $options['deployment'][$option];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function release($option, $default = false)
|
||||
{
|
||||
$options = $this->getEnvironment();
|
||||
if (isset($options['releases'][$option])) {
|
||||
return $options['releases'][$option];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function scm($option, $default = false)
|
||||
{
|
||||
$options = $this->_scm;
|
||||
if (isset($options[$option])) {
|
||||
return $options[$option];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,28 +9,15 @@ class Mage_Task_BuiltIn_Deployment_Releases
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (isset($this->_config['deploy']['releases']['enabled'])) {
|
||||
if ($this->_config['deploy']['releases']['enabled'] == 'true') {
|
||||
if (isset($this->_config['deploy']['releases']['directory'])) {
|
||||
$releasesDirectory = $this->_config['deploy']['releases']['directory'];
|
||||
} else {
|
||||
$releasesDirectory = 'releases';
|
||||
}
|
||||
if (isset($this->_config['deploy']['releases']['symlink'])) {
|
||||
$symlink = $this->_config['deploy']['releases']['symlink'];
|
||||
} else {
|
||||
$symlink = 'current';
|
||||
}
|
||||
if ($this->_config->release('enabled', false) == true) {
|
||||
$releasesDirectory = $this->_config->release('directory', 'releases');
|
||||
$symlink = $this->_config->release('symlink', 'current');
|
||||
|
||||
$currentCopy = $releasesDirectory
|
||||
. '/' . $this->_config['deploy']['releases']['_id'];
|
||||
$currentCopy = $releasesDirectory . '/' . $this->_config->getReleaseId();
|
||||
|
||||
$result = $this->_runRemoteCommand('ln -sf ' . $currentCopy . ' ' . $symlink);
|
||||
return $result;
|
||||
$result = $this->_runRemoteCommand('ln -sf ' . $currentCopy . ' ' . $symlink);
|
||||
return $result;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -4,14 +4,10 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
if (isset($this->_config['deploy']['releases']['enabled'])) {
|
||||
if ($this->_config['deploy']['releases']['enabled'] == 'true') {
|
||||
return 'Rsync (with Releases) [built-in]';
|
||||
} else {
|
||||
return 'Rsync [built-in]';
|
||||
}
|
||||
if ($this->_config->release('enabled', false) == true) {
|
||||
return 'Rsync (with Releases) [built-in]';
|
||||
} else {
|
||||
return 'Rsync [built-in]';
|
||||
return 'Rsync [built-in]';
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,33 +21,23 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
);
|
||||
|
||||
// Look for User Excludes
|
||||
if (isset($this->_config['deploy']['deployment']['excludes'])) {
|
||||
$userExcludes = (array) $this->_config['deploy']['deployment']['excludes'];
|
||||
} else {
|
||||
$userExcludes = array();
|
||||
}
|
||||
$userExcludes = $this->_config->deployment('excludes', array());
|
||||
|
||||
// If we are working with releases
|
||||
$deployToDirectory = $this->_config['deploy']['deployment']['to'];
|
||||
if (isset($this->_config['deploy']['releases']['enabled'])) {
|
||||
if ($this->_config['deploy']['releases']['enabled'] == 'true') {
|
||||
if (isset($this->_config['deploy']['releases']['directory'])) {
|
||||
$releasesDirectory = $this->_config['deploy']['releases']['directory'];
|
||||
} else {
|
||||
$releasesDirectory = 'releases';
|
||||
}
|
||||
$deployToDirectory = $this->_config->deployment('to');
|
||||
if ($this->_config->release('enabled', false) == true) {
|
||||
$releasesDirectory = $this->_config->release('directory', 'releases');
|
||||
|
||||
$deployToDirectory = rtrim($this->_config['deploy']['deployment']['to'], '/')
|
||||
. '/' . $releasesDirectory
|
||||
. '/' . $this->_config['deploy']['releases']['_id'];
|
||||
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config['deploy']['releases']['_id']);
|
||||
}
|
||||
$deployToDirectory = rtrim($this->_config->deployment('to'), '/')
|
||||
. '/' . $releasesDirectory
|
||||
. '/' . $this->_config->getReleaseId();
|
||||
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config->getReleaseId());
|
||||
}
|
||||
|
||||
$command = 'rsync -avz '
|
||||
. $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
|
||||
. $this->_config['deploy']['deployment']['from'] . ' '
|
||||
. $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory;
|
||||
. $this->_config->deployment('from') . ' '
|
||||
. $this->_config->deployment('user') . '@' . $this->_config->getHost() . ':' . $deployToDirectory;
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
|
||||
|
@ -9,39 +9,44 @@ class Mage_Task_BuiltIn_Releases_List
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (isset($this->_config['deploy']['releases']['enabled'])) {
|
||||
if ($this->_config['deploy']['releases']['enabled'] == 'true') {
|
||||
if (isset($this->_config['deploy']['releases']['directory'])) {
|
||||
$releasesDirectory = $this->_config['deploy']['releases']['directory'];
|
||||
} else {
|
||||
$releasesDirectory = 'releases';
|
||||
}
|
||||
if (isset($this->_config['deploy']['releases']['symlink'])) {
|
||||
$symlink = $this->_config['deploy']['releases']['symlink'];
|
||||
} else {
|
||||
$symlink = 'current';
|
||||
}
|
||||
if ($this->_config->release('enabled', false) == true) {
|
||||
$releasesDirectory = $this->_config->release('directory', 'releases');
|
||||
$symlink = $this->_config->release('symlink', 'current');
|
||||
|
||||
Mage_Console::output('Releases available on <dark_gray>' . $this->_config['deploy']['host'] . '</dark_gray>');
|
||||
|
||||
$output = '';
|
||||
$result = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $output);
|
||||
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
|
||||
|
||||
if (count($releases) == 0) {
|
||||
Mage_Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
|
||||
} else {
|
||||
rsort($releases);
|
||||
foreach ($releases as $releaseIndex => $releaseDate) {
|
||||
Mage_Console::output('Index: ' . $releaseIndex . ' - <purple>' . $releaseDate . '</purple>', 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
Mage_Console::output('Releases available on <dark_gray>' . $this->_config->getHost() . '</dark_gray>');
|
||||
|
||||
$output = '';
|
||||
$result = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $output);
|
||||
$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
|
||||
|
||||
if (count($releases) == 0) {
|
||||
Mage_Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
|
||||
} else {
|
||||
return false;
|
||||
rsort($releases);
|
||||
$releases = array_slice($releases, 0, 10);
|
||||
|
||||
foreach ($releases as $releaseIndex => $release) {
|
||||
$releaseIndex = str_pad($releaseIndex * -1, 2, ' ', STR_PAD_LEFT);
|
||||
$releaseDate = $release[0] . $release[1] . $release[2] .$release[3]
|
||||
. '-'
|
||||
. $release[4] . $release[5]
|
||||
. '-'
|
||||
. $release[6] . $release[7]
|
||||
. ' '
|
||||
. $release[8] . $release[9]
|
||||
. ':'
|
||||
. $release[10] . $release[11]
|
||||
. ':'
|
||||
. $release[12] . $release[13];
|
||||
|
||||
Mage_Console::output(
|
||||
'Release: <purple>' . $release . '</purple> '
|
||||
. '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
|
||||
. '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>', 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class Mage_Task_BuiltIn_Scm_Update
|
||||
|
||||
public function init()
|
||||
{
|
||||
switch ($this->_config['scm']['type']) {
|
||||
switch ($this->_config->scm('type')) {
|
||||
case 'git':
|
||||
$this->_name = 'SCM Update (GIT) [built-in]';
|
||||
break;
|
||||
@ -24,7 +24,7 @@ class Mage_Task_BuiltIn_Scm_Update
|
||||
|
||||
public function run()
|
||||
{
|
||||
switch ($this->_config['scm']['type']) {
|
||||
switch ($this->_config->scm('type')) {
|
||||
case 'git':
|
||||
$command = 'git pull';
|
||||
break;
|
||||
|
@ -24,21 +24,18 @@ class Mage_Task_Deploy
|
||||
|
||||
} else {
|
||||
foreach ($hosts as $host) {
|
||||
$taskConfig = $config->getConfig($host);
|
||||
$config->setHost($host);
|
||||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
Mage_Console::output('Deploying to <dark_gray>' . $host . '</dark_gray>');
|
||||
|
||||
$tasksToRun = $config->getTasks();
|
||||
if (isset($taskConfig['deploy']['releases'])) {
|
||||
if (isset($taskConfig['deploy']['releases']['enabled'])) {
|
||||
if ($taskConfig['deploy']['releases']['enabled'] == 'true') {
|
||||
$taskConfig['deploy']['releases']['_id'] = $this->_releaseId;
|
||||
array_push($tasksToRun, 'deployment/releases');
|
||||
}
|
||||
}
|
||||
if ($config->release('enabled', false) == true) {
|
||||
$config->setReleaseId($this->_releaseId);
|
||||
array_push($tasksToRun, 'deployment/releases');
|
||||
}
|
||||
|
||||
if (count($tasksToRun) == 0) {
|
||||
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> skipped!', 1, 3);
|
||||
@ -46,7 +43,7 @@ class Mage_Task_Deploy
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskName) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskName, $taskConfig);
|
||||
$task = Mage_Task_Factory::get($taskName, $config);
|
||||
$task->init();
|
||||
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
@ -87,13 +84,12 @@ class Mage_Task_Deploy
|
||||
} else {
|
||||
Mage_Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
|
||||
|
||||
$taskConfig = $config->getConfig();
|
||||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
foreach ($tasksToRun as $taskName) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskName, $taskConfig);
|
||||
$task = Mage_Task_Factory::get($taskName, $config);
|
||||
$task->init();
|
||||
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, 0);
|
||||
|
@ -7,7 +7,7 @@ class Mage_Task_Factory
|
||||
* @param string $taskName
|
||||
* @return Mage_Task_TaskAbstract
|
||||
*/
|
||||
public static function get($taskName, $taskConfig)
|
||||
public static function get($taskName, Mage_Config $taskConfig)
|
||||
{
|
||||
$instance = null;
|
||||
|
||||
|
@ -27,15 +27,15 @@ class Mage_Task_Releases
|
||||
|
||||
} else {
|
||||
foreach ($hosts as $host) {
|
||||
$taskConfig = $config->getConfig($host);
|
||||
|
||||
$config->setHost($host);
|
||||
switch ($this->getAction()) {
|
||||
case 'list':
|
||||
$task = Mage_Task_Factory::get('releases/list', $taskConfig);
|
||||
$task = Mage_Task_Factory::get('releases/list', $config);
|
||||
$task->init();
|
||||
$result = $task->run();
|
||||
break;
|
||||
}
|
||||
Mage_Console::output('');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ abstract class Mage_Task_TaskAbstract
|
||||
|
||||
public abstract function run();
|
||||
|
||||
public final function __construct($config)
|
||||
public final function __construct(Mage_Config $config)
|
||||
{
|
||||
$this->_config = $config;
|
||||
}
|
||||
@ -24,8 +24,8 @@ abstract class Mage_Task_TaskAbstract
|
||||
protected final function _runRemoteCommand($command, &$output = null)
|
||||
{
|
||||
$localCommand = 'ssh '
|
||||
. $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ' '
|
||||
. '"cd ' . $this->_config['deploy']['deployment']['to'] . ' && '
|
||||
. $this->_config->deployment('user') . '@' . $this->_config->getHost() . ' '
|
||||
. '"cd ' . $this->_config->deployment('to') . ' && '
|
||||
. $command . '"';
|
||||
|
||||
return $this->_runLocalCommand($localCommand, $output);
|
||||
|
Loading…
Reference in New Issue
Block a user