|
@@ -14,7 +14,14 @@ use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
class Release extends Command
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @var string Nombre del archivo de log.
|
|
|
+ */
|
|
|
private $_running_log;
|
|
|
+ /**
|
|
|
+ * @var array Contiene las variables que se utilizar en la ejecucion del ansible.
|
|
|
+ */
|
|
|
+ private $_ansible_vars;
|
|
|
/**
|
|
|
* @var string Contiene el password del usuario root.
|
|
|
*/
|
|
@@ -59,11 +66,12 @@ class Release extends Command
|
|
|
{
|
|
|
parent::__construct($name);
|
|
|
$this->_running_log = "running.log";
|
|
|
- $this->_mysql_root_pass = "235r2342gtfsw";
|
|
|
$this->_mysql_user = "iksop";
|
|
|
$this->_mysql_pass = "235r2342gtfsw";
|
|
|
+ $this->_mysql_root_pass = "235r2342gtfsw";
|
|
|
$this->_domain_behind = "flowdat.com";
|
|
|
$this->_modules = array();
|
|
|
+ $this->_ansible_vars = array();
|
|
|
$this->_modules_all = array(
|
|
|
"base" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -71,7 +79,8 @@ class Release extends Command
|
|
|
'VIRTUAL_HOST' => '',
|
|
|
'HTTPS_METHOD' => 'nohttps',
|
|
|
),
|
|
|
- 'OAUTH' => false
|
|
|
+ 'OAUTH' => false,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
),
|
|
|
"ftth" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -79,7 +88,8 @@ class Release extends Command
|
|
|
'VIRTUAL_HOST' => '',
|
|
|
'HTTPS_METHOD' => 'nohttps',
|
|
|
),
|
|
|
- 'OAUTH' => true
|
|
|
+ 'OAUTH' => true,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
),
|
|
|
"mapas" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -87,7 +97,8 @@ class Release extends Command
|
|
|
'VIRTUAL_HOST' => '',
|
|
|
'HTTPS_METHOD' => 'nohttps',
|
|
|
),
|
|
|
- 'OAUTH' => true
|
|
|
+ 'OAUTH' => true,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
),
|
|
|
"radius" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -95,7 +106,8 @@ class Release extends Command
|
|
|
'VIRTUAL_HOST' => '',
|
|
|
'HTTPS_METHOD' => 'nohttps',
|
|
|
),
|
|
|
- 'OAUTH' => true
|
|
|
+ 'OAUTH' => true,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
),
|
|
|
"stats" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -103,7 +115,8 @@ class Release extends Command
|
|
|
'VIRTUAL_HOST' => '',
|
|
|
'HTTPS_METHOD' => 'nohttps',
|
|
|
),
|
|
|
- 'OAUTH' => true
|
|
|
+ 'OAUTH' => true,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
),
|
|
|
"grafana" => array(
|
|
|
'HOST_ENV' => true,
|
|
@@ -122,7 +135,8 @@ class Release extends Command
|
|
|
),
|
|
|
"extra" => array(
|
|
|
'HOST_ENV' => false,
|
|
|
- 'OAUTH' => false
|
|
|
+ 'OAUTH' => false,
|
|
|
+ 'MODULE_INSTALL' => true
|
|
|
)
|
|
|
);
|
|
|
}
|
|
@@ -154,14 +168,24 @@ class Release extends Command
|
|
|
->addOption('extra-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
->addOption('host-ip', null, InputOption::VALUE_REQUIRED, 'Ip of the runnning host to be added to the /etc/hosts file, eventually', "127.0.1.1")
|
|
|
->addOption('domain', null, InputOption::VALUE_REQUIRED, 'Domain where the flowdat will be installed', "flowdat.com")
|
|
|
+ ->addOption('modules', null, InputOption::VALUE_REQUIRED, 'List of modules to install separated by coma.', "")
|
|
|
+ ->addOption('inventory', null, InputOption::VALUE_REQUIRED, 'Write inventory.ini by default.', true)
|
|
|
->addOption('docker-tag', null, InputOption::VALUE_REQUIRED, 'Docker tag to be used', "latest");
|
|
|
}
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
try {
|
|
|
- if (!$input->hasOption("modules")) {
|
|
|
- $input->setOption("modules", implode(",", array_keys($this->_modules_all)));
|
|
|
+ if (!$input->hasOption("modules") && strlen($input->getOption("modules")) == 0) {
|
|
|
+ // seteo todos los modulos a instalar por defecto
|
|
|
+ $modules = "";
|
|
|
+ foreach ($this->_modules_all as $name => $value) {
|
|
|
+ if (isset($value['MODULE_INSTALL']) && $value['MODULE_INSTALL']) {
|
|
|
+ $modules = $modules . $name . ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $modules = substr($modules, 0, strlen($modules) - 1);
|
|
|
+ $input->setOption("modules", $modules);
|
|
|
}
|
|
|
//##############################################
|
|
|
// TODO: quitar este linea
|
|
@@ -182,6 +206,8 @@ class Release extends Command
|
|
|
$this->_domain = $input->getOption("domain");
|
|
|
$docker_tag = $input->getOption("docker-tag");
|
|
|
|
|
|
+ $this->_ansible_vars["DOMAIN"] = $this->_domain;
|
|
|
+
|
|
|
$dObj = new DevOps\FileSystem($dir);
|
|
|
$dObj->dirExists()->realpath();
|
|
|
$this->_dObj = $dObj;
|
|
@@ -200,15 +226,18 @@ class Release extends Command
|
|
|
$this->writeHostEnv();
|
|
|
// escribo los archivo oauth
|
|
|
$this->writeOAUTH();
|
|
|
-
|
|
|
- $dObj->file('install.yml')->content(
|
|
|
- yaml::dump(array(
|
|
|
- "install_dir" => realpath($dir),
|
|
|
- 'docker_apps' => array('base', /*'stats', 'ftth', 'mapas'*/),
|
|
|
- 'domain' => $this->_domain,
|
|
|
- )
|
|
|
- )
|
|
|
- );
|
|
|
+ // escribo un archivo con variables para ansible
|
|
|
+ $this->writeEnvVariables();
|
|
|
+
|
|
|
+// $dObj->file('install.yml')->content(
|
|
|
+// yaml::dump(array(
|
|
|
+// "install_dir" => realpath($dir),
|
|
|
+// 'docker_apps' => explode(",", $this->_modules),
|
|
|
+// //array('base', /*'stats', 'ftth', 'mapas'*/),
|
|
|
+// 'domain' => $this->_domain,
|
|
|
+// )
|
|
|
+// )
|
|
|
+// );
|
|
|
|
|
|
$dObj->file('ansible.cfg')->content(
|
|
|
"[defaults]\n" .
|
|
@@ -415,6 +444,7 @@ class Release extends Command
|
|
|
->addService($module)
|
|
|
->image($registry . "fd3/$module:" . $version)
|
|
|
->build("./extra/mysql")
|
|
|
+ ->addEnv_file($module . "." . $host_env_file)
|
|
|
->addVolumes("./mysql/", "/var/lib/mysql/");
|
|
|
$this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
|
|
|
array(
|
|
@@ -615,6 +645,9 @@ class Release extends Command
|
|
|
//// ->addEnviroment("HTTPS_METHOD", "nohttps")
|
|
|
//// ;
|
|
|
$this->_dObj->file("docker-compose.yml")->content($composer->render());
|
|
|
+ // escribo un archivo inventory.ini por defecto para no tener que lanzar los docker
|
|
|
+ $this->writeInventory($composer);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -700,11 +733,14 @@ class Release extends Command
|
|
|
*/
|
|
|
private function writeOAUTH()
|
|
|
{
|
|
|
+ $oautModules = "";
|
|
|
foreach ($this->_modules as $nameApp => $app) {
|
|
|
if (isset($app['OAUTH']) && $app['OAUTH']) {
|
|
|
$this->_dObj->file($nameApp . ".oauth.env")->content("");
|
|
|
+ $oautModules = $oautModules . $nameApp . ",";
|
|
|
}
|
|
|
}
|
|
|
+ $this->_ansible_vars["MODULES_INSTALL"] = substr($oautModules, 0, strlen($oautModules) - 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -712,8 +748,6 @@ class Release extends Command
|
|
|
*/
|
|
|
private function writeHostEnv()
|
|
|
{
|
|
|
-// $oauth_client = "1_3323sq6urn8kwccg8s4ok848ggwwgkw4c08wsc4cwkc08osocc";
|
|
|
-// $oauth_client_secret = "5w7gx6ptdoo4g8cwwo88o8gowosgco84sso08ssow0osg88g8k";
|
|
|
$hostEnvConfig = $this->getHostEnv();
|
|
|
$env_content = "";
|
|
|
foreach ($hostEnvConfig as $var => $val) {
|
|
@@ -796,4 +830,33 @@ class Release extends Command
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Crea el archivo con las variables para ejecutar el ansible.
|
|
|
+ */
|
|
|
+ private function writeEnvVariables()
|
|
|
+ {
|
|
|
+ $tmp = "";
|
|
|
+ foreach ($this->_ansible_vars as $key => $value) {
|
|
|
+ $tmp = $tmp . "$key=$value\n";
|
|
|
+ }
|
|
|
+ $this->_dObj->file(str_replace(".log", ".env", $this->_running_log))
|
|
|
+ ->content($tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Crea el archivo con las variables para ejecutar el ansible.
|
|
|
+ */
|
|
|
+ private function writeInventory(FileFormat2 $composer)
|
|
|
+ {
|
|
|
+ $tmp = "";
|
|
|
+ $all = "[all]\n";
|
|
|
+ foreach ($composer->getServices() as $key => $value) {
|
|
|
+ $tmp .= "[$key]\n";
|
|
|
+ $tmp .= $this->_domain . "_" . $key . "_1\n\n";
|
|
|
+ $all .= $this->_domain . "_" . $key . "_1\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->_dObj->file("inventory111.ini")->content($tmp . $all);
|
|
|
+ }
|
|
|
}
|