123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace FD3;
- use Docker\Composer\FileFormat;
- use Docker\Composer\NetworkConfig;
- use Docker\Composer\ServiceNotFoundException;
- use Dotenv\Dotenv;
- use FD3\Services\Amqp;
- use FD3\Services\Api;
- use FD3\Services\Base;
- use FD3\Services\Base_log;
- use FD3\Services\Cablemodem;
- use FD3\Services\Cablemodem_cmd;
- use FD3\Services\Cablemodem_task;
- use FD3\Services\Dhcp;
- use FD3\Services\Dhcp_task;
- use FD3\Services\Freeradius;
- use FD3\Services\Ftth;
- use FD3\Services\Ftth_cmd;
- use FD3\Services\Ftth_task;
- use FD3\Services\Geoserver;
- use FD3\Services\Jsendpoint;
- use FD3\Services\Jsonep_mongo;
- use FD3\Services\Jsonep_mysql;
- use FD3\Services\Kea;
- use FD3\Services\Mongodb;
- use FD3\Services\Mysql;
- use FD3\Services\Nginx;
- use FD3\Services\Pma;
- use FD3\Services\Radius;
- use FD3\Services\Radius_task;
- use FD3\Services\Redis;
- use FD3\Services\Stats;
- use FD3\Services\Stats_cmd;
- use FD3\Services\Statsd;
- use FD3\Services\Supervisord;
- use FD3\Services\Swagger;
- use FD3\Services\Tftp;
- use FD3\Services\Minio;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Exception\LogicException;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Question\ConfirmationQuestion;
- use Symfony\Component\Console\Question\Question;
- use Symfony\Component\Yaml\Yaml;
- class UpdateImages extends ReleaseImages
- {
- /**
- * Constructor.
- *
- * @param string|null $name The name of the command; passing null means it must be set in configure()
- *
- * @throws LogicException When the command name is empty
- */
- public function __construct($name = null)
- {
- parent::__construct($name);
- }
- protected function configure()
- {
- parent::configure();
- $this
- ->setName('make:updateImages')
- ->setDescription('Update an install.')
- ->setHelp('This command allows you to update an installation...');
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- try {
- $this->colors($output);
- if (file_exists($this->directory . "/" . $this->_running_env)) {
- $output->writeln("<red>No se pudo encontrar el archivo " . $this->_running_env . " de la instalacion anterior.\N" .
- "ESTE ARCHIVO NO SE PUEDE TRAER DE OTRA INSTALACION.\n " .
- "NO SE PUEDE ACTUALIZAR.</red>");
- exit();
- }
- if (file_exists(realpath($this->directory) . "/" . $this->_running_log)) {
- $output->writeln("<red>No se pudo encontrar el archivo " . $this->_running_log . " de la instalacion anterior.\n" .
- "ESTE ARCHIVO NO SE PUEDE TRAER DE OTRA INSTALACION.\n " .
- "NO SE PUEDE ACTUALIZAR.</red>");
- exit();
- }
- $this->directory = $input->getArgument('dir');
- if (!is_dir($this->directory)) {
- mkdir($this->directory, 0777, true);
- }
- $this->directory = realpath($this->directory) . "/";
- $this->checkInstalledModules();
- // seteo todos los modulos a instalar por defecto
- $modules = $this->selectInstallModules($input, $output, true);
- $this->AddModules(explode(",", $modules));
- $this->setParametersFormFile($input);
- $this->_domain = $input->getOption("domain");
- $this->_client = $input->getOption("client");
- $this->_develop = $input->getOption("develop") === "true" || $input->getOption("develop") === "1";
- $this->_network_ip = $input->getOption("ip_network_begin");
- if (!$this->_client) {
- $this->_client = basename(realpath($this->directory));
- }
- $version = $input->getOption("branch");
- $internal_user_id = 2;
- $this->_ansible_vars["DOMAIN"] = $this->_domain;
- $this->_ansible_vars["CLIENT"] = $this->_client;
- $this->_ansible_vars["CMD_USERNAME"] = $this->_user_system['users'][$internal_user_id]['user'];
- $this->_ansible_vars["CMD_PASSWORD"] = $this->_user_system['users'][$internal_user_id]['password'];
- $this->_ansible_vars["ENV_LIST"] = "prod,dev,test";
- $this->_ansible_vars["API_CIDR"] = "172.16.0.0/16";
- $this->_ansible_vars["IK_SUBRED"] = "200.50.160.0/21";
- $this->_ansible_vars["MYSQL_ROOT_PASSWORD"] = $this->_mysql_root_pass;
- $this->_add_nginx_links = true;
- $dObj = new DevOps\FileSystem(realpath($this->directory));
- $dObj->dirExists()->realpath();
- $this->_dObj = $dObj;
- $path = $dObj->dirExists()->realpath()->getPath();
- // hosts file not exists, then build it
- if (file_exists($path . "/hosts") === false) {
- copy(getcwd() . "/hosts", $path . "/hosts");
- $this->public_ip = $input->getOption('public_ip');
- while (!filter_var($this->public_ip, FILTER_VALIDATE_IP)) {
- $helper = $this->getHelper('question');
- $question = new Question('IP pública del cliente para acceder a Flowdat ? (Default: 127.0.0.1)', '127.0.0.1');
- $this->public_ip = $helper->ask($input, $output, $question);
- }
- $this->addHosts();
- }
- // agrego las opciones del input a la configuracion _modues
- $this->addConfigOptions($input, $version);
- // creo el archivo de log de como se ejecuto
- $this->createFileRunning($input, $output);
- // cargo las fuentes a clonar
- $this->createGitClone($input);
- // creo el archivo docker-compose.yml
- $this->getDockerComposer($version, "docker.infra.flowdat.com/");
- // escribo el archivo de host
- $this->writeHostsFile($input->getOption("host_ip"));
- // escribo el archivo con las variables de entorno
- $this->writeHostEnv();
- // escribo los archivo oauth
- $this->writeOAUTH();
- // escribo un archivo con variables para ansible
- $this->writeEnvVariables();
- $dObj->file('install.yml')->content(
- yaml::dump(array(
- "install_dir" => realpath($this->directory),
- 'docker_apps' => "base," . implode(",", $this->_ansible_vars),
- 'domain' => $this->_domain,
- )
- )
- );
- $dObj->file('ansible.cfg')->content(
- "[defaults]\n" .
- "inventory=inventory.ini\n" .
- "gather_timeout=30\n"
- );
- // copio el playbook
- copy(getcwd() . "/playbookUpdateSupport.yml", $path . "/playbook.yml");
- // KEA selected for install, copy the file get_kea_files.sh
- // otherwise delete the file if exists in the path
- $keaFile = "{$path}/get_kea_files.sh";
- if ($this->isModuleAvailable(new Kea())) {
- copy(getcwd() . "/get_kea_files.sh", $keaFile);
- } elseif (file_exists($keaFile) === true) {
- unlink($keaFile);
- }
- copy(getcwd() . "/get_supervisord_files.sh", $path . "/get_supervisord_files.sh");
- } catch (\Throwable $t) {
- $output->writeln($t->getTraceAsString());
- } finally {
- $this->_dObj = null;
- $this->_modules = null;
- }
- }
- /**
- * Marca los modulos que ya se encuentran instalados.
- */
- protected function checkInstalledModules()
- {
- $lines = file($this->directory . "/" . $this->_running_env, FILE_IGNORE_NEW_LINES);
- foreach ($lines as $line) {
- if (strpos($line, "MODULES_INSTALL") === 0) {
- $modules = explode(",", explode("=", $line)[1]);
- foreach ($modules as $mod) {
- foreach ($this->_modules_all as $name => $value) {
- if ($name == $mod || $name == "base") {
- $value["INSTALLED"] = true;
- $this->_modules_all[$name] = $value;
- }
- }
- }
- }
- }
- }
- /**
- * Crea el archivo modulo.oauth.env
- */
- protected function writeOAUTH()
- {
- $oautModules = "";
- $arrNotFound = [];
- $found = "";
- foreach ($this->_modules as $nameApp => $app) {
- if (isset($app['OAUTH']) && $app['OAUTH']) {
- if (!file_exists($this->directory . $nameApp . ".oauth.env")) {
- $oautModules = $oautModules . $nameApp . ",";
- $arrNotFound[] = $nameApp;
- } else if ($found == "") {
- $found = $nameApp;
- $oautModules = $oautModules . $nameApp . ",";
- } else {
- $oautModules = $oautModules . $nameApp . ",";
- }
- }
- }
- // copio los archivos oauth de los nuevos modulos
- if (count($arrNotFound) > 0) {
- $content = file_get_contents($this->directory . $found . ".oauth.env");
- foreach ($arrNotFound as $nameApp) {
- $this->_dObj->file($nameApp . ".oauth.env")->content($content);
- }
- }
- $this->_ansible_vars["MODULES_INSTALL"] = "base," . substr($oautModules, 0, strlen($oautModules) - 1);
- }
- }
|