Release.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. <?php
  2. namespace FD3;
  3. use Docker\Composer\ServiceNotFoundException;
  4. use function GuzzleHttp\default_user_agent;
  5. use League\Flysystem\File;
  6. use Symfony\Component\Console\Command\Command;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Input\InputArgument;
  9. use Symfony\Component\Console\Input\InputOption;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Docker\Composer\FileFormat2;
  12. use Symfony\Component\Console\Exception\LogicException;
  13. use Symfony\Component\Console\Question\ConfirmationQuestion;
  14. use Symfony\Component\Yaml\Yaml;
  15. class Release extends Command
  16. {
  17. /**
  18. * @var string Nombre del archivo de log.
  19. */
  20. private $_running_log;
  21. /**
  22. * @var string Contiene la politica de restart de los dockers.
  23. */
  24. private $_docker_restart_default;
  25. /**
  26. * @var array Contiene las variables que se utilizar en la ejecucion del ansible.
  27. */
  28. private $_ansible_vars;
  29. /**
  30. * @var string Contiene el password del usuario root.
  31. */
  32. private $_mysql_root_pass;
  33. /**
  34. * @var string Contiene el usuario de base de datos.
  35. */
  36. private $_mysql_user;
  37. /**
  38. * @var string Contiene la contrasena del usuario de base de datos.
  39. */
  40. private $_mysql_pass;
  41. /**
  42. * @var DevOps\FileSystem Me permite crear archivos.
  43. */
  44. private $_dObj;
  45. /**
  46. * @var string Contiene el dominio.
  47. */
  48. private $_domain;
  49. /**
  50. * @var string Contiene el nombre del cliente.
  51. */
  52. private $_client;
  53. /**
  54. * @var array Contiene todos los modulos para la instalacion.
  55. */
  56. private $_modules_all;
  57. /**
  58. * @var array Contiene la configuracion de los modulos.
  59. */
  60. private $_modules;
  61. /**
  62. * @var array Contiene los usuarios que van a poder acceder al sistema.
  63. */
  64. private $_user_system;
  65. /**
  66. * @var string $directory Directorio de instalación
  67. */
  68. private $directory;
  69. /**
  70. * Constructor.
  71. *
  72. * @param string|null $name The name of the command; passing null means it must be set in configure()
  73. *
  74. * @throws LogicException When the command name is empty
  75. */
  76. public function __construct($name = null)
  77. {
  78. parent::__construct($name);
  79. $this->_running_log = "running.log";
  80. $this->_mysql_user = "iksop";
  81. $this->_mysql_pass = "235r2342gtfsw";
  82. $this->_mysql_root_pass = "235r2342gtfsw";
  83. $this->_mysql_max_connections = 10000;
  84. $this->_docker_restart_default = "on-failure:10";
  85. $this->_user_system = ['users' =>
  86. [
  87. ['user' => 'admin', 'password' => 'admin', 'tenancy' => 1, 'email' => 'soporte@interlink.com.ar', 'extra' => '--super-admin '],
  88. ['user' => 'iksop', 'password' => 'gran5pe', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => ''],
  89. ['user' => 'interno', 'password' => 'gran5pe1nterno', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => '']
  90. ]];
  91. $this->_modules = array();
  92. $this->_ansible_vars = array();
  93. $this->_modules_all = array(
  94. "base" => array(
  95. 'HOST_ENV' => true,
  96. "VAR_ENV" => array(
  97. 'VIRTUAL_HOST' => '',
  98. 'HTTPS_METHOD' => 'nohttps',
  99. 'AMQP_KEY' => 'base'
  100. ),
  101. 'OAUTH' => false,
  102. 'MODULE_INSTALL' => true
  103. ),
  104. "ftth" => array(
  105. 'HOST_ENV' => true,
  106. "VAR_ENV" => array(
  107. 'VIRTUAL_HOST' => '',
  108. 'HTTPS_METHOD' => 'nohttps',
  109. 'AMQP_KEY' => 'ftth'
  110. ),
  111. 'OAUTH' => true,
  112. 'MODULE_INSTALL' => true
  113. ),
  114. "mapas" => array(
  115. 'HOST_ENV' => true,
  116. "VAR_ENV" => array(
  117. 'VIRTUAL_HOST' => '',
  118. 'HTTPS_METHOD' => 'nohttps',
  119. ),
  120. 'OAUTH' => true,
  121. 'MODULE_INSTALL' => true
  122. ),
  123. "radius" => array(
  124. 'HOST_ENV' => true,
  125. "VAR_ENV" => array(
  126. 'VIRTUAL_HOST' => '',
  127. 'HTTPS_METHOD' => 'nohttps',
  128. ),
  129. 'OAUTH' => true,
  130. 'MODULE_INSTALL' => true
  131. ),
  132. "stats" => array(
  133. 'HOST_ENV' => true,
  134. "VAR_ENV" => array(
  135. 'VIRTUAL_HOST' => '',
  136. 'HTTPS_METHOD' => 'nohttps',
  137. 'AMQP_KEY' => 'stats'
  138. ),
  139. 'OAUTH' => true,
  140. 'MODULE_INSTALL' => true
  141. ),
  142. "cablemodem" => array(
  143. 'HOST_ENV' => true,
  144. "VAR_ENV" => array(
  145. 'VIRTUAL_HOST' => '',
  146. 'HTTPS_METHOD' => 'nohttps',
  147. 'AMQP_KEY' => 'cablemodem'
  148. ),
  149. 'OAUTH' => true,
  150. 'MODULE_INSTALL' => true
  151. ),
  152. "dhcp" => array(
  153. 'HOST_ENV' => true,
  154. "VAR_ENV" => array(
  155. 'VIRTUAL_HOST' => '',
  156. 'HTTPS_METHOD' => 'nohttps',
  157. ),
  158. 'OAUTH' => true,
  159. 'MODULE_INSTALL' => true
  160. ),
  161. "grafana" => array(
  162. 'HOST_ENV' => true,
  163. "VAR_ENV" => array(
  164. 'VIRTUAL_HOST' => '',
  165. 'HTTPS_METHOD' => 'nohttps',
  166. ),
  167. 'OAUTH' => false,
  168. 'MODULE_INSTALL' => true
  169. ),
  170. "pma" => array(
  171. 'HOST_ENV' => true,
  172. "VAR_ENV" => array(
  173. 'VIRTUAL_HOST' => '',
  174. ),
  175. 'OAUTH' => false,
  176. 'MODULE_INSTALL' => false
  177. ),
  178. "extra" => array(
  179. 'HOST_ENV' => false,
  180. 'OAUTH' => false,
  181. 'MODULE_INSTALL' => true
  182. ),
  183. "geoserver" => array(
  184. 'HOST_ENV' => true,
  185. "VAR_ENV" => array(
  186. 'VIRTUAL_HOST' => '',
  187. 'HTTPS_METHOD' => 'nohttps',
  188. ),
  189. 'OAUTH' => false,
  190. 'MODULE_INSTALL' => true
  191. ),
  192. );
  193. }
  194. protected function configure()
  195. {
  196. $this
  197. ->setName('make:install')
  198. ->setDescription('Create a new install.')
  199. ->setHelp('This command allows you to create a new installation...')
  200. ->addArgument('dir', InputArgument::REQUIRED, 'The directory where to create the installation.')
  201. ->addOption('base-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/base.git")
  202. ->addOption('base-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Base app', "master")
  203. ->addOption('base-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  204. ->addOption('ftth-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app FTTH', "git@bitbucket.org:ikflowdat/ftth.git")
  205. ->addOption('ftth-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Ftth ', "master")
  206. ->addOption('ftth-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  207. ->addOption('mapas-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Mapas', "git@bitbucket.org:ikflowdat/mapas.git")
  208. ->addOption('mapas-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Mapas app', "master")
  209. ->addOption('mapas-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  210. ->addOption('radius-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app radius', "git@bitbucket.org:ikflowdat/radius.git")
  211. ->addOption('radius-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the radius app', "master")
  212. ->addOption('radius-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  213. ->addOption('stats-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/stats.git")
  214. ->addOption('stats-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Stats app', "master")
  215. ->addOption('stats-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  216. ->addOption('cablemodem-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app Cablemodem', "git@bitbucket.org:ikflowdat/cablemodem.git")
  217. ->addOption('cablemodem-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Cablemodem files and apps', "master")
  218. ->addOption('cablemodem-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  219. ->addOption('dhcp-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url for the app DHCP', "git@bitbucket.org:ikflowdat/dhcp.git")
  220. ->addOption('dhcp-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the DHCP files and apps', "master")
  221. ->addOption('dhcp-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  222. ->addOption('extra-repo', null, InputOption::VALUE_REQUIRED, 'Git clone Url fot the app Base', "git@bitbucket.org:ikflowdat/extra.git")
  223. ->addOption('extra-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone the Extra files and apps', "master")
  224. ->addOption('extra-build', null, InputOption::VALUE_REQUIRED, 'Generate image build', "false")
  225. ->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")
  226. ->addOption('domain', null, InputOption::VALUE_REQUIRED, 'Domain where the flowdat will be installed', "flowdat.com")
  227. ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client name, if is not provided uses, the dirname of the installation', false)
  228. ->addOption('modules', null, InputOption::VALUE_REQUIRED, 'List of modules to install separated by coma.', "all")
  229. ->addOption('inventory', null, InputOption::VALUE_REQUIRED, 'Write inventory.ini by default.', true)
  230. ->addOption('docker-tag', null, InputOption::VALUE_REQUIRED, 'Docker tag to be used', "latest")
  231. ->addOption('all-ref', null, InputOption::VALUE_REQUIRED, 'Git reference (branch or tag) to clone all app', "")
  232. ->addOption('general-version', null, InputOption::VALUE_REQUIRED, 'Set options all-ref and docker-tag with this value. Ej. 0.1.1', "");
  233. }
  234. protected function execute(InputInterface $input, OutputInterface $output)
  235. {
  236. try {
  237. if (strlen(trim($input->getOption("general-version"))) > 0) {
  238. $input->setOption('all-ref', 'v' . $input->getOption('general-version'));
  239. $input->setOption('docker-tag', $input->getOption('general-version'));
  240. }
  241. if (strlen(trim($input->getOption("all-ref"))) > 0) {
  242. $input->setOption('base-ref', $input->getOption('all-ref'));
  243. $input->setOption('ftth-ref', $input->getOption('all-ref'));
  244. $input->setOption('mapas-ref', $input->getOption('all-ref'));
  245. $input->setOption('radius-ref', $input->getOption('all-ref'));
  246. $input->setOption('stats-ref', $input->getOption('all-ref'));
  247. $input->setOption('cablemodem-ref', $input->getOption('all-ref'));
  248. $input->setOption('dhcp-ref', $input->getOption('all-ref'));
  249. $input->setOption('extra-ref', $input->getOption('all-ref'));
  250. }
  251. if (strtolower($input->getOption("modules")) == "all") {
  252. // seteo todos los modulos a instalar por defecto
  253. $modules = "";
  254. foreach ($this->_modules_all as $name => $value) {
  255. if (isset($value['MODULE_INSTALL']) && $value['MODULE_INSTALL']) {
  256. $modules = $modules . $name . ",";
  257. }
  258. }
  259. $modules = substr($modules, 0, strlen($modules) - 1);
  260. $input->setOption("modules", $modules);
  261. }
  262. $this->AddModules(explode(",", $input->getOption("modules")));
  263. $this->directory = $input->getArgument('dir');
  264. if (!is_dir($this->directory)) {
  265. mkdir($this->directory, 0777, true);
  266. }
  267. if (file_exists($this->directory . "/" . $this->_running_log)) {
  268. $helper = $this->getHelper('question');
  269. $question = new ConfirmationQuestion('The ' . realpath($this->directory) . "/" . $this->_running_log . ' file exist. Read file or take parameters? (Y/n)', true);
  270. if ($helper->ask($input, $output, $question)) {
  271. $this->setParametersFormFile($input);
  272. }
  273. }
  274. $this->_domain = $input->getOption("domain");
  275. $this->_client = $input->getOption("client");
  276. if (!$this->_client) {
  277. $this->_client = basename(realpath($this->directory));
  278. }
  279. $docker_tag = $input->getOption("docker-tag");
  280. $this->internal_user_id = 2;
  281. $this->_ansible_vars["DOMAIN"] = $this->_domain;
  282. $this->_ansible_vars["CLIENT"] = $this->_client;
  283. $this->_ansible_vars["CMD_USERNAME"] = $this->_user_system['users'][$this->internal_user_id]['user'];
  284. $this->_ansible_vars["CMD_PASSWORD"] = $this->_user_system['users'][$this->internal_user_id]['password'];
  285. $dObj = new DevOps\FileSystem(realpath($this->directory));
  286. $dObj->dirExists()->realpath();
  287. $this->_dObj = $dObj;
  288. // agrego las opciones del input a la configuracion _modues
  289. $this->addConfigOptions($input);
  290. // creo el archivo de log de como se ejecuto
  291. $this->createFileRunning($input, $output);
  292. // cargo las fuentes a clonar
  293. $this->createGitClone();
  294. // creo el archivo docker-compose.yml
  295. $this->getDockerComposer($docker_tag, "host.env", "docker.infra.flowdat.com/");
  296. // escribo el archivo de host
  297. $this->writeHostsFile($input->getOption("host-ip"));
  298. // escribo el archivo con las variables de entorno
  299. $this->writeHostEnv();
  300. // escribo los archivo oauth
  301. $this->writeOAUTH();
  302. // escribo un archivo con variables para ansible
  303. $this->writeEnvVariables();
  304. // escribo un archivo con los usuarios del sistema
  305. $this->writeUserSystem();
  306. $dObj->file('install.yml')->content(
  307. yaml::dump(array(
  308. "install_dir" => realpath($this->directory),
  309. 'docker_apps' => "base," . implode(",", $this->_ansible_vars),
  310. 'domain' => $this->_domain,
  311. )
  312. )
  313. );
  314. $dObj->file('ansible.cfg')->content(
  315. "[defaults]\n" .
  316. "inventory=inventory.ini\n"
  317. );
  318. // copio el playbook
  319. copy(getcwd() . "/playbook.yml", $dObj->dirExists()->realpath()->getPath() . "/playbook.yml");
  320. // copio el script de base de datos inicial
  321. copy(getcwd() . "/mysql_scripts.sql", $dObj->dirExists()->realpath()->getPath() . "/mysql_scripts.sql");
  322. // copio el archivo que contiene los usuarios del sistema
  323. copy(getcwd() . "/user_system.json", $dObj->dirExists()->realpath()->getPath() . "/user_system.json");
  324. // copio script mysql schema freeradius
  325. copy(getcwd() . "/mysql/freeradius/schema.sql", $dObj->dirExists()->realpath()->getPath() . "/freeradius_schema.sql");
  326. // copio el docker-compose.service
  327. copy(getcwd() . "/docker-compose.service", $dObj->dirExists()->realpath()->getPath() . "/docker-compose.service");
  328. // copio el archivo con variables de entorno de grafana
  329. copy(getcwd() . "/grafana.env", $dObj->dirExists()->realpath()->getPath() . "/grafana.env");
  330. } catch (\Throwable $error) {
  331. throw $error;
  332. } finally {
  333. $this->_dObj = null;
  334. $this->_modules = null;
  335. }
  336. }
  337. /**
  338. * @return array Retorna un array con los host como key el dominio como valor.
  339. */
  340. function getHostEnv()
  341. {
  342. $resp = array();
  343. foreach ($this->_modules as $key => $values) {
  344. if ($values['HOST_ENV']) {
  345. $resp ["HOST_" . strtoupper($key)] = $this->getDomain($key);
  346. }
  347. }
  348. return $resp;
  349. }
  350. function getHostConfig($config_ip)
  351. {
  352. $resp = array();
  353. foreach ($this->_modules as $key => $values) {
  354. if ($values['HOST_ENV']) {
  355. $resp [$this->getDomain($key)] = $config_ip;
  356. }
  357. }
  358. return $resp;
  359. }
  360. function addBase(FileFormat2 $composer, $config = array())
  361. {
  362. $module = "base";
  363. $version = "latest";
  364. $registry = "";
  365. $host_env_file = "";
  366. extract($config);
  367. $composer
  368. ->addService($module)
  369. ->image($registry . "fd3/$module:" . $version)
  370. ->restart($this->_docker_restart_default)
  371. ->addLinks("mysql:mysql")
  372. ->addEnv_file("running.env")
  373. ->addEnv_file($host_env_file)
  374. ->addEnv_file($module . "." . $host_env_file)
  375. ->addVolumes("./$module/", "/opt/$module");
  376. $this->addBuild($module, $composer);
  377. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  378. }
  379. function addFtth(FileFormat2 $composer, $config = array())
  380. {
  381. $module = "ftth";
  382. $version = "latest";
  383. $registry = "";
  384. $host_env_file = "";
  385. extract($config);
  386. $composer
  387. ->addService($module)
  388. ->image($registry . "fd3/$module:" . $version)
  389. ->restart($this->_docker_restart_default)
  390. ->addLinks("mysql:mysql")
  391. ->addLinks("base")
  392. ->addLinks("base", $this->getDomain("base"))
  393. ->addEnv_file("running.env")
  394. ->addEnv_file($host_env_file)
  395. ->addEnv_file($module . "." . $host_env_file)
  396. ->addEnv_file($module . ".oauth.env")
  397. ->addVolumes("./$module/", "/opt/" . $module);
  398. $this->addBuild($module, $composer);
  399. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  400. }
  401. function addStats(FileFormat2 $composer, $config = array())
  402. {
  403. $module = "stats";
  404. $version = "latest";
  405. $registry = "";
  406. $host_env_file = "";
  407. extract($config);
  408. $composer
  409. ->addService($module)
  410. ->image($registry . "fd3/$module:" . $version)
  411. ->restart($this->_docker_restart_default)
  412. ->addLinks("mysql:mysql")
  413. ->addLinks("jsonep_mysql:jsonep_mysql")
  414. ->addLinks("base")
  415. ->addLinks("base", $this->getDomain("base"))
  416. ->addVolumes("./$module/", "/opt/$module")
  417. ->addEnv_file("running.env")
  418. ->addEnv_file($host_env_file)
  419. ->addEnv_file($module . "." . $host_env_file)
  420. ->addEnv_file("$module.oauth.env");
  421. $this->addBuild($module, $composer);
  422. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  423. }
  424. function addMapas(FileFormat2 $composer, $config = array())
  425. {
  426. $module = "mapas";
  427. $version = "latest";
  428. $registry = "";
  429. $host_env_file = "";
  430. extract($config);
  431. $composer
  432. ->addService($module)
  433. ->image($registry . "fd3/$module:" . $version)
  434. ->restart($this->_docker_restart_default)
  435. ->addLinks("mysql:mysql")
  436. ->addLinks("base")
  437. ->addLinks("base", $this->getDomain("base"))
  438. ->addEnv_file("running.env")
  439. ->addEnv_file($host_env_file)
  440. ->addEnv_file($module . "." . $host_env_file)
  441. ->addEnv_file("$module.oauth.env")
  442. ->addVolumes("./$module/", "/opt/$module")
  443. ->addVolumes("./$module/web/uploads", "/opt/$module/web/uploads");
  444. $this->addBuild($module, $composer);
  445. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  446. }
  447. function addCablemodem(FileFormat2 $composer, $config = array())
  448. {
  449. $module = "cablemodem";
  450. $version = "latest";
  451. $registry = "";
  452. $host_env_file = "";
  453. extract($config);
  454. $composer
  455. ->addService($module)
  456. ->image($registry . "fd3/$module:" . $version)
  457. ->restart($this->_docker_restart_default)
  458. ->addLinks("mysql:mysql")
  459. ->addLinks("base")
  460. ->addLinks("base", $this->getDomain("base"))
  461. ->addEnv_file("running.env")
  462. ->addEnv_file($host_env_file)
  463. ->addEnv_file($module . "." . $host_env_file)
  464. ->addEnv_file("$module.oauth.env")
  465. ->addVolumes("./$module/", "/opt/$module")
  466. ->addVolumes("./$module/web/uploads", "/opt/$module/web/uploads");
  467. $this->addBuild($module, $composer);
  468. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  469. }
  470. /**
  471. * atftp, tod
  472. *
  473. * @param FileFormat2 $composer
  474. * @param array $config
  475. */
  476. function addTftp(FileFormat2 $composer, $config = array())
  477. {
  478. $version = "latest";
  479. $registry = "";
  480. $host_env_file = "";
  481. extract($config);
  482. $composer
  483. ->addService("tftp")
  484. ->build("extra/tftp/")
  485. ->image($registry . "fd3/tftp:" . $version)
  486. ->addEnv_file($host_env_file)
  487. ->restart($this->_docker_restart_default)
  488. ->addPorts(69, 69);
  489. }
  490. function addRadius(FileFormat2 $composer, $config = array())
  491. {
  492. $module = "radius";
  493. $version = "latest";
  494. $registry = "";
  495. $host_env_file = "";
  496. extract($config);
  497. $composer
  498. ->addService($module)
  499. ->image($registry . "fd3/$module:" . $version)
  500. ->restart($this->_docker_restart_default)
  501. ->addLinks("mysql:mysql")
  502. ->addLinks("base")
  503. ->addLinks("base", $this->getDomain("base"))
  504. ->addEnv_file("running.env")
  505. ->addEnv_file($host_env_file)
  506. ->addEnv_file($module . "." . $host_env_file)
  507. ->addEnv_file("$module.oauth.env")
  508. ->addVolumes("./$module/", "/opt/$module");
  509. $this->addBuild($module, $composer);
  510. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  511. }
  512. function addDHCP(FileFormat2 $composer, $config = array())
  513. {
  514. $module = "dhcp";
  515. $version = "latest";
  516. $registry = "";
  517. $host_env_file = "";
  518. extract($config);
  519. $composer
  520. ->addService($module)
  521. ->image($registry . "fd3/$module:" . $version)
  522. ->restart($this->_docker_restart_default)
  523. ->addLinks("mysql:mysql")
  524. ->addLinks("base")
  525. ->addLinks("base", $this->getDomain("base"))
  526. ->addEnv_file("running.env")
  527. ->addEnv_file($host_env_file)
  528. ->addEnv_file($module . "." . $host_env_file)
  529. ->addEnv_file("$module.oauth.env")
  530. ->addVolumes("./$module/", "/opt/$module");
  531. $this->addBuild($module, $composer);
  532. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  533. }
  534. function addNginx(FileFormat2 $composer, $config = array())
  535. {
  536. $version = "latest";
  537. $registry = "";
  538. $host_env_file = "";
  539. extract($config);
  540. $composer
  541. ->addService("nginx")
  542. ->build("extra/nginx/")
  543. ->image($registry . "fd3/nginx:" . $version)
  544. ->addEnv_file($host_env_file)
  545. ->restart($this->_docker_restart_default)
  546. ->addPorts(80, 80)
  547. ->addPorts(443, 443)
  548. ->addVolumes("/var/run/docker.sock", "/tmp/docker.sock:ro")
  549. ->addVolumes("./extra/nginx/certs", "/etc/nginx/certs:ro")
  550. ->addVolumes("./extra/nginx/conf.d", "/etc/nginx/conf.d")
  551. ->addVolumes("./extra/nginx/share", "/usr/share/nginx/html");
  552. }
  553. function addMongDb(FileFormat2 $composer, $config = array())
  554. {
  555. $mongdb_version = "3.4";
  556. extract($config);
  557. $composer
  558. ->addService("mongodb")
  559. ->image("mongo:" . $mongdb_version)
  560. ->addVolumes("./mongodb", "/data/db");
  561. }
  562. /**
  563. * @param FileFormat2 $composer
  564. * @param array $config
  565. */
  566. function addSupervisord(FileFormat2 $composer, $config = array())
  567. {
  568. $version = "latest";
  569. $registry = "";
  570. $host_env_file = "";
  571. extract($config);
  572. $composer
  573. ->addService("supervisord")
  574. ->build("./extra/supervisord")
  575. ->image($registry . "fd3/supervisord:$version")
  576. ->privileged(true)
  577. ->restart($this->_docker_restart_default)
  578. ->addLinks("geoserver")
  579. ->addLinks("nginx", $this->getDomain("geoserver"))
  580. ->addVolumes("./extra/supervisord/", "/etc/supervisord/")
  581. ->addVolumes("./extra/supervisord/var/", "/var/log/supervisor/")
  582. ->addVolumes("./extra/supervisord/sshd_config", "/etc/ssh/sshd_config")
  583. ->addVolumes("./extra/supervisord/bin/fiberhome", "/usr/bin/fiberhome")
  584. ->addVolumes("./extra/supervisord/bin/fiberlink", "/usr/bin/fiberlink")
  585. ->addVolumes("./extra/supervisord/bin/huawei", "/usr/bin/huawei")
  586. ->addVolumes("./stats", "/opt/stats")
  587. ->addEnv_file("running.env")
  588. ->addEnv_file($host_env_file)
  589. ->addEnv_file("stats.host.env")
  590. ->addEnv_file("stats.oauth.env");
  591. }
  592. function addMySql(FileFormat2 $composer, $config = array())
  593. {
  594. $module = "mysql";
  595. $version = "latest";
  596. $registry = "";
  597. $host_env_file = "";
  598. extract($config);
  599. $composer
  600. ->addService($module)
  601. ->image($registry . "fd3/$module:" . $version)
  602. ->build("./extra/mysql")
  603. ->addEnv_file($module . "." . $host_env_file)
  604. ->addVolumes("./mysql/", "/var/lib/mysql/")
  605. ->addVolumes("./extra/mysql/fd3.conf", "/etc/mysql/conf.d/fd3.conf");
  606. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
  607. array(
  608. "MYSQL_ROOT_PASSWORD" => $this->_mysql_root_pass,
  609. "MYSQL_USER" => $this->_mysql_user,
  610. "MYSQL_PASSWORD" => $this->_mysql_pass,
  611. "MYSQL_MAX_CONNECTIONS" => $this->_mysql_max_connections,
  612. ));
  613. }
  614. function addRedis(FileFormat2 $composer, $config = array(), $flavor = "dev")
  615. {
  616. $composer
  617. ->addService("redis")
  618. ->image("redis:latest")
  619. ->command("redis-server --appendonly yes")
  620. ->restart($this->_docker_restart_default);
  621. }
  622. function addGenieACS(FileFormat2 $composer, $config = array(), $flavor = "dev")
  623. {
  624. $composer
  625. ->addService("genieacs-cwmp")
  626. ->build("extra/genieacs/genieacs-cwmp")
  627. ->addLinks("mongodb")
  628. ->addLinks("redis")
  629. ->addPorts("7547", "7547")
  630. ->restart($this->_docker_restart_default);
  631. $composer
  632. ->addService("genieacs-nbi")
  633. ->build("extra/genieacs/genieacs-nbi")
  634. ->addLinks("mongodb")
  635. ->addLinks("redis")
  636. ->addPorts("7557", "7557")
  637. ->restart($this->_docker_restart_default);
  638. $composer
  639. ->addService("genieacs-fs")
  640. ->build("extra/genieacs/genieacs-fs")
  641. ->addLinks("mongodb")
  642. ->addLinks("redis")
  643. ->addPorts("7567", "7567")
  644. ->restart($this->_docker_restart_default);
  645. $composer
  646. ->addService("genieacs-gui")
  647. ->build("extra/genieacs/genieacs-gui")
  648. ->addLinks("genieacs-nbi")
  649. ->addPorts("3001", "3000")
  650. ->restart($this->_docker_restart_default);
  651. }
  652. function addFreeradius(FileFormat2 $composer, $config = array(), $flavor = "dev")
  653. {
  654. $module = "freeradius";
  655. $version = "latest";
  656. $registry = "";
  657. $host_env_file = "";
  658. extract($config);
  659. $composer
  660. ->addService("freeradius")
  661. ->image($registry . "fd3/freeradius:" . $version)
  662. ->addLinks("mysql")
  663. ->addPorts("1812:1812/udp")
  664. ->addPorts("1813:1813/udp")
  665. ->addPorts("3799:3799/udp")
  666. ->addEnv_file("mysql." . $host_env_file)
  667. ->addEnv_file($module . "." . $host_env_file)
  668. ->addVolumes("./extra/freeradius/wsdl/code/", "/var/www/html/")
  669. ->addVolumes("./extra/freeradius/etc/cron.d", "/etc/cron.d")
  670. ->addVolumes("./extra/freeradius/etc/freeradius", "/etc/freeradius")
  671. ->addVolumes("./extra/freeradius/etc/supervisor/conf.d", "/etc/supervisor/conf.d");
  672. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module,
  673. array(
  674. "MYSQL_HOST" => "mysql",
  675. ));
  676. }
  677. function addPma(FileFormat2 $composer, $config = array())
  678. {
  679. $module = "pma";
  680. $host_env_file = "";
  681. extract($config);
  682. $composer
  683. ->addService("phpmyadmin")
  684. ->image("phpmyadmin/phpmyadmin")
  685. ->restart($this->_docker_restart_default)
  686. ->addPorts(8080, 80)
  687. ->addLinks("mysql", "db")
  688. ->addEnv_file("mysql." . $host_env_file)
  689. ->addEnv_file($module . "." . $host_env_file);
  690. $this->writeVariablesEnviroment($module . "." . $host_env_file, $module);
  691. }
  692. function addGrafana(FileFormat2 $composer, $config = array())
  693. {
  694. $module = "grafana";
  695. $host_env_file = "";
  696. extract($config);
  697. $composer
  698. ->addService($module)
  699. ->image("grafana/grafana:3.1.1")
  700. ->addLinks("mysql")
  701. ->restart($this->_docker_restart_default)
  702. ->addEnv_file("running.env")
  703. ->addEnv_file("grafana.env")
  704. ->addVolumes("./extra/statsd/grafana/lib", "/var/lib/grafana");
  705. $this->addJsonEndPoints($composer, $config);
  706. }
  707. function addJsonEndPoints(FileFormat2 $composer, $config = array())
  708. {
  709. $version = "latest";
  710. $registry = "";
  711. $host_env_file = "";
  712. extract($config);
  713. $composer
  714. ->addService("statsd")
  715. ->build("./extra/statsd/statsd")
  716. ->image($registry . "fd3/statsd:$version")
  717. ->addPorts("8125", "8125/udp")
  718. ->addLinks("mysql")
  719. ->addLinks("mongodb")
  720. ->restart($this->_docker_restart_default)
  721. ->addVolumes("./extra/statsd/statsd/statsd.config.js", "/opt/config/statsd.config.js");
  722. $composer
  723. ->addService("jsendpoint")
  724. ->build("./extra/statsd/endpoint/json")
  725. ->image($registry . "fd3/jsonep:$version")
  726. ->addVolumes("./extra/statsd/endpoint/json", "/opt/datasource")
  727. ->addLinks("jsonep_mysql")
  728. ->addLinks("jsonep_mongo")
  729. ->restart($this->_docker_restart_default);
  730. $composer
  731. ->addService("jsonep_mysql")
  732. ->build("./extra/statsd/endpoint/mysql")
  733. ->image($registry . "fd3/jsonep_mysql:$version")
  734. ->addVolumes("./extra/statsd/endpoint/mysql", "/opt/datasource")
  735. ->addLinks("mysql")
  736. ->addEnv_file("mysql." . $host_env_file)
  737. ->restart($this->_docker_restart_default);
  738. $composer
  739. ->addService("jsonep_mongo")
  740. ->build("./extra/statsd/endpoint/mongodb")
  741. ->image($registry . "fd3/jsonep_mongo:$version")
  742. ->addVolumes("./extra/statsd/endpoint/mongodb", "/opt/datasource")
  743. ->addLinks("mongodb")
  744. ->restart($this->_docker_restart_default);
  745. }
  746. function addCommandWorkers(FileFormat2 $composer, $config = array())
  747. {
  748. $version = "latest";
  749. $registry = "";
  750. extract($config);
  751. $composer
  752. ->addService("base_log_worker")
  753. ->image($registry . "fd3/base:" . $version)
  754. ->build("./base/")
  755. ->command("bin/console rabbitmq:consumer log_consumer")
  756. ->restart($this->_docker_restart_default)
  757. ->addLinks("mysql")
  758. ->addLinks("base")
  759. ->addLinks("nginx", $this->getDomain("base"))
  760. ->addEnv_file("running.env")
  761. ->addEnv_file("host.env")
  762. ->addEnv_file("base.host.env")
  763. ->addEnviroment("AMQP_KEY", "base")
  764. ->addEnviroment("SYMFONY_ENV", "prod")
  765. ->addVolumes("./base/", "/opt/base");
  766. $composer
  767. ->addService("ftth_tasklogger_worker")
  768. ->image($registry . "fd3/ftth:" . $version)
  769. ->build("./ftth/")
  770. ->command("bin/console rabbitmq:consumer flowdat_tasklogger")
  771. ->restart($this->_docker_restart_default)
  772. ->addLinks("mysql")
  773. ->addLinks("base")
  774. ->addLinks("nginx", $this->getDomain("base"))
  775. ->addEnv_file("running.env")
  776. ->addEnv_file("host.env")
  777. ->addEnv_file("ftth.host.env")
  778. ->addEnviroment("AMQP_KEY", "ftth")
  779. ->addVolumes("./ftth/", "/opt/ftth");
  780. $composer
  781. ->addService("cablemodem_tasklogger_worker")
  782. ->image($registry . "fd3/cablemodem:" . $version)
  783. ->build("./cablemodem/")
  784. ->command("bin/console rabbitmq:consumer flowdat_tasklogger")
  785. ->restart($this->_docker_restart_default)
  786. ->addLinks("mysql")
  787. ->addLinks("base")
  788. ->addLinks("nginx", $this->getDomain("base"))
  789. ->addEnv_file("running.env")
  790. ->addEnv_file("host.env")
  791. ->addEnv_file("cablemodem.host.env")
  792. ->addEnviroment("AMQP_KEY", "cablemodem")
  793. ->addVolumes("./cablemodem/", "/opt/cablemodem");
  794. $composer
  795. ->addService("ftth_command_worker")
  796. ->image($registry . "fd3/ftth:" . $version)
  797. ->build("./ftth/")
  798. ->command("bin/console rabbitmq:consumer command_consumer")
  799. ->restart($this->_docker_restart_default)
  800. ->addLinks("mysql")
  801. ->addLinks("base")
  802. ->addLinks("nginx", $this->getDomain("base"))
  803. ->addEnv_file("running.env")
  804. ->addEnv_file("host.env")
  805. ->addEnv_file("ftth.host.env")
  806. ->addEnviroment("AMQP_KEY", "ftth")
  807. ->addVolumes("./ftth/", "/opt/ftth");
  808. $composer
  809. ->addService("stats_command_worker")
  810. ->image($registry . "fd3/stats:" . $version)
  811. ->build("./stats/")
  812. ->command("bin/console rabbitmq:consumer command_consumer")
  813. ->restart($this->_docker_restart_default)
  814. ->addLinks("mysql")
  815. ->addLinks("base")
  816. ->addLinks("nginx", $this->getDomain("base"))
  817. ->addLinks("geoserver")
  818. ->addLinks("nginx", $this->getDomain("geoserver"))
  819. ->addEnv_file("running.env")
  820. ->addEnv_file("host.env")
  821. ->addEnv_file("stats.host.env")
  822. ->addEnviroment("AMQP_KEY", "stats")
  823. ->addVolumes("./stats/", "/opt/stats")
  824. ->addVolumes("./geoserver/geoserver-shapes", "/var/www/shapes");
  825. $composer
  826. ->addService("cablemodem_command_worker")
  827. ->image($registry . "fd3/cablemodem:" . $version)
  828. ->build("./cablemodem/")
  829. ->command("bin/console rabbitmq:consumer command_consumer")
  830. ->restart($this->_docker_restart_default)
  831. ->addLinks("mysql")
  832. ->addLinks("base")
  833. ->addLinks("nginx", $this->getDomain("base"))
  834. ->addEnv_file("running.env")
  835. ->addEnv_file("host.env")
  836. ->addEnv_file("cablemodem.host.env")
  837. ->addEnviroment("AMQP_KEY", "cablemodem")
  838. ->addVolumes("./cablemodem/", "/opt/cablemodem");
  839. }
  840. /**
  841. * @param FileFormat2 $composer
  842. * @param array $config
  843. */
  844. public function addGeoserver(FileFormat2 $composer, $config = array())
  845. {
  846. $version = "latest";
  847. $registry = "";
  848. extract($config);
  849. $composer
  850. ->addService("geoserver")
  851. ->image($registry . "fd3/geoserver:" . $version)
  852. ->build("./extra/geoserver/")
  853. ->restart($this->_docker_restart_default)
  854. ->addLinks("nginx", $this->getDomain("geoserver"))
  855. ->addEnv_file("running.env")
  856. ->addEnv_file("host.env")
  857. ->addVolumes("./extra/geoserver/geoserver-data/styles", "/opt/geoserver/data_dir/styles")
  858. ->addVolumes("./geoserver/geoserver-shapes", "/var/www/shapes")
  859. ->addPorts(8081, 8080);
  860. }
  861. function getDockerComposer($version = "latest", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/")
  862. {
  863. $composer = new FileFormat2("../");
  864. $base_vars = array(
  865. "version" => $version,
  866. "host_env_file" => $host_env_file,
  867. "registry" => $registry);
  868. $this->addNginx($composer, $base_vars);
  869. /**************************************************************************************/
  870. /* Apps / Web UI / Grafana / PMA */
  871. /**************************************************************************************/
  872. foreach ($this->_modules_all as $module => $env) {
  873. $method = 'add' . ucfirst($module);
  874. if (array_key_exists($module, $this->_modules) && method_exists($this, $method)) {
  875. $this->$method($composer, $base_vars);
  876. }
  877. }
  878. /**************************************************************************************/
  879. /* Servicios */
  880. /**************************************************************************************/
  881. $this->addMySql($composer, $base_vars);
  882. $composer
  883. ->addService("amqp")
  884. ->image("rabbitmq:3-management")
  885. ->restart($this->_docker_restart_default);
  886. $this->addMongDb($composer, $base_vars);
  887. $this->addRedis($composer, $base_vars);
  888. $this->addGenieACS($composer, $base_vars);
  889. $this->addFreeradius($composer, $base_vars);
  890. /**************************************************************************************/
  891. /* Workers */
  892. /**************************************************************************************/
  893. $this->addSupervisord($composer, $base_vars);
  894. $this->addCommandWorkers($composer, $base_vars);
  895. $this->addTftp($composer, $base_vars);
  896. // Geoserver
  897. $this->addGeoserver($composer, $base_vars);
  898. $this->_dObj->file("docker-compose.yml")->content($composer->render());
  899. // escribo un archivo inventory.ini por defecto para no tener que lanzar los docker
  900. $this->writeInventory($composer);
  901. }
  902. /**
  903. * Crea un array con la configuracion de los modulos.
  904. * @param InputInterface $input Contiene el input.
  905. */
  906. private function addConfigOptions(InputInterface $input)
  907. {
  908. foreach ($this->_modules as $key => $values) {
  909. if ($input->hasOption($key . "-repo") &&
  910. $input->hasOption($key . "-ref") &&
  911. $input->hasOption($key . "-build")
  912. ) {
  913. $this->_modules[$key]['repo'] = $input->getOption($key . "-repo");
  914. $this->_modules[$key]['ref'] = $input->getOption($key . "-ref");
  915. $this->_modules[$key]['build'] = $input->getOption($key . "-build");
  916. }
  917. }
  918. }
  919. /**
  920. * Crea un array con las direcciones de a clonar.
  921. */
  922. private function createGitClone()
  923. {
  924. $clone = array();
  925. $modules = array_keys($this->_modules);
  926. foreach ($modules as $name) {
  927. if (isset($this->_modules[$name]["repo"]) &&
  928. isset($this->_modules[$name]["ref"])) {
  929. $clone[$name] = array(
  930. 'url' => $this->_modules[$name]["repo"],
  931. 'branch' => $this->_modules[$name]["ref"]
  932. );
  933. }
  934. }
  935. $this->_dObj->file("git.ini")->writeIniConfig($clone);
  936. }
  937. /**
  938. * Crea un archivo conlos parametros con los que se corrio el script.
  939. * @param InputInterface $input Contiene el input
  940. * @param OutputInterface $output Contiene el output
  941. */
  942. private function createFileRunning(InputInterface $input, OutputInterface $output)
  943. {
  944. $file = array();
  945. $file ["Running"] = array("date" => gmdate('Y-m-d h:i:s'));
  946. $file ["Arguments"] = $input->getArguments();
  947. $file ["Options"] = $input->getOptions();
  948. $output->writeln("Writing " . $this->_dObj->getPath() . "/" . $this->_running_log);
  949. $this->_dObj->file($this->_running_log)->writeIniConfig($file);
  950. }
  951. /**
  952. * @param string $name Contiene el nombre del modulo.
  953. * @param string $module Contiene el nombre del modulo.
  954. * @param array $extras Contiene variables de entorno extra.
  955. * @return string|array Retorna un array con los datos de virtual host.
  956. */
  957. function getEnviromentVarialbes($name, $module, $extras = array())
  958. {
  959. $env = "";
  960. if ($module != null) {
  961. foreach ($this->_modules as $nameApp => $app) {
  962. if (isset($app['VAR_ENV']) && $nameApp == $module) {
  963. foreach ($app['VAR_ENV'] as $key => $value) {
  964. if ($key == 'VIRTUAL_HOST') {
  965. $env .= "VIRTUAL_HOST=" . $this->getDomain($module) . "\n";
  966. } else {
  967. $env .= $key . "=" . $value . "\n";
  968. }
  969. }
  970. }
  971. }
  972. }
  973. foreach ($extras as $key => $value) {
  974. $env .= $key . "=" . $value . "\n";
  975. }
  976. return $env;
  977. }
  978. /**
  979. * Crea el archivo modulo.oauth.env
  980. */
  981. private function writeOAUTH()
  982. {
  983. $oautModules = "";
  984. foreach ($this->_modules as $nameApp => $app) {
  985. if (isset($app['OAUTH']) && $app['OAUTH']) {
  986. $this->_dObj->file($nameApp . ".oauth.env")->content("");
  987. $oautModules = $oautModules . $nameApp . ",";
  988. }
  989. }
  990. $this->_ansible_vars["MODULES_INSTALL"] = substr($oautModules, 0, strlen($oautModules) - 1);
  991. }
  992. /**
  993. * Crea el archivo host.env
  994. */
  995. private function writeHostEnv()
  996. {
  997. $hostEnvConfig = $this->getHostEnv();
  998. $env_content = "";
  999. foreach ($hostEnvConfig as $var => $val) {
  1000. $env_content .= $var . "=" . $val . "\n";
  1001. }
  1002. $this->_dObj->file('host.env')->content($env_content);
  1003. }
  1004. /**
  1005. * Crea el archivo hostsDile
  1006. * @param string $config_ip Contiene la ip.
  1007. */
  1008. private function writeHostsFile($config_ip)
  1009. {
  1010. $hostConfig = $this->getHostConfig($config_ip);
  1011. $hostfile_content = "";
  1012. foreach ($hostConfig as $host => $ip) {
  1013. $hostfile_content .= $ip . "\t" . $host . "\n";
  1014. }
  1015. $this->_dObj->file("hostsFile")->content($hostfile_content);
  1016. }
  1017. /**
  1018. * Crea un archivo con las variables de entorno particulares del modulo.
  1019. * @param string $name Contiene el nombre del archivo.
  1020. * @param string $module Contiene el nombre del modulo.
  1021. * @param array $extras Contiene un array con las variables extras.
  1022. */
  1023. private function writeVariablesEnviroment($name, $module = null, $extras = array())
  1024. {
  1025. $this->_dObj->file($name)->content(
  1026. $this->getEnviromentVarialbes($name, $module, $extras));
  1027. }
  1028. /**
  1029. * Funcion que agrega el build de acuerdo en la configuracion.
  1030. * @param string $module Contiene el nombre del modulo.
  1031. * @param FileFormat2 $composer Contiene el objeto FileFormat2.
  1032. */
  1033. private function addBuild($module, FileFormat2 $composer)
  1034. {
  1035. if (isset($this->_modules[$module]['build']) &&
  1036. filter_var($this->_modules[$module]['build'], FILTER_VALIDATE_BOOLEAN)) {
  1037. try {
  1038. $composer->service($module)->build("./$module/");
  1039. } catch (ServiceNotFoundException $ignore) {
  1040. }
  1041. }
  1042. }
  1043. /**
  1044. * Funcion que setea los valores que se lean desde el archivo running.log.
  1045. * Solo se reemplazan las opciones.
  1046. * Si se toman los argumentos puede pisar el directorio de destino y a lo mejor se quiere replicar la instalacion en
  1047. * otro directorio.
  1048. * @param InputInterface $input contiene el input
  1049. */
  1050. private function setParametersFormFile(InputInterface $input)
  1051. {
  1052. $parameters = parse_ini_file($input->getArgument('dir') . "/" . $this->_running_log, true);
  1053. foreach ($parameters["Options"] as $key => $value) {
  1054. $input->setOption($key, $value);
  1055. }
  1056. }
  1057. /**
  1058. * @param string $module Contiene el nombre del modulo.
  1059. * @return string Retorna el dominio para el modulo.
  1060. */
  1061. private function getDomain($module)
  1062. {
  1063. return $module . "." . $this->_client . "." . $this->_domain;
  1064. }
  1065. /**
  1066. * @param array $modules Contiene los modulos a implementar
  1067. */
  1068. private function AddModules($modules)
  1069. {
  1070. foreach ($modules as $value) {
  1071. if (array_key_exists($value, $this->_modules_all)) {
  1072. $this->_modules[$value] = $this->_modules_all[$value];
  1073. }
  1074. }
  1075. }
  1076. /**
  1077. * Crea el archivo con las variables para ejecutar el ansible.
  1078. */
  1079. private function writeEnvVariables()
  1080. {
  1081. $tmp = "";
  1082. foreach ($this->_ansible_vars as $key => $value) {
  1083. $tmp = $tmp . "$key=$value\n";
  1084. }
  1085. $this->_dObj->file(str_replace(".log", ".env", $this->_running_log))
  1086. ->content($tmp);
  1087. }
  1088. /**
  1089. * Crea el archivo con los usuarios del sistema para que lea el ansible.
  1090. */
  1091. private function writeUserSystem()
  1092. {
  1093. $this->_dObj->file("user_system.json")
  1094. ->content(json_encode($this->_user_system));
  1095. }
  1096. /**
  1097. * Crea el archivo con las variables para ejecutar el ansible.
  1098. */
  1099. private function writeInventory(FileFormat2 $composer)
  1100. {
  1101. $tmp = "";
  1102. $all = "[all]\n";
  1103. $prefix = basename(realpath($this->directory));
  1104. foreach ($composer->getServices() as $key => $value) {
  1105. $tmp .= "[$key]\n";
  1106. $tmp .= $prefix . "_" . $key . "_1\n\n";
  1107. $all .= $prefix . "_" . $key . "_1\n";
  1108. }
  1109. $this->_dObj->file("inventory.ini")->content($tmp . $all);
  1110. }
  1111. }