Release.php 53 KB

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