Release.php 45 KB

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