1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384 |
- <?php
- namespace FD3;
- use Docker\Composer\ServiceNotFoundException;
- use function GuzzleHttp\default_user_agent;
- use League\Flysystem\File;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Docker\Composer\FileFormat2;
- use Symfony\Component\Console\Exception\LogicException;
- use Symfony\Component\Console\Question\ConfirmationQuestion;
- use Symfony\Component\Yaml\Yaml;
- class Release extends Command
- {
- /**
- * @var string Nombre del archivo de log.
- */
- private $_running_log;
- /**
- * @var string Contiene la politica de restart de los dockers.
- */
- private $_docker_restart_default;
- /**
- * @var array Contiene las variables que se utilizar en la ejecucion del ansible.
- */
- private $_ansible_vars;
- /**
- * @var string Contiene el password del usuario root.
- */
- private $_mysql_root_pass;
- /**
- * @var string Contiene el usuario de base de datos.
- */
- private $_mysql_user;
- /**
- * @var string Contiene la contrasena del usuario de base de datos.
- */
- private $_mysql_pass;
- /**
- * @var DevOps\FileSystem Me permite crear archivos.
- */
- private $_dObj;
- /**
- * @var string Contiene el dominio.
- */
- private $_domain;
- /**
- * @var string Contiene el nombre del cliente.
- */
- private $_client;
- /**
- * @var array Contiene todos los modulos para la instalacion.
- */
- private $_modules_all;
- /**
- * @var array Contiene la configuracion de los modulos.
- */
- private $_modules;
- /**
- * @var array Contiene los usuarios que van a poder acceder al sistema.
- */
- private $_user_system;
- /**
- * @var string $directory Directorio de instalacion
- */
- private $directory;
-
- /**
- * @var boolean $_use_nginx_links Para indicar si se crean los links nginx entre los modulos
- */
- private $_use_nginx_links;
- /**
- * 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->_docker_restart_default = "on-failure:10";
- $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 = array(
- "base" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- 'AMQP_KEY' => 'base'
- ),
- 'OAUTH' => false,
- 'MODULE_INSTALL' => true
- ),
- "ftth" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- 'AMQP_KEY' => 'ftth'
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "mapas" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "radius" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "stats" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- 'AMQP_KEY' => 'stats'
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "cablemodem" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- 'AMQP_KEY' => 'cablemodem'
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "dhcp" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- ),
- 'OAUTH' => true,
- 'MODULE_INSTALL' => true
- ),
- "grafana" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- ),
- 'OAUTH' => false,
- 'MODULE_INSTALL' => true
- ),
- "pma" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- ),
- 'OAUTH' => false,
- 'MODULE_INSTALL' => false
- ),
- "extra" => array(
- 'HOST_ENV' => false,
- 'OAUTH' => false,
- 'MODULE_INSTALL' => true
- ),
- "kea" => array(
- 'HOST_ENV' => false,
- 'OAUTH' => false,
- 'MODULE_INSTALL' => true
- ),
- "geoserver" => array(
- 'HOST_ENV' => true,
- "VAR_ENV" => array(
- 'VIRTUAL_HOST' => '',
- 'HTTPS_METHOD' => 'nohttps',
- ),
- 'OAUTH' => false,
- 'MODULE_INSTALL' => true
- ),
- );
- $this->_add_nginx_links = false;
- }
- 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 fot the app Base', "git@bitbucket.org:ikflowdat/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 fot the app FTTH', "git@bitbucket.org:ikflowdat/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('mapas-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Mapas', "git@bitbucket.org:ikflowdat/mapas.git")
- ->addOption('mapas-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Mapas app', "master")
- ->addOption('mapas-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
- ->addOption('radius-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app radius', "git@bitbucket.org:ikflowdat/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 fot the app Base', "git@bitbucket.org:ikflowdat/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@bitbucket.org:ikflowdat/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@bitbucket.org:ikflowdat/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 fot the app Base', "git@bitbucket.org:ikflowdat/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@bitbucket.org:ikflowdat/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.com")
- ->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_REQUIRED, 'Add NGINX links between dockers', false);
- }
- 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('mapas-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 = "";
- 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);
- }
- $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 or take parameters? (Y/n)', true);
- if ($helper->ask($input, $output, $question)) {
- $this->setParametersFormFile($input);
- }
- }
- $this->_domain = $input->getOption("domain");
- $this->_client = $input->getOption("client");
- if (!$this->_client) {
- $this->_client = basename(realpath($this->directory));
- }
- $docker_tag = $input->getOption("docker-tag");
- $this->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'][$this->internal_user_id]['user'];
- $this->_ansible_vars["CMD_PASSWORD"] = $this->_user_system['users'][$this->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["MYSQL_ROOT_PASSWORD"] = $this->_mysql_root_pass;
-
- $this->_add_nginx_links = $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();
- // 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");
- // copio el archivo con variables de entorno de grafana
- copy(getcwd() . "/grafana.env", $dObj->dirExists()->realpath()->getPath() . "/grafana.env");
- } catch (\Throwable $error) {
- throw $error;
- } finally {
- $this->_dObj = null;
- $this->_modules = null;
- }
- }
- /**
- * @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 addBase(FileFormat2 $composer, $config = array())
- {
- $module = "base";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("base/")
- ->addLinks("mysql:mysql")
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addVolumes("./$module/", "/opt/$module");
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addFtth(FileFormat2 $composer, $config = array())
- {
- $module = "ftth";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("ftth/")
- ->addLinks("mysql:mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file($module . ".oauth.env")
- ->addVolumes("./$module/", "/opt/" . $module)
- ->addVolumes("./extra/netmiko", "/opt/netmiko")
- ->addVolumes("./extra/backups-config", "/opt/ftth/web/backups-config");
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addStats(FileFormat2 $composer, $config = array())
- {
- $module = "stats";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("stats/")
- ->addLinks("mysql:mysql")
- ->addLinks("jsonep_mysql:jsonep_mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addVolumes("./$module/", "/opt/$module")
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file("$module.oauth.env");
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addMapas(FileFormat2 $composer, $config = array())
- {
- $module = "mapas";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("mapas/")
- ->addLinks("mysql:mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file("$module.oauth.env")
- ->addVolumes("./$module/", "/opt/$module")
- ->addVolumes("./$module/web/uploads", "/opt/$module/web/uploads");
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addCablemodem(FileFormat2 $composer, $config = array())
- {
- $module = "cablemodem";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("cablemodem/")
- ->addLinks("mysql:mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file("$module.oauth.env")
- ->addVolumes("./$module/", "/opt/$module")
- ->addVolumes("./$module/web/uploads", "/opt/$module/web/uploads");
-
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- /**
- * atftp, tod
- *
- * @param FileFormat2 $composer
- * @param array $config
- */
- function addTftp(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("tftp")
- ->build("extra/tftp/")
- ->image($registry . "fd3/tftp:" . $version)
- ->addEnv_file($host_env_file)
- ->restart($this->_docker_restart_default)
- ->addPorts(69, '69/udp');
- }
- function addRadius(FileFormat2 $composer, $config = array())
- {
- $module = "radius";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("radius/")
- ->addLinks("mysql:mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file("$module.oauth.env")
- ->addVolumes("./$module/", "/opt/$module");
- $this->addNginxLinks($module, $composer);
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addDHCP(FileFormat2 $composer, $config = array())
- {
- $module = "dhcp";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->restart($this->_docker_restart_default)
- ->build("dhcp/")
- ->addLinks("mysql:mysql")
- ->addLinks("base")
- //->addLinks("base", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addEnv_file("$module.oauth.env")
- ->addVolumes("./$module/", "/opt/$module")
- ->addVolumes("./kea/conf", "/opt/dhcp/web/kea")
- ;
- $this->addNginxLinks($module, $composer);
-
- $this->addBuild($module, $composer);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addNginx(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("nginx")
- ->build("extra/nginx/")
- ->image($registry . "fd3/nginx:" . $version)
- ->addEnv_file($host_env_file)
- ->restart($this->_docker_restart_default)
- ->addPorts(80, 80)
- ->addPorts(443, 443)
- ->addVolumes("./base/", "/opt/base")
- ->addVolumes("./ftth/", "/opt/ftth")
- ->addVolumes("./mapas/", "/opt/mapas")
- ->addVolumes("./radius/", "/opt/radius")
- ->addVolumes("./stats/", "/opt/stats")
- ->addVolumes("./cablemodem/", "/opt/cablemodem")
- ->addVolumes("./dhcp/", "/opt/dhcp")
- ->addVolumes("./grafana/", "/opt/grafana")
- ->addVolumes("/var/run/docker.sock", "/tmp/docker.sock:ro")
- ->addVolumes("./extra/nginx/certs", "/etc/nginx/certs:ro")
- ->addVolumes("./extra/nginx/conf.d", "/etc/nginx/conf.d")
- ->addVolumes("./extra/nginx/share", "/usr/share/nginx/html");
- }
- function addMongDb(FileFormat2 $composer, $config = array())
- {
- $mongdb_version = "3.4";
- extract($config);
- $composer
- ->addService("mongodb")
- ->image("mongo:" . $mongdb_version)
- ->addVolumes("./mongodb", "/data/db");
- }
- /**
- * @param FileFormat2 $composer
- * @param array $config
- */
- function addSupervisord(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("supervisord")
- ->build("./extra/supervisord")
- ->image($registry . "fd3/supervisord:$version")
- ->privileged(true)
- ->restart($this->_docker_restart_default)
- ->addLinks("geoserver")
- ->addLinks("nginx", $this->getDomain("geoserver"))
- ->addVolumes("./extra/supervisord/", "/etc/supervisord/")
- ->addVolumes("./extra/supervisord/var/", "/var/log/supervisor/")
- ->addVolumes("./extra/supervisord/sshd_config", "/etc/ssh/sshd_config")
- ->addVolumes("./extra/supervisord/bin/fiberhome", "/usr/bin/fiberhome")
- ->addVolumes("./extra/supervisord/bin/fiberlink", "/usr/bin/fiberlink")
- ->addVolumes("./extra/supervisord/bin/huawei", "/usr/bin/huawei")
- ->addVolumes("./extra/supervisord/bin/zte", "/usr/bin/zte")
- ->addVolumes("./stats", "/opt/stats")
- ->addEnv_file("running.env")
- ->addEnv_file($host_env_file)
- ->addEnv_file("stats.host.env")
- ->addEnv_file("stats.oauth.env");
- }
- function addMySql(FileFormat2 $composer, $config = array())
- {
- $module = "mysql";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image($registry . "fd3/$module:" . $version)
- ->build("./extra/mysql")
- ->addEnv_file($module . "." . $host_env_file)
- ->addVolumes("./mysql/", "/var/lib/mysql/")
- ->addVolumes("./extra/mysql/fd3.conf", "/etc/mysql/conf.d/fd3.conf");
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
- array(
- "MYSQL_ROOT_PASSWORD" => $this->_mysql_root_pass,
- "MYSQL_USER" => $this->_mysql_user,
- "MYSQL_PASSWORD" => $this->_mysql_pass,
- "MYSQL_MAX_CONNECTIONS" => $this->_mysql_max_connections,
- ));
- }
- function addRedis(FileFormat2 $composer, $config = array(), $flavor = "dev")
- {
- $composer
- ->addService("redis")
- ->image("redis:latest")
- ->command("redis-server --appendonly yes")
- ->restart($this->_docker_restart_default);
- }
- function addGenieACS(FileFormat2 $composer, $config = array(), $flavor = "dev")
- {
- $composer
- ->addService("genieacs-cwmp")
- ->build("extra/genieacs/genieacs-cwmp")
- ->addLinks("mongodb")
- ->addLinks("redis")
- ->addPorts("7547", "7547")
- ->restart($this->_docker_restart_default);
- $composer
- ->addService("genieacs-nbi")
- ->build("extra/genieacs/genieacs-nbi")
- ->addLinks("mongodb")
- ->addLinks("redis")
- ->addPorts("7557", "7557")
- ->restart($this->_docker_restart_default);
- $composer
- ->addService("genieacs-fs")
- ->build("extra/genieacs/genieacs-fs")
- ->addLinks("mongodb")
- ->addLinks("redis")
- ->addPorts("7567", "7567")
- ->restart($this->_docker_restart_default);
- $composer
- ->addService("genieacs-gui")
- ->build("extra/genieacs/genieacs-gui")
- ->addLinks("genieacs-nbi")
- ->addPorts("3001", "3000")
- ->restart($this->_docker_restart_default);
- }
- function addFreeradius(FileFormat2 $composer, $config = array(), $flavor = "dev")
- {
- $module = "freeradius";
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("freeradius")
- ->image($registry . "fd3/freeradius:" . $version)
- ->addLinks("mysql")
- ->addPorts("1812:1812/udp")
- ->addPorts("1813:1813/udp")
- ->addPorts("3799:3799/udp")
- ->addEnv_file("mysql." . $host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addVolumes("./extra/freeradius/wsdl/code/", "/var/www/html/")
- ->addVolumes("./extra/freeradius/etc/cron.d", "/etc/cron.d")
- ->addVolumes("./extra/freeradius/etc/freeradius", "/etc/freeradius")
- ->addVolumes("./extra/freeradius/etc/supervisor/conf.d", "/etc/supervisor/conf.d");
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
- array(
- "MYSQL_HOST" => "mysql",
- ));
- }
- function addPma(FileFormat2 $composer, $config = array())
- {
- $module = "pma";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("phpmyadmin")
- ->image("phpmyadmin/phpmyadmin")
- ->restart($this->_docker_restart_default)
- ->addPorts(8080, 80)
- ->addLinks("mysql", "db")
- ->addEnv_file("mysql." . $host_env_file)
- ->addEnv_file($module . "." . $host_env_file);
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
- }
- function addGrafana(FileFormat2 $composer, $config = array())
- {
- $module = "grafana";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService($module)
- ->image("grafana/grafana:5.0.4")
- ->addLinks("mysql")
- ->restart($this->_docker_restart_default)
- ->addEnv_file("running.env")
- ->addEnv_file("grafana.env")
- ->addVolumes("./extra/statsd/grafana/lib", "/var/lib/grafana");
- $this->addJsonEndPoints($composer, $config);
- }
- function addJsonEndPoints(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- $host_env_file = "";
- extract($config);
- $composer
- ->addService("statsd")
- ->build("./extra/statsd/statsd")
- ->image($registry . "fd3/statsd:$version")
- ->addPorts("8125", "8125/udp")
- ->addLinks("mysql")
- ->addLinks("mongodb")
- ->restart($this->_docker_restart_default)
- ->addVolumes("./extra/statsd/statsd/statsd.config.js", "/opt/config/statsd.config.js");
- $composer
- ->addService("jsendpoint")
- ->build("./extra/statsd/endpoint/json")
- ->image($registry . "fd3/jsonep:$version")
- ->addVolumes("./extra/statsd/endpoint/json", "/opt/datasource")
- ->addLinks("jsonep_mysql")
- ->addLinks("jsonep_mongo")
- ->restart($this->_docker_restart_default);
- $composer
- ->addService("jsonep_mysql")
- ->build("./extra/statsd/endpoint/mysql")
- ->image($registry . "fd3/jsonep_mysql:$version")
- ->addVolumes("./extra/statsd/endpoint/mysql", "/opt/datasource")
- ->addLinks("mysql")
- ->addEnv_file("mysql." . $host_env_file)
- ->restart($this->_docker_restart_default);
- $composer
- ->addService("jsonep_mongo")
- ->build("./extra/statsd/endpoint/mongodb")
- ->image($registry . "fd3/jsonep_mongo:$version")
- ->addVolumes("./extra/statsd/endpoint/mongodb", "/opt/datasource")
- ->addLinks("mongodb")
- ->restart($this->_docker_restart_default);
- }
- function addCommandWorkers(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- extract($config);
- $composer
- ->addService("base_log_worker")
- ->image($registry . "fd3/base:" . $version)
- ->build("./base/")
- ->command("bin/console rabbitmq:consumer log_consumer")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("base.host.env")
- ->addEnviroment("AMQP_KEY", "base")
- ->addEnviroment("SYMFONY_ENV", "prod")
- ->addVolumes("./base/", "/opt/base");
- $composer
- ->addService("ftth_tasklogger_worker")
- ->image($registry . "fd3/ftth:" . $version)
- ->build("./ftth/")
- ->command("bin/console rabbitmq:consumer flowdat_tasklogger")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("ftth.host.env")
- ->addEnviroment("AMQP_KEY", "ftth")
- ->addVolumes("./ftth/", "/opt/ftth")
- ->addVolumes("./extra/netmiko", "/opt/netmiko")
- ->addVolumes("./extra/backups-config", "/opt/ftth/web/backups-config");
- $composer
- ->addService("cablemodem_tasklogger_worker")
- ->image($registry . "fd3/cablemodem:" . $version)
- ->build("./cablemodem/")
- ->command("bin/console rabbitmq:consumer flowdat_tasklogger")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("cablemodem.host.env")
- ->addEnviroment("AMQP_KEY", "cablemodem")
- ->addVolumes("./cablemodem/", "/opt/cablemodem");
- $composer
- ->addService("dhcp_tasklogger_worker")
- ->image($registry . "fd3/dhcp:" . $version)
- ->build("./dhcp/")
- ->command("bin/console rabbitmq:consumer flowdat_tasklogger")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("dhcp.host.env")
- ->addEnviroment("AMQP_KEY", "dhcp")
- ->addVolumes("./dhcp/", "/opt/dhcp");
- $composer
- ->addService("ftth_command_worker")
- ->image($registry . "fd3/ftth:" . $version)
- ->build("./ftth/")
- ->command("bin/console rabbitmq:consumer command_consumer")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("ftth.host.env")
- ->addEnviroment("AMQP_KEY", "ftth")
- ->addVolumes("./ftth/", "/opt/ftth");
- $composer
- ->addService("stats_command_worker")
- ->image($registry . "fd3/stats:" . $version)
- ->build("./stats/")
- ->command("bin/console rabbitmq:consumer command_consumer")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addLinks("geoserver")
- ->addLinks("nginx", $this->getDomain("geoserver"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("stats.host.env")
- ->addEnviroment("AMQP_KEY", "stats")
- ->addVolumes("./stats/", "/opt/stats")
- ->addVolumes("./geoserver/geoserver-shapes", "/var/www/shapes");
- $composer
- ->addService("cablemodem_command_worker")
- ->image($registry . "fd3/cablemodem:" . $version)
- ->build("./cablemodem/")
- ->command("bin/console rabbitmq:consumer command_consumer")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql")
- ->addLinks("base")
- ->addLinks("nginx", $this->getDomain("base"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file("cablemodem.host.env")
- ->addEnviroment("AMQP_KEY", "cablemodem")
- ->addVolumes("./cablemodem/", "/opt/cablemodem");
- }
- /**
- * @param FileFormat2 $composer
- * @param array $config
- */
- public function addGeoserver(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- extract($config);
- $composer
- ->addService("geoserver")
- ->image($registry . "fd3/geoserver:" . $version)
- ->build("./extra/geoserver/")
- ->restart($this->_docker_restart_default)
- ->addLinks("nginx", $this->getDomain("geoserver"))
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addVolumes("./extra/geoserver/geoserver-data/styles", "/opt/geoserver/data_dir/styles")
- ->addVolumes("./geoserver/geoserver-shapes", "/var/www/shapes")
- ->addPorts(8081, 8080);
- }
- /**
- * @param FileFormat2 $composer
- * @param array $config
- */
- public function addKea(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- extract($config);
- $module = 'kea';
- $composer
- ->addService("kea")
- ->image($registry . "fd3/kea-1.4.0:" . $version)
- // ->build("./extra/kea/")
- ->restart($this->_docker_restart_default)
- ->addPorts(8086, 8080)
- ->addPorts(67, '67/udp')
- ->addPorts(68, '68/udp')
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addEnv_file($module . "." . $host_env_file)
- ->addVolumes("./kea/conf/kea-ctrl-agent.conf", "/usr/local/etc/kea/kea-ctrl-agent.conf")
- ->addVolumes("./kea/conf/kea-dhcp4.conf", "/usr/local/etc/kea/kea-dhcp4.conf")
- ->addVolumes("/kea/supervisord", "/etc/supervisord")
- ->addVolumes("./kea/hooks", "/opt/hooks")
- ;
- $this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
- array(
- "MYSQL_ROOT_PASSWORD" => $this->_mysql_root_pass,
- "MYSQL_USER" => $this->_mysql_user,
- ));
- }
- /**
- * @param FileFormat2 $composer
- * @param array $config
- */
- public function addSwagger(FileFormat2 $composer, $config = array())
- {
- $version = "latest";
- $registry = "";
- extract($config);
- $composer
- ->addService("swagger-ui")
- ->image($registry . "fd3/swagger-ui:" . $version)
- ->build("./extra/swagger/")
- ->restart($this->_docker_restart_default)
- ->addEnviroment("SWAGGER_JSON", "/foo/ftth.json")
- ->addEnv_file("running.env")
- ->addEnv_file("host.env")
- ->addPorts(8085, 8080);
- }
- function getDockerComposer($version = "latest", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/")
- {
- $composer = new FileFormat2("../");
- $base_vars = array(
- "version" => $version,
- "host_env_file" => $host_env_file,
- "registry" => $registry);
- $this->addNginx($composer, $base_vars);
- /**************************************************************************************/
- /* Apps / Web UI / Grafana / PMA */
- /**************************************************************************************/
- foreach ($this->_modules_all as $module => $env) {
- $method = 'add' . ucfirst($module);
- if (array_key_exists($module, $this->_modules) && method_exists($this, $method)) {
- $this->$method($composer, $base_vars);
- }
- }
- /**************************************************************************************/
- /* Servicios */
- /**************************************************************************************/
- $this->addMySql($composer, $base_vars);
- $composer
- ->addService("amqp")
- ->build("./extra/amqp/")
- ->image("rabbitmq:3-management")
- ->addPorts(15674, 15674)
- ->restart($this->_docker_restart_default);
- $this->addMongDb($composer, $base_vars);
- $this->addRedis($composer, $base_vars);
- $this->addGenieACS($composer, $base_vars);
- $this->addFreeradius($composer, $base_vars);
- /**************************************************************************************/
- /* Workers */
- /**************************************************************************************/
- $this->addSupervisord($composer, $base_vars);
- $this->addCommandWorkers($composer, $base_vars);
- $this->addTftp($composer, $base_vars);
- // Geoserver
- $this->addGeoserver($composer, $base_vars);
- // Kea
- $this->addKea($composer, $base_vars);
- // Swagger
- $this->addSwagger($composer, $base_vars);
- $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.
- */
- private 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.
- */
- private function createGitClone()
- {
- $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"]
- );
- }
- }
- $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
- */
- private 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 $name Contiene el nombre del modulo.
- * @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($name, $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 {
- $env .= $key . "=" . $value . "\n";
- }
- }
- }
- }
- }
- foreach ($extras as $key => $value) {
- $env .= $key . "=" . $value . "\n";
- }
- return $env;
- }
- /**
- * Crea el archivo modulo.oauth.env
- */
- 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);
- }
- /**
- * Crea el archivo host.env
- */
- private 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.
- */
- private 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.
- */
- private function writeVariablesEnviroment($name, $module = null, $extras = array())
- {
- $this->_dObj->file($name)->content(
- $this->getEnviromentVarialbes($name, $module, $extras));
- }
- /**
- * Funcion que agrega el build de acuerdo en la configuracion.
- * @param string $module Contiene el nombre del modulo.
- * @param FileFormat2 $composer Contiene el objeto FileFormat2.
- */
- private function addBuild($module, FileFormat2 $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
- */
- private 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.
- */
- private function getDomain($module)
- {
- return $module . "." . $this->_client . "." . $this->_domain;
- }
- /**
- * @param array $modules Contiene los modulos a implementar
- */
- private 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.
- */
- 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 los usuarios del sistema para que lea el ansible.
- */
- private function writeUserSystem()
- {
- $this->_dObj->file("user_system.json")
- ->content(json_encode($this->_user_system));
- }
- /**
- * Crea el archivo con las variables para ejecutar el ansible.
- */
- private function writeInventory(FileFormat2 $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 FileFormat2 $composer Contiene el objeto FileFormat2.
- */
- private function addNginxLinks($module, FileFormat2 $composer)
- {
- if ($this->_add_nginx_links) {
- $composer->service($module)
- ->addLinks("nginx", $this->getDomain("base"))
- ->addLinks("nginx", $this->getDomain("ftth"))
- ->addLinks("nginx", $this->getDomain("cablemodem"))
- ->addLinks("nginx", $this->getDomain("mapas"))
- ->addLinks("nginx", $this->getDomain("stats"))
- ->addLinks("nginx", $this->getDomain("dhcp"))
- ->addLinks("nginx", $this->getDomain("radius"));
- }
- }
- }
|