mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-08-25 21:00:18 +02:00
New reorder of classes and configuration. New instantiation of Tasks.
This commit is contained in:
parent
3caa3d7313
commit
b161220e69
5
.buildpath
Normal file
5
.buildpath
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<buildpath>
|
||||
<buildpathentry kind="src" path=""/>
|
||||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
|
||||
</buildpath>
|
22
.project
Normal file
22
.project
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Magallanes</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.php.core.PHPNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
3
.settings/org.eclipse.php.core.prefs
Normal file
3
.settings/org.eclipse.php.core.prefs
Normal file
@ -0,0 +1,3 @@
|
||||
#Mon Nov 21 16:37:20 UYST 2011
|
||||
eclipse.preferences.version=1
|
||||
include_path=0;/Magallanes
|
@ -1,26 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
class Magallanes_Autoload
|
||||
class Mage_Autoload
|
||||
{
|
||||
public static function autoload($className)
|
||||
{
|
51
Mage/Config.php
Normal file
51
Mage/Config.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
class Mage_Config
|
||||
{
|
||||
private $_environment = null;
|
||||
private $_scm = null;
|
||||
|
||||
public function loadEnvironment($environment)
|
||||
{
|
||||
$this->_environment = yaml_parse_file('.mage/config/environment/' . $environment . '.yaml');
|
||||
}
|
||||
|
||||
public function loadSCM()
|
||||
{
|
||||
$this->_scm = yaml_parse_file('.mage/config/scm.yaml');
|
||||
}
|
||||
|
||||
public function getEnvironment()
|
||||
{
|
||||
return $this->_environment;
|
||||
}
|
||||
|
||||
public function getSCM()
|
||||
{
|
||||
return $this->_scm;
|
||||
}
|
||||
|
||||
public function getHosts()
|
||||
{
|
||||
$config = $this->getEnvironment();
|
||||
return $config['hosts'];
|
||||
}
|
||||
|
||||
public function getTasks()
|
||||
{
|
||||
$config = $this->getEnvironment();
|
||||
return $config['tasks'];
|
||||
}
|
||||
|
||||
public function getConfig($host)
|
||||
{
|
||||
$taskConfig = array();
|
||||
$taskConfig['deploy'] = $this->getEnvironment();
|
||||
$taskConfig['deploy']['host'] = $host;
|
||||
$taskConfig['scm'] = $this->getSCM();
|
||||
|
||||
unset($taskConfig['deploy']['tasks']);
|
||||
unset($taskConfig['deploy']['hosts']);
|
||||
|
||||
return $taskConfig;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
class Magallanes_Console
|
||||
class Mage_Console
|
||||
{
|
||||
private $_args;
|
||||
private $_action;
|
||||
@ -42,23 +42,33 @@ class Magallanes_Console
|
||||
echo $message;
|
||||
}
|
||||
|
||||
public static function executeCommand($command)
|
||||
{
|
||||
ob_start();
|
||||
system($command . ' 2>&1', $return);
|
||||
$log = ob_get_clean();
|
||||
|
||||
return !$return;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$config = new Magallanes_Config;
|
||||
$config = new Mage_Config;
|
||||
$config->loadEnvironment($this->getEnvironment());
|
||||
$config->loadSCM();
|
||||
|
||||
switch ($this->getAction()) {
|
||||
case 'deploy':
|
||||
$config->loadEnvironment($this->getEnvironment());
|
||||
$task = new Magallanes_Task_Deploy;
|
||||
$task = new Mage_Task_Deploy;
|
||||
$task->run($config);
|
||||
break;
|
||||
|
||||
case 'update';
|
||||
$config->loadCSM();
|
||||
$task = new Magallanes_Task_Update;
|
||||
$task = new Mage_Task_Update;
|
||||
$task->run($config);
|
||||
break;
|
||||
}
|
||||
|
||||
$task->run($config);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
class Magallanes_Console_Colors {
|
||||
class Mage_Console_Colors {
|
||||
private static $foreground_colors = array ();
|
||||
private static $background_colors = array ();
|
||||
|
28
Mage/Task/BuiltIn/Deployment/Rsync.php
Normal file
28
Mage/Task/BuiltIn/Deployment/Rsync.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
class Mage_Task_BuiltIn_Deployment_Rsync
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'Rsync (built-in)';
|
||||
}
|
||||
|
||||
public function run($config)
|
||||
{
|
||||
$ignores = array(
|
||||
'--exclude .git',
|
||||
'--exclude .svn',
|
||||
'--exclude .mage',
|
||||
'--exclude .gitignore'
|
||||
);
|
||||
|
||||
$command = 'rsync -avz '
|
||||
. implode(' ', $ignores) .' '
|
||||
. $config['deploy']['deploy-from'] . ' '
|
||||
. $config['deploy']['user'] . '@' . $config['deploy']['host'] . ':' . $config['deploy']['deploy-to'];
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
26
Mage/Task/BuiltIn/Scm/Update.php
Normal file
26
Mage/Task/BuiltIn/Scm/Update.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
class Mage_Task_BuiltIn_Scm_Update
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'SCM Update (built-in)';
|
||||
}
|
||||
|
||||
public function run($config)
|
||||
{
|
||||
switch ($config['scm']['type']) {
|
||||
case 'git':
|
||||
$command = 'git pull';
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
$command = 'svn update';
|
||||
break;
|
||||
}
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
37
Mage/Task/Deploy.php
Normal file
37
Mage/Task/Deploy.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
class Mage_Task_Deploy
|
||||
{
|
||||
private $_config = null;
|
||||
|
||||
public function run(Mage_Config $config)
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
foreach ($config->getHosts() as $host)
|
||||
{
|
||||
$taskConfig = $config->getConfig($host);
|
||||
$tasks = 0;
|
||||
$completedTasks = 0;
|
||||
|
||||
Mage_Console::output(PHP_TAB . 'Deploying to ' . $host . PHP_EOL);
|
||||
|
||||
foreach ($config->getTasks() as $taskName) {
|
||||
$tasks++;
|
||||
$task = Mage_Task_Factory::get($taskName);
|
||||
|
||||
Mage_Console::output(PHP_TAB . PHP_TAB . 'Running ' . $task->getName() . ' ... ');
|
||||
$result = $task->run($taskConfig);
|
||||
|
||||
if ($result == true) {
|
||||
Mage_Console::output(PHP_TAB . 'OK' . PHP_EOL);
|
||||
$completedTasks++;
|
||||
} else {
|
||||
Mage_Console::output(PHP_TAB . 'FAIL' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
Mage_Console::output(PHP_TAB . 'Deployment to ' . $host . ' compted: ' . $completedTasks . '/' . $tasks . ' tasks done.' . PHP_EOL . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
16
Mage/Task/Factory.php
Normal file
16
Mage/Task/Factory.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
class Mage_Task_Factory
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $taskName
|
||||
* @return Mage_Task_TaskAbstract
|
||||
*/
|
||||
public static function get($taskName)
|
||||
{
|
||||
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
|
||||
$className = 'Mage_Task_BuiltIn_' . $taskName;
|
||||
return new $className;
|
||||
}
|
||||
}
|
17
Mage/Task/TaskAbstract.php
Normal file
17
Mage/Task/TaskAbstract.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
abstract class Mage_Task_TaskAbstract
|
||||
{
|
||||
public abstract function getName();
|
||||
|
||||
public abstract function run($config);
|
||||
|
||||
protected function _runLocalCommand($command)
|
||||
{
|
||||
return Mage_Console::executeCommand($command);
|
||||
}
|
||||
|
||||
protected function _runRemoteCommand($command)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
16
bin/mage.php
16
bin/mage.php
@ -1,4 +1,12 @@
|
||||
<?php
|
||||
# mage install
|
||||
# mage init
|
||||
|
||||
# mage config add environment [production]
|
||||
# mage config add host prod_example@s05.example.com to:[production]
|
||||
# mage config git git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git
|
||||
# mage config svn svn://example.com/repo
|
||||
|
||||
# mage deploy to:production
|
||||
# mage update
|
||||
# mage up
|
||||
@ -9,12 +17,12 @@
|
||||
|
||||
$baseDir = dirname(dirname(__FILE__));
|
||||
|
||||
require_once $baseDir . '/Magallanes/Autoload.php';
|
||||
spl_autoload_register(array('Magallanes_Autoload', 'autoload'));
|
||||
require_once $baseDir . '/Mage/Autoload.php';
|
||||
spl_autoload_register(array('Mage_Autoload', 'autoload'));
|
||||
|
||||
Magallanes_Console::output('Begining Magallanes' . PHP_EOL . PHP_EOL);
|
||||
Mage_Console::output('Begining Magallanes' . PHP_EOL . PHP_EOL);
|
||||
|
||||
$console = new Magallanes_Console;
|
||||
$console = new Mage_Console;
|
||||
$console->setArgs($argv);
|
||||
$console->parse();
|
||||
|
||||
|
11
docs/example-config/.mage/config/environment/production.yaml
Normal file
11
docs/example-config/.mage/config/environment/production.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
#production
|
||||
user: root
|
||||
deploy-from: ./
|
||||
deploy-to: /var/www/vhosts/example.com/www
|
||||
hosts:
|
||||
- s01.example.com
|
||||
- s02.example.com
|
||||
- s03.example.com
|
||||
tasks:
|
||||
- scm/update
|
||||
- deployment/rsync
|
@ -0,0 +1,9 @@
|
||||
#staging
|
||||
user: stg_example
|
||||
deploy-from: application
|
||||
deploy-to: /var/www/vhosts/example.com/staging
|
||||
hosts:
|
||||
- staging.example.com
|
||||
tasks:
|
||||
- scm/update
|
||||
- deployment/rsync
|
1
docs/example-config/.mage/logs/.gitignore
vendored
Normal file
1
docs/example-config/.mage/logs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
log-*
|
Loading…
Reference in New Issue
Block a user