123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395 |
- <?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(
- "PMA_HOST"=> "mysql",
- "PMA_PORT"=> "3306",
- "PMA_ABSOLUTE_URI"=> ""
- ),
- '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_NONE, 'Add NGINX links between dockers', null);
- }
- 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 = (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();
- // 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("pma_volumen", "/opt/pma")
- ->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")
- ->mem_limit('10g');
- }
- /**
- * @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")
- ->addVolumes("./ftth", "/opt/ftth")
- ->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 = "host.env";
- extract($config);
- $composer
- ->addService("pma")
- ->image("phpmyadmin/phpmyadmin")
- ->restart($this->_docker_restart_default)
- ->addLinks("mysql", "mysql")
- ->addEnv_file("host.env")
- ->addEnv_file("mysql." . $host_env_file)
- ->addEnv_file($module . "." . $host_env_file)
- ->addVolumes("pma_volumen", "/www");
- $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)
- ->mem_limit('500m');
- }
- /**
- * @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-ik-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("../");
- $composer->getVolumes()->addVolumen('pma_volumen', 'local');
- $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);
- $this->addPma($composer, $base_vars);
- $composer
- ->addService("amqp")
- ->build("./extra/amqp/")
- ->image("rabbitmq:3-management")
- ->addPorts(15674, 15674)
- ->addPorts(15672, 15672)
- ->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 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
- */
- 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"));
- }
- }
- }
|