mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	First iteration of the Releases feature.
This commit is contained in:
		
							parent
							
								
									67ca7b1e21
								
							
						
					
					
						commit
						5faad41b78
					
				
							
								
								
									
										39
									
								
								Mage/Task/BuiltIn/Deployment/Releases.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Mage/Task/BuiltIn/Deployment/Releases.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class Mage_Task_BuiltIn_Deployment_Releases
 | 
				
			||||||
 | 
					    extends Mage_Task_TaskAbstract
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function getName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 'Releasing [built-in]';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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';
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $currentCopy = $releasesDirectory
 | 
				
			||||||
 | 
					                             . '/' . $this->_config['deploy']['releases']['_id'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $result = $this->_runRemoteCommand('ln -sf ' . $currentCopy . ' ' . $symlink);
 | 
				
			||||||
 | 
					                return $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -4,7 +4,15 @@ class Mage_Task_BuiltIn_Deployment_Rsync
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Rsync [built-in]';
 | 
					        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]';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return 'Rsync [built-in]';            
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
@ -22,11 +30,28 @@ class Mage_Task_BuiltIn_Deployment_Rsync
 | 
				
			|||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            $userExcludes = array();
 | 
					            $userExcludes = array();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // If we are working with releases
 | 
				
			||||||
 | 
					        $deployToDirectory = $this->_config['deploy']['deploy-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 = rtrim($this->_config['deploy']['deploy-to'], '/')
 | 
				
			||||||
 | 
					                                   . '/' . $releasesDirectory
 | 
				
			||||||
 | 
					                                   . '/' . $this->_config['deploy']['releases']['_id'];
 | 
				
			||||||
 | 
					                $this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config['deploy']['releases']['_id']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'rsync -avz '
 | 
					        $command = 'rsync -avz '
 | 
				
			||||||
                 . $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
 | 
					                 . $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
 | 
				
			||||||
                 . $this->_config['deploy']['deploy-from'] . ' '
 | 
					                 . $this->_config['deploy']['deploy-from'] . ' '
 | 
				
			||||||
                 . $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $this->_config['deploy']['deploy-to'];
 | 
					                 . $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $result = $this->_runLocalCommand($command);
 | 
					        $result = $this->_runLocalCommand($command);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,12 @@
 | 
				
			|||||||
class Mage_Task_Deploy
 | 
					class Mage_Task_Deploy
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private $_config = null;
 | 
					    private $_config = null;
 | 
				
			||||||
 | 
					    private $_releaseId = null;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public function __construct()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->_releaseId = date('YmdHis');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public function run(Mage_Config $config)
 | 
					    public function run(Mage_Config $config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -25,6 +31,14 @@ class Mage_Task_Deploy
 | 
				
			|||||||
                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 (isset($taskConfig['deploy']['releases']['enabled'])) {
 | 
				
			||||||
 | 
					                        if ($taskConfig['deploy']['releases']['enabled'] == 'true') {
 | 
				
			||||||
 | 
					                            $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);
 | 
				
			||||||
 | 
				
			|||||||
@ -3,9 +3,9 @@ user: root
 | 
				
			|||||||
deploy-from: ./
 | 
					deploy-from: ./
 | 
				
			||||||
deploy-to: /var/www/vhosts/example.com/www
 | 
					deploy-to: /var/www/vhosts/example.com/www
 | 
				
			||||||
releases:
 | 
					releases:
 | 
				
			||||||
  - enabled: true
 | 
					  enabled: true
 | 
				
			||||||
  - symlink: current
 | 
					  symlink: current
 | 
				
			||||||
  - directory: releases
 | 
					  directory: releases
 | 
				
			||||||
hosts:
 | 
					hosts:
 | 
				
			||||||
  - s01.example.com
 | 
					  - s01.example.com
 | 
				
			||||||
  - s02.example.com
 | 
					  - s02.example.com
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user