mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-20 06:25:04 +02:00
Changes on configuration.
Preparation for Post Release tasks.
This commit is contained in:
parent
1349f296c0
commit
9c03ae6bed
|
@ -40,28 +40,36 @@ class Mage_Config
|
|||
return $hosts;
|
||||
}
|
||||
|
||||
public function getTasks($type = 'tasks')
|
||||
public function getTasks($stage = 'on-deploy')
|
||||
{
|
||||
switch ($type) {
|
||||
case 'pre':
|
||||
$type = 'pre-tasks';
|
||||
switch ($stage) {
|
||||
case 'pre-deploy':
|
||||
$type = 'tasks';
|
||||
$stage = 'pre-deploy';
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
$type = 'post-tasks';
|
||||
case 'post-deploy':
|
||||
$type = 'tasks';
|
||||
$stage = 'post-deploy';
|
||||
break;
|
||||
|
||||
case 'tasks':
|
||||
case 'post-release':
|
||||
$type = 'releases';
|
||||
$stage = 'post-release';
|
||||
break;
|
||||
|
||||
case 'on-deploy':
|
||||
default:
|
||||
$type = 'tasks';
|
||||
$stage = 'on-deploy';
|
||||
break;
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
$config = $this->getEnvironment();
|
||||
|
||||
if (isset($config[$type])) {
|
||||
$tasks = (array) $config[$type];
|
||||
if (isset($config[$type]) && isset($config[$type][$stage])) {
|
||||
$tasks = (array) $config[$type][$stage];
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
|
|
|
@ -13,15 +13,17 @@ class Mage_Task_Add
|
|||
Mage_Console::output('<light_red>Error!!</light_red> Already exists an environment called <dark_gray>' . $environmentName . '</dark_gray>', 1, 2);
|
||||
} else {
|
||||
$baseConfig = '#' . $environmentName . PHP_EOL
|
||||
. 'user: dummy' . PHP_EOL
|
||||
. 'deploy-from: ./' . PHP_EOL
|
||||
. 'deploy-to: /var/www/vhosts/example.com/www' . PHP_EOL
|
||||
. 'rsync-excludes:' . PHP_EOL
|
||||
. 'deployment:'
|
||||
. ' user: dummy' . PHP_EOL
|
||||
. ' from: ./' . PHP_EOL
|
||||
. ' to: /var/www/vhosts/example.com/www' . PHP_EOL
|
||||
. ' excludes:' . PHP_EOL
|
||||
. 'hosts:' . PHP_EOL
|
||||
. 'pre-tasks:' . PHP_EOL
|
||||
. 'tasks:' . PHP_EOL
|
||||
. ' - deployment/rsync' . PHP_EOL
|
||||
. 'post-tasks:' . PHP_EOL;
|
||||
. 'tasks:'
|
||||
. ' pre-deploy:' . PHP_EOL
|
||||
. ' on-deploy:' . PHP_EOL
|
||||
. ' - deployment/rsync' . PHP_EOL
|
||||
. ' post-deploy:' . PHP_EOL;
|
||||
$result = file_put_contents($environmentConfigFile, $baseConfig);
|
||||
|
||||
if ($result) {
|
||||
|
|
|
@ -25,14 +25,14 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
|||
);
|
||||
|
||||
// Look for User Excludes
|
||||
if (isset($this->_config['deploy']['rsync-excludes'])) {
|
||||
$userExcludes = (array) $this->_config['deploy']['rsync-excludes'];
|
||||
if (isset($this->_config['deploy']['deployment']['excludes'])) {
|
||||
$userExcludes = (array) $this->_config['deploy']['deployment']['excludes'];
|
||||
} else {
|
||||
$userExcludes = array();
|
||||
}
|
||||
|
||||
// If we are working with releases
|
||||
$deployToDirectory = $this->_config['deploy']['deploy-to'];
|
||||
$deployToDirectory = $this->_config['deploy']['deployment']['to'];
|
||||
if (isset($this->_config['deploy']['releases']['enabled'])) {
|
||||
if ($this->_config['deploy']['releases']['enabled'] == 'true') {
|
||||
if (isset($this->_config['deploy']['releases']['directory'])) {
|
||||
|
@ -41,7 +41,7 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
|||
$releasesDirectory = 'releases';
|
||||
}
|
||||
|
||||
$deployToDirectory = rtrim($this->_config['deploy']['deploy-to'], '/')
|
||||
$deployToDirectory = rtrim($this->_config['deploy']['deployment']['to'], '/')
|
||||
. '/' . $releasesDirectory
|
||||
. '/' . $this->_config['deploy']['releases']['_id'];
|
||||
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config['deploy']['releases']['_id']);
|
||||
|
@ -50,8 +50,8 @@ class Mage_Task_BuiltIn_Deployment_Rsync
|
|||
|
||||
$command = 'rsync -avz '
|
||||
. $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
|
||||
. $this->_config['deploy']['deploy-from'] . ' '
|
||||
. $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory;
|
||||
. $this->_config['deploy']['deployment']['from'] . ' '
|
||||
. $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory;
|
||||
|
||||
$result = $this->_runLocalCommand($command);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class Mage_Task_Deploy
|
|||
$this->_config = $config;
|
||||
|
||||
// Run Pre-Deployment Tasks
|
||||
$this->_runNonDeploymentTasks('pre', $config);
|
||||
$this->_runNonDeploymentTasks('pre-deploy', $config, 'Pre-Deployment');
|
||||
|
||||
// Run Tasks for Deployment
|
||||
$hosts = $config->getHosts();
|
||||
|
@ -60,6 +60,8 @@ class Mage_Task_Deploy
|
|||
}
|
||||
}
|
||||
|
||||
// Run Post-Deployment Tasks
|
||||
|
||||
if ($completedTasks == $tasks) {
|
||||
$tasksColor = 'green';
|
||||
} else {
|
||||
|
@ -72,18 +74,18 @@ class Mage_Task_Deploy
|
|||
}
|
||||
|
||||
// Run Post-Deployment Tasks
|
||||
$this->_runNonDeploymentTasks('post', $config);
|
||||
$this->_runNonDeploymentTasks('post-deploy', $config, 'Post-Deployment');
|
||||
}
|
||||
|
||||
private function _runNonDeploymentTasks($type, Mage_Config $config)
|
||||
private function _runNonDeploymentTasks($stage, Mage_Config $config, $title)
|
||||
{
|
||||
$tasksToRun = $config->getTasks($type);
|
||||
$tasksToRun = $config->getTasks($stage);
|
||||
|
||||
if (count($tasksToRun) == 0) {
|
||||
Mage_Console::output('<dark_gray>No </dark_gray><light_cyan>' . ucfirst($type) . '-Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
|
||||
Mage_Console::output('<dark_gray>No </dark_gray><light_cyan>' . $title . '</light_cyan> <dark_gray>tasks defined.</dark_gray>', 1, 3);
|
||||
|
||||
} else {
|
||||
Mage_Console::output('Starting <dark_gray>' . ucfirst($type) . '-Deployment</dark_gray> tasks:');
|
||||
Mage_Console::output('Starting <dark_gray>' . $title . '</dark_gray> tasks:');
|
||||
|
||||
$taskConfig = $config->getConfig();
|
||||
$tasks = 0;
|
||||
|
@ -94,7 +96,7 @@ class Mage_Task_Deploy
|
|||
$task = Mage_Task_Factory::get($taskName, $taskConfig);
|
||||
$task->init();
|
||||
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
|
||||
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, 0);
|
||||
$result = $task->run();
|
||||
|
||||
if ($result == true) {
|
||||
|
@ -111,7 +113,7 @@ class Mage_Task_Deploy
|
|||
$tasksColor = 'red';
|
||||
}
|
||||
|
||||
Mage_Console::output('Finished <dark_gray>' . ucfirst($type) . '-Deployment</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
Mage_Console::output('Finished <dark_gray>' . $title . '</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ abstract class Mage_Task_TaskAbstract
|
|||
protected final function _runRemoteCommand($command)
|
||||
{
|
||||
$localCommand = 'ssh '
|
||||
. $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ' '
|
||||
. '"cd ' . $this->_config['deploy']['deploy-to'] . ' && '
|
||||
. $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ' '
|
||||
. '"cd ' . $this->_config['deploy']['deployment']['to'] . ' && '
|
||||
. $command . '"';
|
||||
|
||||
return $this->_runLocalCommand($localCommand);
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
#production
|
||||
user: root
|
||||
deploy-from: ./
|
||||
deploy-to: /var/www/vhosts/example.com/www
|
||||
deployment:
|
||||
user: root
|
||||
from: ./
|
||||
to: /var/www/vhosts/example.com/www
|
||||
excludes:
|
||||
- application/data/cache/twig/*
|
||||
releases:
|
||||
enabled: true
|
||||
symlink: current
|
||||
directory: releases
|
||||
tasks:
|
||||
hosts:
|
||||
- s01.example.com
|
||||
- s02.example.com
|
||||
- s03.example.com
|
||||
- s05.example.com
|
||||
rsync-excludes:
|
||||
- application/data/cache/twig/*
|
||||
pre-tasks:
|
||||
- scm/update
|
||||
tasks:
|
||||
- deployment/rsync
|
||||
- privileges
|
||||
#post-tasks:
|
||||
pre-deploy:
|
||||
- scm/update
|
||||
on-deploy:
|
||||
- deployment/rsync
|
||||
- privileges
|
||||
#post-deploy:
|
|
@ -1,11 +1,14 @@
|
|||
#staging
|
||||
user: stg_example
|
||||
deploy-from: application
|
||||
deploy-to: /var/www/vhosts/example.com/staging
|
||||
deployment:
|
||||
user: stg_user
|
||||
from: ./
|
||||
to: /var/www/vhosts/example.com/staging
|
||||
hosts:
|
||||
- staging.example.com
|
||||
pre-tasks:
|
||||
- scm/update
|
||||
tasks:
|
||||
- deployment/rsync
|
||||
- privileges
|
||||
pre-deploy:
|
||||
- scm/update
|
||||
on-deploy:
|
||||
- deployment/rsync
|
||||
- privileges
|
||||
#post-deploy:
|
Loading…
Reference in a new issue