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