mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-27 09:48:55 +02:00
Verify if environment is defined. Verify that rollback has release point.
This commit is contained in:
+40
-34
@@ -7,13 +7,13 @@ class Mage_Config
|
||||
private $_general = null;
|
||||
private $_host = null;
|
||||
private $_releaseId = null;
|
||||
|
||||
|
||||
public function loadEnvironment($environment)
|
||||
{
|
||||
if (($environment != '') && file_exists('.mage/config/environment/' . $environment . '.yml')) {
|
||||
$this->_environment = spyc_load_file('.mage/config/environment/' . $environment . '.yml');
|
||||
$this->_environmentName = $environment;
|
||||
|
||||
|
||||
// Create temporal directory for clone
|
||||
if (isset($this->_environment['deployment']['source']) && is_array($this->_environment['deployment']['source'])) {
|
||||
if (trim($this->_environment['deployment']['source']['temporal']) == '') {
|
||||
@@ -22,34 +22,40 @@ class Mage_Config
|
||||
$newTemporal = rtrim($this->_environment['deployment']['source']['temporal'], '/')
|
||||
. '/' . md5(microtime()) . '/';
|
||||
$this->_environment['deployment']['source']['temporal'] = $newTemporal;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (($environment != '') && !file_exists('.mage/config/environment/' . $environment . '.yml')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function loadSCM()
|
||||
{
|
||||
if (file_exists('.mage/config/scm.yml')) {
|
||||
$this->_scm = spyc_load_file('.mage/config/scm.yml');
|
||||
$this->_scm = spyc_load_file('.mage/config/scm.yml');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function loadGeneral()
|
||||
{
|
||||
if (file_exists('.mage/config/general.yml')) {
|
||||
$this->_general = spyc_load_file('.mage/config/general.yml');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getEnvironment()
|
||||
{
|
||||
return $this->_environment;
|
||||
}
|
||||
|
||||
|
||||
public function getEnvironmentName()
|
||||
{
|
||||
return $this->_environmentName;
|
||||
}
|
||||
|
||||
|
||||
public function getSCM()
|
||||
{
|
||||
return $this->_scm;
|
||||
@@ -59,64 +65,64 @@ class Mage_Config
|
||||
{
|
||||
return $this->_global;
|
||||
}
|
||||
|
||||
|
||||
public function getHosts()
|
||||
{
|
||||
$config = $this->getEnvironment();
|
||||
$hosts = array();
|
||||
|
||||
|
||||
if (isset($config['hosts'])) {
|
||||
if (is_array($config['hosts'])) {
|
||||
$hosts = (array) $config['hosts'];
|
||||
$hosts = (array) $config['hosts'];
|
||||
} else if (is_string($config['hosts'])) {
|
||||
$fileContent = fopen($config['hosts'], 'r');
|
||||
while (($host = fgets($fileContent)) == true) {
|
||||
$host = trim($host);
|
||||
if ($host != '') {
|
||||
$hosts[] = $host;
|
||||
$hosts[] = $host;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->_host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getHostName()
|
||||
{
|
||||
$info = explode(':', $this->_host);
|
||||
return $info[0];
|
||||
}
|
||||
|
||||
|
||||
public function getHostPort()
|
||||
{
|
||||
$info = explode(':', $this->_host);
|
||||
$info[] = $this->deployment('port', '22');
|
||||
return $info[1];
|
||||
}
|
||||
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
|
||||
public function setReleaseId($id)
|
||||
{
|
||||
$this->_releaseId = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getReleaseId()
|
||||
{
|
||||
return $this->_releaseId;
|
||||
}
|
||||
|
||||
|
||||
public function getTasks($stage = 'on-deploy')
|
||||
{
|
||||
switch ($stage) {
|
||||
@@ -124,24 +130,24 @@ class Mage_Config
|
||||
$type = 'tasks';
|
||||
$stage = 'pre-deploy';
|
||||
break;
|
||||
|
||||
|
||||
case 'post-deploy':
|
||||
$type = 'tasks';
|
||||
$stage = 'post-deploy';
|
||||
break;
|
||||
|
||||
|
||||
case 'post-release':
|
||||
$type = 'releases';
|
||||
$stage = 'post-release';
|
||||
break;
|
||||
|
||||
|
||||
case 'on-deploy':
|
||||
default:
|
||||
$type = 'tasks';
|
||||
$stage = 'on-deploy';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$tasks = array();
|
||||
$config = $this->getEnvironment();
|
||||
|
||||
@@ -151,17 +157,17 @@ class Mage_Config
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
|
||||
public function getConfig($host = false)
|
||||
{
|
||||
$taskConfig = array();
|
||||
$taskConfig['deploy'] = $this->getEnvironment();
|
||||
$taskConfig['deploy']['host'] = $host;
|
||||
$taskConfig['scm'] = $this->getSCM();
|
||||
|
||||
|
||||
unset($taskConfig['deploy']['tasks']);
|
||||
unset($taskConfig['deploy']['hosts']);
|
||||
|
||||
|
||||
return $taskConfig;
|
||||
}
|
||||
|
||||
@@ -170,7 +176,7 @@ class Mage_Config
|
||||
$this->_environment['deployment']['from'] = $from;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function deployment($option, $default = false)
|
||||
{
|
||||
$options = $this->getEnvironment();
|
||||
@@ -178,13 +184,13 @@ class Mage_Config
|
||||
if (is_array($default) && ($options['deployment'][$option] == '')) {
|
||||
return $default;
|
||||
} else {
|
||||
return $options['deployment'][$option];
|
||||
return $options['deployment'][$option];
|
||||
}
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function release($option, $default = false)
|
||||
{
|
||||
$options = $this->getEnvironment();
|
||||
@@ -198,7 +204,7 @@ class Mage_Config
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function scm($option, $default = false)
|
||||
{
|
||||
$options = $this->_scm;
|
||||
@@ -213,7 +219,7 @@ class Mage_Config
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function general($option, $default = false)
|
||||
{
|
||||
$options = $this->_general;
|
||||
@@ -227,7 +233,7 @@ class Mage_Config
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function mail($option, $default = false)
|
||||
{
|
||||
$options = $this->_general;
|
||||
|
||||
Reference in New Issue
Block a user