|
@@ -1,831 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace FD3;
|
|
|
-
|
|
|
-use Docker\Composer\FileFormat;
|
|
|
-use Docker\Composer\NetworkConfig;
|
|
|
-use Docker\Composer\ServiceNotFoundException;
|
|
|
-use FD3\Services\Amqp;
|
|
|
-use FD3\Services\Api;
|
|
|
-use FD3\Services\Base;
|
|
|
-use FD3\Services\Base_log;
|
|
|
-use FD3\Services\Cablemodem;
|
|
|
-use FD3\Services\Cablemodem_cmd;
|
|
|
-use FD3\Services\Cablemodem_task;
|
|
|
-use FD3\Services\Dhcp;
|
|
|
-use FD3\Services\Dhcp_task;
|
|
|
-use FD3\Services\Freeradius;
|
|
|
-use FD3\Services\Ftth;
|
|
|
-use FD3\Services\Ftth_cmd;
|
|
|
-use FD3\Services\Ftth_task;
|
|
|
-use FD3\Services\Genieacs_cwmp;
|
|
|
-use FD3\Services\Genieacs_fs;
|
|
|
-use FD3\Services\Genieacs_gui;
|
|
|
-use FD3\Services\Genieacs_nbi;
|
|
|
-use FD3\Services\Geoserver;
|
|
|
-use FD3\Services\Jsendpoint;
|
|
|
-use FD3\Services\Jsonep_mongo;
|
|
|
-use FD3\Services\Jsonep_mysql;
|
|
|
-use FD3\Services\Kea;
|
|
|
-use FD3\Services\Mongodb;
|
|
|
-use FD3\Services\Mysql;
|
|
|
-use FD3\Services\Nginx;
|
|
|
-use FD3\Services\Pma;
|
|
|
-use FD3\Services\Radius;
|
|
|
-use FD3\Services\Redis;
|
|
|
-use FD3\Services\Stats;
|
|
|
-use FD3\Services\Stats_cmd;
|
|
|
-use FD3\Services\Statsd;
|
|
|
-use FD3\Services\Supervisord;
|
|
|
-use FD3\Services\Swagger;
|
|
|
-use FD3\Services\Tftp;
|
|
|
-use Symfony\Component\Console\Command\Command;
|
|
|
-use Symfony\Component\Console\Exception\LogicException;
|
|
|
-use Symfony\Component\Console\Input\InputArgument;
|
|
|
-use Symfony\Component\Console\Input\InputInterface;
|
|
|
-use Symfony\Component\Console\Input\InputOption;
|
|
|
-use Symfony\Component\Console\Output\OutputInterface;
|
|
|
-use Symfony\Component\Console\Question\ConfirmationQuestion;
|
|
|
-use Symfony\Component\Yaml\Yaml;
|
|
|
-
|
|
|
-class Release extends Command
|
|
|
-{
|
|
|
- /**
|
|
|
- * @var string Nombre del archivo de log.
|
|
|
- */
|
|
|
- protected $_running_log;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene la politica de restart de los dockers.
|
|
|
- */
|
|
|
- public $_docker_restart_default;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var array Contiene las variables que se utilizar en la ejecucion del ansible.
|
|
|
- */
|
|
|
- protected $_ansible_vars;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene el password del usuario root.
|
|
|
- */
|
|
|
- public $_mysql_root_pass;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene el usuario de base de datos.
|
|
|
- */
|
|
|
- public $_mysql_user;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene la contrasena del usuario de base de datos.
|
|
|
- */
|
|
|
- public $_mysql_pass;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var DevOps\FileSystem Me permite crear archivos.
|
|
|
- */
|
|
|
- protected $_dObj;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene el dominio.
|
|
|
- */
|
|
|
- protected $_domain;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Contiene el nombre del cliente.
|
|
|
- */
|
|
|
- protected $_client;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var array Contiene todos los modulos para la instalacion.
|
|
|
- */
|
|
|
- public $_modules_all;
|
|
|
- /**
|
|
|
- * @var array Contiene todos los modulos extras para la instalacion.
|
|
|
- */
|
|
|
- protected $_modules_extra;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var array Contiene la configuracion de los modulos.
|
|
|
- */
|
|
|
- protected $_modules;
|
|
|
- /**
|
|
|
- * @var array Contiene los usuarios que van a poder acceder al sistema.
|
|
|
- */
|
|
|
- protected $_user_system;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string $directory Directorio de instalacion
|
|
|
- */
|
|
|
- protected $directory;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var boolean $_use_nginx_links Para indicar si se crean los links nginx entre los modulos
|
|
|
- */
|
|
|
- protected $_use_nginx_links;
|
|
|
- /**
|
|
|
- * Add links nginx
|
|
|
- */
|
|
|
- protected $_add_nginx_links;
|
|
|
- /**
|
|
|
- * @var int Max connection for mysql
|
|
|
- */
|
|
|
- public $_mysql_max_connections;
|
|
|
- /**
|
|
|
- * @var string Running env file
|
|
|
- */
|
|
|
- public $_running_env;
|
|
|
- /**
|
|
|
- * @var string Host env file
|
|
|
- */
|
|
|
- public $_host_env;
|
|
|
- /**
|
|
|
- * @var string IP configuration
|
|
|
- */
|
|
|
- public $_network_ip;
|
|
|
- /**
|
|
|
- * @var string Network name
|
|
|
- */
|
|
|
- public $_network_name;
|
|
|
-
|
|
|
- /**
|
|
|
- * Constructor.
|
|
|
- *
|
|
|
- * @param string|null $name The name of the command; passing null means it must be set in configure()
|
|
|
- *
|
|
|
- * @throws LogicException When the command name is empty
|
|
|
- */
|
|
|
- public function __construct($name = null)
|
|
|
- {
|
|
|
- parent::__construct($name);
|
|
|
- $this->_running_log = "running.log";
|
|
|
- $this->_mysql_user = "iksop";
|
|
|
- $this->_mysql_pass = "235r2342gtfsw";
|
|
|
- $this->_mysql_root_pass = "235r2342gtfsw";
|
|
|
- $this->_mysql_max_connections = 10000;
|
|
|
- $this->_running_env = "running.env";
|
|
|
- $this->_host_env = "host.env";
|
|
|
- $this->_docker_restart_default = "on-failure:10";
|
|
|
- $this->_network_name = "flowdat3";
|
|
|
- $this->_user_system = ['users' =>
|
|
|
- [
|
|
|
- ['user' => 'admin', 'password' => 'admin', 'tenancy' => 1, 'email' => 'soporte@interlink.com.ar', 'extra' => '--super-admin '],
|
|
|
- ['user' => 'iksop', 'password' => 'gran5pe', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => ''],
|
|
|
- ['user' => 'interno', 'password' => 'gran5pe1nterno', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => '']
|
|
|
- ]];
|
|
|
- $this->_modules = array();
|
|
|
- $this->_ansible_vars = array();
|
|
|
- $this->_modules_all = $this->getModules();
|
|
|
- $this->_add_nginx_links = false;
|
|
|
- }
|
|
|
-
|
|
|
- private function getModules()
|
|
|
- {
|
|
|
- $dir = __DIR__ . "/Services/";
|
|
|
- $files = scandir($dir);
|
|
|
- $modulesRead = [];
|
|
|
- $resp = [];
|
|
|
- foreach ($files as $file) {
|
|
|
- if (is_file($dir . $file) && $file != "InitialService.php") {
|
|
|
- $class = "FD3\\Services\\" . explode(".", $file)[0];
|
|
|
- $object = new $class();
|
|
|
- array_push($modulesRead, $object);
|
|
|
- }
|
|
|
- }
|
|
|
- // obtengo los modulos requeridos por obligacion
|
|
|
- foreach ($modulesRead as $key => $mod) {
|
|
|
- if ($mod->isRequired()) {
|
|
|
- $resp[$mod->getModuleName()] = $mod->getConfig();
|
|
|
- unset($modulesRead[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
- // obtengo los modulos sin dependencias
|
|
|
- foreach ($modulesRead as $key => $mod) {
|
|
|
- if (count($mod->getDepends()) == 0) {
|
|
|
- $resp[$mod->getModuleName()] = $mod->getConfig();
|
|
|
- unset($modulesRead[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
- // obtengo el resto de los modulos
|
|
|
- foreach ($modulesRead as $mod) {
|
|
|
- $resp[$mod->getModuleName()] = $mod->getConfig();
|
|
|
- }
|
|
|
- return $resp;
|
|
|
- }
|
|
|
-
|
|
|
- protected function configure()
|
|
|
- {
|
|
|
- $this
|
|
|
- ->setName('make:install')
|
|
|
- ->setDescription('Create a new install.')
|
|
|
- ->setHelp('This command allows you to create a new installation...')
|
|
|
- ->addArgument('dir', InputArgument::REQUIRED, 'The directory where to create the installation.')
|
|
|
- ->addOption('base-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app Base', "git@gitlab.com:interlink-sa/flowdat3/modules/base.git")
|
|
|
- ->addOption('base-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Base app', "master")
|
|
|
- ->addOption('base-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('ftth-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app FTTH', "git@gitlab.com:interlink-sa/flowdat3/modules/ftth.git")
|
|
|
- ->addOption('ftth-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Ftth ', "master")
|
|
|
- ->addOption('ftth-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('radius-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app Radius', "git@gitlab.com:interlink-sa/flowdat3/modules/radius.git")
|
|
|
- ->addOption('radius-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the radius app', "master")
|
|
|
- ->addOption('radius-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('stats-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app Stats', "git@gitlab.com:interlink-sa/flowdat3/modules/stats.git")
|
|
|
- ->addOption('stats-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Stats app', "master")
|
|
|
- ->addOption('stats-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('cablemodem-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app Cablemodem', "git@gitlab.com:interlink-sa/flowdat3/modules/cablemodem.git")
|
|
|
- ->addOption('cablemodem-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Cablemodem files and apps', "master")
|
|
|
- ->addOption('cablemodem-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('dhcp-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app DHCP', "git@gitlab.com:interlink-sa/flowdat3/modules/dhcp.git")
|
|
|
- ->addOption('dhcp-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the DHCP files and apps', "master")
|
|
|
- ->addOption('dhcp-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('extra-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for Extra repository', "git@gitlab.com:interlink-sa/flowdat3/modules/extra.git")
|
|
|
- ->addOption('extra-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Extra files and apps', "master")
|
|
|
- ->addOption('extra-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
|
|
|
- ->addOption('kea-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for KEA', "git@gitlab.com:interlink-sa/flowdat3/vendors/kea.git")
|
|
|
- ->addOption('kea-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone KEA files and apps', "master")
|
|
|
- ->addOption('kea-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.net")
|
|
|
- ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client name, if is not provided uses, the dirname of the installation', false)
|
|
|
- ->addOption('modules', null, InputOption::VALUE_REQUIRED, 'List of modules to install separated by coma.', "all")
|
|
|
- ->addOption('inventory', null, InputOption::VALUE_REQUIRED, 'Write inventory.ini by default.', true)
|
|
|
- ->addOption('docker-tag', null, InputOption::VALUE_REQUIRED, 'Docker tag to be used. Ej. v0.1.1', "latest")
|
|
|
- ->addOption('all-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone all app. Ej. 0.1.1', "")
|
|
|
- ->addOption('general-version', null, InputOption::VALUE_REQUIRED, 'Set options all-ref and docker-tag with this value. Ej. 0.1.1', "")
|
|
|
- ->addOption('add-nginx-links', null, InputOption::VALUE_NONE, 'Add NGINX links between dockers', null)
|
|
|
- ->addOption('ip-network_begin', null, InputOption::VALUE_REQUIRED, 'Flowdat ip network configuration', "172.172.172.0");
|
|
|
- }
|
|
|
-
|
|
|
- protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
- {
|
|
|
- try {
|
|
|
- if (strlen(trim($input->getOption("general-version"))) > 0) {
|
|
|
- $input->setOption('all-ref', 'v' . $input->getOption('general-version'));
|
|
|
- $input->setOption('docker-tag', $input->getOption('general-version'));
|
|
|
- }
|
|
|
- if (strlen(trim($input->getOption("all-ref"))) > 0) {
|
|
|
- $input->setOption('base-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('ftth-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('radius-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('stats-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('cablemodem-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('dhcp-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('extra-ref', $input->getOption('all-ref'));
|
|
|
- $input->setOption('kea-ref', $input->getOption('all-ref'));
|
|
|
- }
|
|
|
- if (strtolower($input->getOption("modules")) == "all") {
|
|
|
- // seteo todos los modulos a instalar por defecto
|
|
|
- $modules = $this->selectInstallModules($input, $output);
|
|
|
- $input->setOption("modules", $modules);
|
|
|
- }
|
|
|
- $this->AddModules(explode(",", $input->getOption("modules")));
|
|
|
- $this->directory = $input->getArgument('dir');
|
|
|
- if (!is_dir($this->directory)) {
|
|
|
- mkdir($this->directory, 0777, true);
|
|
|
- }
|
|
|
- if (file_exists($this->directory . "/" . $this->_running_log)) {
|
|
|
- $helper = $this->getHelper('question');
|
|
|
- $question = new ConfirmationQuestion('The ' . realpath($this->directory) . "/" . $this->_running_log . ' file exist. Read file (Y) or take parameters (N)? (Y/n)', true);
|
|
|
- if ($helper->ask($input, $output, $question)) {
|
|
|
- $this->setParametersFormFile($input);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->_domain = $input->getOption("domain");
|
|
|
- $this->_client = $input->getOption("client");
|
|
|
- $this->_network_ip = $input->getOption("ip-network_begin");
|
|
|
-
|
|
|
- if (!$this->_client) {
|
|
|
- $this->_client = basename(realpath($this->directory));
|
|
|
- }
|
|
|
-
|
|
|
- $docker_tag = $input->getOption("docker-tag");
|
|
|
-
|
|
|
- $internal_user_id = 2;
|
|
|
-
|
|
|
- $this->_ansible_vars["DOMAIN"] = $this->_domain;
|
|
|
- $this->_ansible_vars["CLIENT"] = $this->_client;
|
|
|
- $this->_ansible_vars["CMD_USERNAME"] = $this->_user_system['users'][$internal_user_id]['user'];
|
|
|
- $this->_ansible_vars["CMD_PASSWORD"] = $this->_user_system['users'][$internal_user_id]['password'];
|
|
|
- $this->_ansible_vars["ENV_LIST"] = "prod,dev,test";
|
|
|
- $this->_ansible_vars["API_CIDR"] = "172.20.0.0/24";
|
|
|
- $this->_ansible_vars["IK_SUBRED"] = "200.50.160.0/21";
|
|
|
- $this->_ansible_vars["MYSQL_ROOT_PASSWORD"] = $this->_mysql_root_pass;
|
|
|
-
|
|
|
- $this->_add_nginx_links = (boolean)$input->getOption('add-nginx-links');
|
|
|
-
|
|
|
- $dObj = new DevOps\FileSystem(realpath($this->directory));
|
|
|
- $dObj->dirExists()->realpath();
|
|
|
- $this->_dObj = $dObj;
|
|
|
-
|
|
|
- // agrego las opciones del input a la configuracion _modues
|
|
|
- $this->addConfigOptions($input);
|
|
|
- // creo el archivo de log de como se ejecuto
|
|
|
- $this->createFileRunning($input, $output);
|
|
|
- // cargo las fuentes a clonar
|
|
|
- $this->createGitClone($input);
|
|
|
- // creo el archivo docker-compose.yml
|
|
|
- $this->getDockerComposer($docker_tag, "host.env", "docker.infra.flowdat.com/");
|
|
|
- // escribo el archivo de host
|
|
|
- $this->writeHostsFile($input->getOption("host-ip"));
|
|
|
- // escribo el archivo con las variables de entorno
|
|
|
- $this->writeHostEnv();
|
|
|
- // escribo los archivo oauth
|
|
|
- $this->writeOAUTH();
|
|
|
- // escribo un archivo con variables para ansible
|
|
|
- $this->writeEnvVariables();
|
|
|
- // escribo un archivo con los usuarios del sistema
|
|
|
- $this->writeUserSystem();
|
|
|
-
|
|
|
- $dObj->file('install.yml')->content(
|
|
|
- yaml::dump(array(
|
|
|
- "install_dir" => realpath($this->directory),
|
|
|
- 'docker_apps' => "base," . implode(",", $this->_ansible_vars),
|
|
|
- 'domain' => $this->_domain,
|
|
|
- )
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- $dObj->file('ansible.cfg')->content(
|
|
|
- "[defaults]\n" .
|
|
|
- "inventory=inventory.ini\n"
|
|
|
- );
|
|
|
-
|
|
|
- // copio el playbook
|
|
|
- copy(getcwd() . "/playbook.yml", $dObj->dirExists()->realpath()->getPath() . "/playbook.yml");
|
|
|
- // copio el script de base de datos inicial
|
|
|
- copy(getcwd() . "/mysql_scripts.sql", $dObj->dirExists()->realpath()->getPath() . "/mysql_scripts.sql");
|
|
|
- // copio el archivo que contiene los usuarios del sistema
|
|
|
- copy(getcwd() . "/user_system.json", $dObj->dirExists()->realpath()->getPath() . "/user_system.json");
|
|
|
- // copio script mysql schema freeradius
|
|
|
- copy(getcwd() . "/mysql/freeradius/schema.sql", $dObj->dirExists()->realpath()->getPath() . "/freeradius_schema.sql");
|
|
|
- // copio el docker-compose.service
|
|
|
- copy(getcwd() . "/docker-compose.service", $dObj->dirExists()->realpath()->getPath() . "/docker-compose.service");
|
|
|
- } finally {
|
|
|
- $this->_dObj = null;
|
|
|
- $this->_modules = null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $module Name of module.
|
|
|
- * @return bool Return TRUE if depends exists.
|
|
|
- */
|
|
|
- public function needInstallModule($module)
|
|
|
- {
|
|
|
- foreach ($this->_modules as $key => $value) {
|
|
|
- if ($key == $module) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param array $modules All modules selected.
|
|
|
- * @param array $depends All modules to depends.
|
|
|
- * @return bool Return TRUE if depends exists.
|
|
|
- */
|
|
|
- public function checkDepends($modules, $depends)
|
|
|
- {
|
|
|
- if ($depends) {
|
|
|
- foreach ($depends as $depend) {
|
|
|
- if (in_array($depend, $modules)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param InputInterface $input InputInterface
|
|
|
- * @param OutputInterface $output OutputInterface
|
|
|
- * @return string Return all modules selected.
|
|
|
- */
|
|
|
- public function selectInstallModules(InputInterface $input, OutputInterface $output)
|
|
|
- {
|
|
|
- $modules = [];
|
|
|
- $output->writeln("Seleccione los módulos que desea instalar:");
|
|
|
- foreach ($this->_modules_all as $name => $value) {
|
|
|
- if (isset($value['REQUIRED']) && $value['REQUIRED']) {
|
|
|
- $modules[] = $name;
|
|
|
- $output->writeln("Se instala el modulo $name, por ser una dependencia obligatoria");
|
|
|
- } else {
|
|
|
- if ($this->checkDepends($modules, $value['DEPENDS'])) {
|
|
|
- $modules[] = $name;
|
|
|
- $value['REQUIRED'] = true;
|
|
|
- $output->writeln("Se instala el modulo $name, por tener las siguientes dependencias " .
|
|
|
- implode(",", $value['DEPENDS']));
|
|
|
- } else {
|
|
|
- $helper = $this->getHelper('question');
|
|
|
- $question = new ConfirmationQuestion((isset($value['HELP']) ? ($value['HELP'] . ". ") : "") .
|
|
|
- strtoupper($name) . "? (Y/n) ");
|
|
|
- if ($helper->ask($input, $output, $question)) {
|
|
|
- $modules [] = $name;
|
|
|
- $value['REQUIRED'] = true;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $modules = implode(",", $modules);
|
|
|
- return $modules;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return array Retorna un array con los host como key el dominio como valor.
|
|
|
- */
|
|
|
- function getHostEnv()
|
|
|
- {
|
|
|
- $resp = array();
|
|
|
- foreach ($this->_modules as $key => $values) {
|
|
|
- if ($values['HOST_ENV']) {
|
|
|
- $resp ["HOST_" . strtoupper($key)] = $this->getDomain($key);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return $resp;
|
|
|
- }
|
|
|
-
|
|
|
- function getHostConfig($config_ip)
|
|
|
- {
|
|
|
- $resp = array();
|
|
|
- foreach ($this->_modules as $key => $values) {
|
|
|
- if ($values['HOST_ENV']) {
|
|
|
- $resp [$this->getDomain($key)] = $config_ip;
|
|
|
- }
|
|
|
- }
|
|
|
- return $resp;
|
|
|
- }
|
|
|
-
|
|
|
- function getDockerComposer($version = "latest", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/")
|
|
|
- {
|
|
|
- $composer = new FileFormat("../", "3.7");
|
|
|
- $this->registerVolumes($composer);
|
|
|
- $nc = new NetworkConfig();
|
|
|
- $nc->addDriver()->addSubnetGateway("172.172.172.0/24");
|
|
|
- $composer->getNetwork()->addDriver($this->_network_name)->addConfig($this->_network_name, $nc);
|
|
|
-
|
|
|
- $base_vars = array(
|
|
|
- "version" => $version,
|
|
|
- "host_env_file" => $host_env_file,
|
|
|
- "registry" => $registry);
|
|
|
-
|
|
|
- $ip = explode(".", $this->_network_ip);
|
|
|
- array_pop($ip);
|
|
|
- $ip = implode(".", $ip);
|
|
|
- foreach ($this->_modules_all as $module => $env) {
|
|
|
- if (strpos($module, "genieacs") !== false) {
|
|
|
- $module = str_replace("-", "_", $module);
|
|
|
- }
|
|
|
- $class = "FD3\\Services\\" . ucfirst($module);
|
|
|
- $object = new $class();
|
|
|
- $object
|
|
|
- ->setRelease($this)
|
|
|
- ->setComposer($composer)
|
|
|
- ->setConfigVar($base_vars)
|
|
|
- ->setIp($ip)
|
|
|
- ->setProduction(false)
|
|
|
- ->add();
|
|
|
- }
|
|
|
-
|
|
|
- $this->checkLinkDependencyDockerCompose($composer);
|
|
|
- $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);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea un array con la configuracion de los modulos.
|
|
|
- * @param InputInterface $input Contiene el input.
|
|
|
- */
|
|
|
- protected function addConfigOptions(InputInterface $input)
|
|
|
- {
|
|
|
- foreach ($this->_modules as $key => $values) {
|
|
|
- if ($input->hasOption($key . "-repo") &&
|
|
|
- $input->hasOption($key . "-ref") &&
|
|
|
- $input->hasOption($key . "-build")
|
|
|
- ) {
|
|
|
- $this->_modules[$key]['repo'] = $input->getOption($key . "-repo");
|
|
|
- $this->_modules[$key]['ref'] = $input->getOption($key . "-ref");
|
|
|
- $this->_modules[$key]['build'] = $input->getOption($key . "-build");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea un array con las direcciones de a clonar.
|
|
|
- */
|
|
|
- protected function createGitClone(InputInterface $input)
|
|
|
- {
|
|
|
- $clone = array();
|
|
|
- $modules = array_keys($this->_modules);
|
|
|
- foreach ($modules as $name) {
|
|
|
- if (isset($this->_modules[$name]["repo"]) &&
|
|
|
- isset($this->_modules[$name]["ref"])) {
|
|
|
- $clone[$name] = array(
|
|
|
- 'url' => $this->_modules[$name]["repo"],
|
|
|
- 'branch' => $this->_modules[$name]["ref"]
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- $name = 'extra';
|
|
|
- $clone[$name] = array(
|
|
|
- 'url' => $input->getOption($name . "-repo"),
|
|
|
- 'branch' => $input->getOption($name . "-ref")
|
|
|
- );
|
|
|
- $this->_dObj->file("git.ini")->writeIniConfig($clone);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea un archivo conlos parametros con los que se corrio el script.
|
|
|
- * @param InputInterface $input Contiene el input
|
|
|
- * @param OutputInterface $output Contiene el output
|
|
|
- */
|
|
|
- protected function createFileRunning(InputInterface $input, OutputInterface $output)
|
|
|
- {
|
|
|
- $file = array();
|
|
|
- $file ["Running"] = array("date" => gmdate('Y-m-d h:i:s'));
|
|
|
- $file ["Arguments"] = $input->getArguments();
|
|
|
- $file ["Options"] = $input->getOptions();
|
|
|
- $output->writeln("Writing " . $this->_dObj->getPath() . "/" . $this->_running_log);
|
|
|
- $this->_dObj->file($this->_running_log)->writeIniConfig($file);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $module Contiene el nombre del modulo.
|
|
|
- * @param array $extras Contiene variables de entorno extra.
|
|
|
- * @return string|array Retorna un array con los datos de virtual host.
|
|
|
- */
|
|
|
- function getEnviromentVarialbes($module, $extras = array())
|
|
|
- {
|
|
|
- $env = "";
|
|
|
- if ($module != null) {
|
|
|
- foreach ($this->_modules as $nameApp => $app) {
|
|
|
- if (isset($app['VAR_ENV']) && $nameApp == $module) {
|
|
|
- foreach ($app['VAR_ENV'] as $key => $value) {
|
|
|
- if ($key == 'VIRTUAL_HOST') {
|
|
|
- $env .= "VIRTUAL_HOST=" . $this->getDomain($module) . "\n";
|
|
|
- } else if ($key == 'PMA_ABSOLUTE_URI') {
|
|
|
- $env .= "PMA_ABSOLUTE_URI=" . $this->getDomain("pma") . "\n";
|
|
|
- } else {
|
|
|
- $env .= $key . "=" . $value . "\n";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($extras as $key => $value) {
|
|
|
- $env .= $key . "=" . $value . "\n";
|
|
|
- }
|
|
|
- return $env;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea el archivo modulo.oauth.env
|
|
|
- */
|
|
|
- protected function writeOAUTH()
|
|
|
- {
|
|
|
- $oautModules = "";
|
|
|
- foreach ($this->_modules as $nameApp => $app) {
|
|
|
- if (isset($app['OAUTH']) && $app['OAUTH']) {
|
|
|
- if (!file_exists(realpath($this->directory) . $nameApp . ".oauth.env")) {
|
|
|
- $this->_dObj->file($nameApp . ".oauth.env")->content("");
|
|
|
- $oautModules = $oautModules . $nameApp . ",";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $this->_ansible_vars["MODULES_INSTALL"] = substr($oautModules, 0, strlen($oautModules) - 1);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea el archivo host.env
|
|
|
- */
|
|
|
- protected function writeHostEnv()
|
|
|
- {
|
|
|
- $hostEnvConfig = $this->getHostEnv();
|
|
|
- $env_content = "";
|
|
|
- foreach ($hostEnvConfig as $var => $val) {
|
|
|
- $env_content .= $var . "=" . $val . "\n";
|
|
|
- }
|
|
|
- $this->_dObj->file('host.env')->content($env_content);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea el archivo hostsDile
|
|
|
- * @param string $config_ip Contiene la ip.
|
|
|
- */
|
|
|
- protected function writeHostsFile($config_ip)
|
|
|
- {
|
|
|
- $hostConfig = $this->getHostConfig($config_ip);
|
|
|
- $hostfile_content = "";
|
|
|
- foreach ($hostConfig as $host => $ip) {
|
|
|
- $hostfile_content .= $ip . "\t" . $host . "\n";
|
|
|
- }
|
|
|
- $this->_dObj->file("hostsFile")->content($hostfile_content);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea un archivo con las variables de entorno particulares del modulo.
|
|
|
- * @param string $name Contiene el nombre del archivo.
|
|
|
- * @param string $module Contiene el nombre del modulo.
|
|
|
- * @param array $extras Contiene un array con las variables extras.
|
|
|
- */
|
|
|
- public function writeVariablesEnviroment($name, $module = null, $extras = array())
|
|
|
- {
|
|
|
- $this->_dObj->file($name)->content(
|
|
|
- $this->getEnviromentVarialbes($module, $extras));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Funcion que agrega el build de acuerdo en la configuracion.
|
|
|
- * @param string $module Contiene el nombre del modulo.
|
|
|
- * @param FileFormat $composer Contiene el objeto FileFormat.
|
|
|
- */
|
|
|
- public function addBuild($module, FileFormat $composer)
|
|
|
- {
|
|
|
- if (isset($this->_modules[$module]['build']) &&
|
|
|
- filter_var($this->_modules[$module]['build'], FILTER_VALIDATE_BOOLEAN)) {
|
|
|
- try {
|
|
|
- $composer->service($module)->build("./$module/");
|
|
|
- } catch (ServiceNotFoundException $ignore) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Funcion que setea los valores que se lean desde el archivo running.log.
|
|
|
- * Solo se reemplazan las opciones.
|
|
|
- * Si se toman los argumentos puede pisar el directorio de destino y a lo mejor se quiere replicar la instalacion en
|
|
|
- * otro directorio.
|
|
|
- * @param InputInterface $input contiene el input
|
|
|
- */
|
|
|
- protected function setParametersFormFile(InputInterface $input)
|
|
|
- {
|
|
|
- $parameters = parse_ini_file($input->getArgument('dir') . "/" . $this->_running_log, true);
|
|
|
- foreach ($parameters["Options"] as $key => $value) {
|
|
|
- $input->setOption($key, $value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $module Contiene el nombre del modulo.
|
|
|
- * @return string Retorna el dominio para el modulo.
|
|
|
- */
|
|
|
- public function getDomain($module)
|
|
|
- {
|
|
|
- return $module . "." . $this->_client . "." . $this->_domain;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param array $modules Contiene los modulos a implementar
|
|
|
- */
|
|
|
- protected function AddModules($modules)
|
|
|
- {
|
|
|
- foreach ($modules as $value) {
|
|
|
- if (array_key_exists($value, $this->_modules_all)) {
|
|
|
- $this->_modules[$value] = $this->_modules_all[$value];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea el archivo con las variables para ejecutar el ansible.
|
|
|
- */
|
|
|
- protected 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 los usuarios del sistema para que lea el ansible.
|
|
|
- */
|
|
|
- protected function writeUserSystem()
|
|
|
- {
|
|
|
- $this->_dObj->file("user_system.json")
|
|
|
- ->content(json_encode($this->_user_system));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Crea el archivo con las variables para ejecutar el ansible.
|
|
|
- */
|
|
|
- protected function writeInventory(FileFormat $composer)
|
|
|
- {
|
|
|
- $tmp = "";
|
|
|
- $all = "[all]\n";
|
|
|
- $prefix = basename(realpath($this->directory));
|
|
|
- foreach ($composer->getServices() as $key => $value) {
|
|
|
- $tmp .= "[$key]\n";
|
|
|
- $tmp .= $prefix . "_" . $key . "_1\n\n";
|
|
|
- $all .= $prefix . "_" . $key . "_1\n";
|
|
|
- }
|
|
|
-
|
|
|
- $this->_dObj->file("inventory.ini")->content($tmp . $all);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Funcion que agrega links nginx a los modulos principales (para instalacion dev)
|
|
|
- * @param string $module Contiene el nombre del modulo.
|
|
|
- * @param FileFormat $composer Contiene el objeto FileFormat.
|
|
|
- * @throws ServiceNotFoundException
|
|
|
- */
|
|
|
- public function addNginxLinks($module, FileFormat $composer)
|
|
|
- {
|
|
|
- if ($this->_add_nginx_links) {
|
|
|
- if (in_array((new Base())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Base())->getModuleName()));
|
|
|
- }
|
|
|
- if (in_array((new Ftth())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Ftth())->getModuleName()));
|
|
|
- }
|
|
|
- if (in_array((new Cablemodem())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Cablemodem())->getModuleName()));
|
|
|
- }
|
|
|
- if (in_array((new Stats())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Stats())->getModuleName()));
|
|
|
- }
|
|
|
- if (in_array((new Dhcp())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Dhcp())->getModuleName()));
|
|
|
- }
|
|
|
- if (in_array((new Radius())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->service($module)->addLinks((new Nginx())->getModuleName(), $this->getDomain((new Radius())->getModuleName()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function registerVolumes(FileFormat $composer)
|
|
|
- {
|
|
|
- if (in_array((new Pma())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Pma::PMA_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Swagger())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Swagger::SWAGGER_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Base())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Base::BASE_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Cablemodem())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Cablemodem::CABLEMODEM_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Dhcp())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Dhcp::DHCP_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Ftth())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Ftth::FTTH_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Radius())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Radius::RADIUS_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Stats())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Stats::STATS_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- if (in_array((new Api())->getModuleName(), $this->_modules_all)) {
|
|
|
- $composer->getVolumes()->addVolumen(Api::API_SOCKET_VOLUMEN, 'local');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param FileFormat $composer Contains composer.
|
|
|
- * @return FileFormat Return composer with corrected link.
|
|
|
- */
|
|
|
- private function checkLinkDependencyDockerCompose(FileFormat $composer)
|
|
|
- {
|
|
|
- foreach ($composer->getServices() as $key => $value) {
|
|
|
- // every service in docker compose
|
|
|
- if ($value->getLinks()) {
|
|
|
- $arrtmp = [];
|
|
|
- foreach ($value->getLinks() as $link) {
|
|
|
- // every link in service in docker compose
|
|
|
- $found = false;
|
|
|
- foreach ($this->_modules as $module => $env) {
|
|
|
- // every module selected for install
|
|
|
- if (strpos($module, "genieacs") !== false) {
|
|
|
- $moduleg = str_replace("-", "_", $module);
|
|
|
- } else {
|
|
|
- $moduleg = "";
|
|
|
- }
|
|
|
- //remove nginx: to compare because nginx is always TRUE
|
|
|
- $linkTmp = str_replace("nginx:", "", $link);
|
|
|
- if (strpos($linkTmp, $module) === false) {
|
|
|
- } else if ($moduleg != "" && strpos($linkTmp, $moduleg) === false) {
|
|
|
- } else {
|
|
|
- $found = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if ($found) {
|
|
|
- // add link only if is in list of modules install
|
|
|
- $arrtmp[] = $link;
|
|
|
- }
|
|
|
- }
|
|
|
- $value->setLinks($arrtmp);
|
|
|
- }
|
|
|
- }
|
|
|
- return $composer;
|
|
|
- }
|
|
|
-}
|