Release.php 54 KB

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