mirror of https://github.com/hauke68/Magallanes
Andrs Montaez
13 years ago
23 changed files with 257 additions and 108 deletions
@ -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> |
@ -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> |
@ -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) |
||||
{ |
@ -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_Colors { |
||||
class Mage_Console_Colors { |
||||
private static $foreground_colors = array (); |
||||
private static $background_colors = array (); |
||||
|
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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) |
||||
{ |
||||
|
||||
} |
||||
} |
@ -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 |
Loading…
Reference in new issue