mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	Import of current work
This commit is contained in:
		
							parent
							
								
									9f89c76716
								
							
						
					
					
						commit
						3caa3d7313
					
				
							
								
								
									
										10
									
								
								Magallanes/Autoload.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Magallanes/Autoload.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Autoload
 | 
			
		||||
{
 | 
			
		||||
    public static function autoload($className)
 | 
			
		||||
    {
 | 
			
		||||
        $baseDir = dirname(dirname(__FILE__));
 | 
			
		||||
        $classFile = $baseDir . '/' . str_replace('_', '/', $className . '.php');
 | 
			
		||||
        require_once $classFile;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								Magallanes/Config.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Magallanes/Config.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Config
 | 
			
		||||
{
 | 
			
		||||
    private $_environment = null;
 | 
			
		||||
    private $_csm = null;
 | 
			
		||||
    
 | 
			
		||||
    public function loadEnvironment($environment)
 | 
			
		||||
    {
 | 
			
		||||
        $this->_environment = yaml_parse_file('.mage/environment/' . $environment . '.yaml');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function loadCSM()
 | 
			
		||||
    {
 | 
			
		||||
        $this->_csm = yaml_parse_file('.mage/csm.yaml');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getEnvironment()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_environment;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getCSM()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_csm;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										65
									
								
								Magallanes/Console.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								Magallanes/Console.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,65 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Console
 | 
			
		||||
{
 | 
			
		||||
    private $_args;
 | 
			
		||||
    private $_action;
 | 
			
		||||
    private $_actionOptions;
 | 
			
		||||
    private $_environment;
 | 
			
		||||
    
 | 
			
		||||
    public function setArgs($args)
 | 
			
		||||
    {
 | 
			
		||||
        $this->_args = $args;
 | 
			
		||||
        array_shift($this->_args);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function parse()
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($this->_args as $argument) {
 | 
			
		||||
            if ($argument == 'deploy') {
 | 
			
		||||
                $this->_action = 'deploy';
 | 
			
		||||
 | 
			
		||||
            } else if ($argument == 'update') {
 | 
			
		||||
                $this->_action = 'update';
 | 
			
		||||
 | 
			
		||||
            } else if (preg_match('/to:[\w]+/i', $argument)) {
 | 
			
		||||
                $this->_environment = str_replace('to:', '', $argument);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getAction()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_action;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getEnvironment()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->_environment;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static function output($message)
 | 
			
		||||
    {
 | 
			
		||||
        echo $message;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function run()
 | 
			
		||||
    {
 | 
			
		||||
        $config = new Magallanes_Config;
 | 
			
		||||
 | 
			
		||||
        switch ($this->getAction()) {
 | 
			
		||||
            case 'deploy':
 | 
			
		||||
                $config->loadEnvironment($this->getEnvironment());
 | 
			
		||||
                $task = new Magallanes_Task_Deploy;
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case 'update';
 | 
			
		||||
                $config->loadCSM();
 | 
			
		||||
                $task = new Magallanes_Task_Update;
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $task->run($config);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
define('PHP_TAB', "\t");
 | 
			
		||||
							
								
								
									
										53
									
								
								Magallanes/Console/Colors.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Magallanes/Console/Colors.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,53 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Console_Colors {
 | 
			
		||||
	private static $foreground_colors = array ();
 | 
			
		||||
	private static $background_colors = array ();
 | 
			
		||||
	
 | 
			
		||||
	public function __construct() {
 | 
			
		||||
		// Set up shell colors
 | 
			
		||||
		self::$foreground_colors ['black'] = '0;30';
 | 
			
		||||
		self::$foreground_colors ['dark_gray'] = '1;30';
 | 
			
		||||
		self::$foreground_colors ['blue'] = '0;34';
 | 
			
		||||
		self::$foreground_colors ['light_blue'] = '1;34';
 | 
			
		||||
		self::$foreground_colors ['green'] = '0;32';
 | 
			
		||||
		self::$foreground_colors ['light_green'] = '1;32';
 | 
			
		||||
		self::$foreground_colors ['cyan'] = '0;36';
 | 
			
		||||
		self::$foreground_colors ['light_cyan'] = '1;36';
 | 
			
		||||
		self::$foreground_colors ['red'] = '0;31';
 | 
			
		||||
		self::$foreground_colors ['light_red'] = '1;31';
 | 
			
		||||
		self::$foreground_colors ['purple'] = '0;35';
 | 
			
		||||
		self::$foreground_colors ['light_purple'] = '1;35';
 | 
			
		||||
		self::$foreground_colors ['brown'] = '0;33';
 | 
			
		||||
		self::$foreground_colors ['yellow'] = '1;33';
 | 
			
		||||
		self::$foreground_colors ['light_gray'] = '0;37';
 | 
			
		||||
		self::$foreground_colors ['white'] = '1;37';
 | 
			
		||||
		
 | 
			
		||||
		self::$background_colors ['black'] = '40';
 | 
			
		||||
		self::$background_colors ['red'] = '41';
 | 
			
		||||
		self::$background_colors ['green'] = '42';
 | 
			
		||||
		self::$background_colors ['yellow'] = '43';
 | 
			
		||||
		self::$background_colors ['blue'] = '44';
 | 
			
		||||
		self::$background_colors ['magenta'] = '45';
 | 
			
		||||
		self::$background_colors ['cyan'] = '46';
 | 
			
		||||
		self::$background_colors ['light_gray'] = '47';
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// Returns colored string
 | 
			
		||||
	public static function g($string, $foreground_color = null, $background_color = null) {
 | 
			
		||||
		$colored_string = "";
 | 
			
		||||
		
 | 
			
		||||
		// Check if given foreground color found
 | 
			
		||||
		if (isset ( self::$foreground_colors [$foreground_color] )) {
 | 
			
		||||
			$colored_string .= "\033[" . self::$foreground_colors [$foreground_color] . "m";
 | 
			
		||||
		}
 | 
			
		||||
		// Check if given background color found
 | 
			
		||||
		if (isset ( self::$background_colors [$background_color] )) {
 | 
			
		||||
			$colored_string .= "\033[" . self::$background_colors [$background_color] . "m";
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Add string and end coloring
 | 
			
		||||
		$colored_string .= $string . "\033[0m";
 | 
			
		||||
		
 | 
			
		||||
		return $colored_string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								Magallanes/Task/CSM/Git.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Magallanes/Task/CSM/Git.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Task_CSM_Git
 | 
			
		||||
{
 | 
			
		||||
    private $_url = null;
 | 
			
		||||
    
 | 
			
		||||
    public function run($url)
 | 
			
		||||
    {
 | 
			
		||||
        $this->_url = $url;
 | 
			
		||||
        $this->_update();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private function _update()
 | 
			
		||||
    {
 | 
			
		||||
        Magallanes_Console::output('git pull ' . $this->_url . PHP_EOL);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								Magallanes/Task/Deploy.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Magallanes/Task/Deploy.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Task_Deploy
 | 
			
		||||
{
 | 
			
		||||
    private $_config = null;
 | 
			
		||||
    
 | 
			
		||||
    public function run(Magallanes_Config $config)
 | 
			
		||||
    {
 | 
			
		||||
        $this->_config = $config;
 | 
			
		||||
        $this->_rsync();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private function _rsync()
 | 
			
		||||
    {
 | 
			
		||||
        $config = $this->_config->getEnvironment();
 | 
			
		||||
        $user = $config['user'];
 | 
			
		||||
        $to = $config['deploy-to'];
 | 
			
		||||
        $from = $config['deploy-from'];
 | 
			
		||||
 | 
			
		||||
        foreach ($config['hosts'] as $host) {            
 | 
			
		||||
            Magallanes_Console::output(PHP_TAB . 'Deploying to: ' . $host);
 | 
			
		||||
            $result = Magallanes_Task_Deploy_Rsync::exec($user, $host, $from, $to);
 | 
			
		||||
            if ($result == 0) {
 | 
			
		||||
                Magallanes_Console::output(PHP_TAB . 'OK' . PHP_EOL);
 | 
			
		||||
            } else {
 | 
			
		||||
                Magallanes_Console::output(PHP_TAB . 'FAIL' . PHP_EOL);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Magallanes/Task/Deploy/Rsync.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Magallanes/Task/Deploy/Rsync.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Task_Deploy_Rsync
 | 
			
		||||
{
 | 
			
		||||
    public static function exec($user, $host, $from, $to)
 | 
			
		||||
    {
 | 
			
		||||
        $output = array();
 | 
			
		||||
        $command = 'rsync -avz ' . $from . ' ' . $user . '@' . $host . ':' . $to;
 | 
			
		||||
        exec($command . ' 2>&1 ', $command, $result);
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								Magallanes/Task/Update.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Magallanes/Task/Update.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Magallanes_Task_Update
 | 
			
		||||
{
 | 
			
		||||
    private $_config = null;
 | 
			
		||||
    
 | 
			
		||||
    public function run(Magallanes_Config $config)
 | 
			
		||||
    {
 | 
			
		||||
        $csmConfig = $config->getCSM();
 | 
			
		||||
        $csm = new Magallanes_Task_CSM_Git;
 | 
			
		||||
        $csm->run($csmConfig['url']);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								bin/mage
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								bin/mage
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
SCRIPT=$(readlink -f $0)
 | 
			
		||||
DIR=$(dirname $SCRIPT)
 | 
			
		||||
PHP_BIN=$(which php) 
 | 
			
		||||
 | 
			
		||||
$PHP_BIN -d safe_mode=Off -f $DIR/mage.php -- $@
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								bin/mage.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								bin/mage.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
<?php
 | 
			
		||||
# mage deploy to:production
 | 
			
		||||
# mage update
 | 
			
		||||
# mage up
 | 
			
		||||
# mage task:init to:production 
 | 
			
		||||
# mage run:full-deployment to:production
 | 
			
		||||
 | 
			
		||||
# full-deployment = update, deploy to:production
 | 
			
		||||
 | 
			
		||||
$baseDir = dirname(dirname(__FILE__));
 | 
			
		||||
 | 
			
		||||
require_once $baseDir . '/Magallanes/Autoload.php';
 | 
			
		||||
spl_autoload_register(array('Magallanes_Autoload', 'autoload'));
 | 
			
		||||
 | 
			
		||||
Magallanes_Console::output('Begining Magallanes' . PHP_EOL . PHP_EOL);
 | 
			
		||||
 | 
			
		||||
$console = new Magallanes_Console;
 | 
			
		||||
$console->setArgs($argv);
 | 
			
		||||
$console->parse();
 | 
			
		||||
 | 
			
		||||
$console->run();
 | 
			
		||||
							
								
								
									
										2
									
								
								docs/example-config/.mage/csm.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								docs/example-config/.mage/csm.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
type: git
 | 
			
		||||
url: git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git
 | 
			
		||||
							
								
								
									
										8
									
								
								docs/example-config/.mage/environment/production.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								docs/example-config/.mage/environment/production.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#production
 | 
			
		||||
user: prod_example
 | 
			
		||||
deploy-from: application
 | 
			
		||||
deploy-to: /var/www/vhosts/example.com/www
 | 
			
		||||
hosts:
 | 
			
		||||
  - s01.example.com
 | 
			
		||||
  - s02.example.com
 | 
			
		||||
  - s03.example.com
 | 
			
		||||
							
								
								
									
										6
									
								
								docs/example-config/.mage/environment/staging.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								docs/example-config/.mage/environment/staging.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
#staging
 | 
			
		||||
user: stg_example
 | 
			
		||||
deploy-from: application
 | 
			
		||||
deploy-to: /var/www/vhosts/example.com/staging
 | 
			
		||||
hosts:
 | 
			
		||||
  - staging.example.com
 | 
			
		||||
							
								
								
									
										1
									
								
								docs/example-config/.mage/global.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								docs/example-config/.mage/global.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
backupdir: /tmp
 | 
			
		||||
							
								
								
									
										8
									
								
								docs/example-config/.mage/tasks/MyTask.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								docs/example-config/.mage/tasks/MyTask.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
<?php
 | 
			
		||||
class MyTask
 | 
			
		||||
{
 | 
			
		||||
    public function run()
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user