Explorar o código

Agregados para la actualización de flowdat.

Instrucciones en README.md
gabriel %!s(int64=7) %!d(string=hai) anos
pai
achega
49a93120ab
Modificáronse 4 ficheiros con 165 adicións e 0 borrados
  1. 13 0
      README.md
  2. 2 0
      tools/cmd.php
  3. 67 0
      tools/src/UpdateFlowdatCommand.php
  4. 83 0
      tools/src/UpdateFlowdatModulesCommand.php

+ 13 - 0
README.md

@@ -31,3 +31,16 @@ Cada vez que se genere un módulo nuevo se debe agregar la dirección del reposi
 
 ##Extra (ADICIONAL)
     El módulo extra debe hacerse en forma manual. Tanto el branch como tag. Por ahora debe usuarse el master. 
+
+## Actualización FLOWDAT
+     Primero debemos conectarnos con el servidor para luego iniciar el dind y lanzar los comandos correspondientes.
+     Para conectarme al servidor y lanzar el dind puedo ejecutar la siguiente sentencia:
+         ssh root@base.fd3.flowdat.com -t "docker run -it -v /opt/:/opt/ -v /var/run/docker.sock:/tmp/docker.sock dind bash"
+     Cambiar los permisos de la key para conectarse a bitbucket:
+         chmod 600 /op/flowdat/keys/bitbucket.id_rsa
+     Agregar la key al ssh-agent:
+         eval $(ssh-agent); ssh-add /opt/flowdat/keys/bitbucket.id_rsa
+     Ahora debo actualizar el installer con el siguiente comando (ver las opciones con --help):
+         php cmd.php ik:update:installer vX.Y.Z 
+     Ahora debo actualizar el installer con el siguiente comando (ver las opciones con --help):
+         php cmd.php ik:update:modules ../modules.ini vX.Y.Z 

+ 2 - 0
tools/cmd.php

@@ -18,6 +18,8 @@ $app->add(new FD3\Command\ImportONUCommand());
 $app->add(new FD3\Command\MakeVersionCommand());
 $app->add(new FD3\Command\MakeSubversionCommand());
 $app->add(new FD3\ImportClient());
+$app->add(new FD3\UpdateFlowdatCommand());
+$app->add(new FD3\UpdateFlowdatModulesCommand());
 $app->add(new FD3\Command\ImportONUCommand());
 $app->add(new FD3\Command\TagVendorsCommand());
 $app->add(new FD3\Command\TagModulesCommand());

+ 67 - 0
tools/src/UpdateFlowdatCommand.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace FD3;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class UpdateFlowdatCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+            ->setName('ik:update:installer')
+            ->setDescription('Update flowdat to some release.')
+            ->setHelp('Update flowdat to some release.')
+	    ->addArgument('version', InputArgument::REQUIRED, 'Use the version expression. Ex. v0.2.1')
+	    ->addArgument('sudo', InputArgument::OPTIONAL, 'Run as sudo?.", "FALSE')
+            ->addArgument('remote', InputArgument::OPTIONAL, 'Remote repository.', 'origin')
+	    ->addArgument('tag', InputArgument::OPTIONAL, 'If release is tag then true.', 'TRUE')
+            ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $version = $input->getArgument("version");
+	$sudo = strtolower($input->getArgument("sudo")) === 'true' ? "sudo " : "";
+        $remote = $input->getArgument("remote");
+	$tag  = strtolower($input->getArgument("tag")) === 'true';
+
+	$values = explode('.', $version);
+	unset ($values[count($values) - 1]);
+	$versionOnly = implode ('.', $values);
+
+        $realpath = realpath(".");
+        $dir = dirname($realpath);
+
+        $dirBackup = $dir . "-backup";
+	if (!file_exists($dirBackup)) {
+	    $output->writeln("Creating directory " . $dirBackup);
+	    mkdir($dirBackup,  777);
+	}
+        /**
+	 * EN CASO DE ERROR Y QUE TENGA QUE VOLVER EL SISTEMA ATRAS, TENGO QUE TENER EN CUENTA CON LOS DIRECTORIOS mysql, mongo y extra. 
+	 * PORQUE EL SISTEMA ORIGINAL SIGUE ADELANTE MIENTRAS SE ACTUALIZA Y PUEDEN QUEDAR DESACTUALIZADAS LAS BASES DE DATOS Y 
+	 * DEMAS YERBAS.
+	 */ 
+	$output->writeln("Backup files on " . $dirBackup);
+	$command = $sudo . "cp -rf " . $dir . " " . $dirBackup;
+	$output->writeln("\t" . $command);
+	$resp = shell_exec ($command);
+	$output->writeln($resp);
+
+	if ($tag) {
+            $command = 'git stash && git checkout -B ' . $versionOnly . ' && git fetch ' . $remote .
+                       ' ' . $versionOnly . ':refs/tags/' . $versionOnly . ' && git merge -X theirs ' . $version;
+        } else {
+            $command = 'git stash && git checkout -B ' . $versionOnly . ' && git fetch ' . $remote . ' ' . $version;
+        }
+        $output->writeln("\t" . $command);  
+	$resp = shell_exec ($command);
+        $output->writeln($resp);  
+    }
+}
+

+ 83 - 0
tools/src/UpdateFlowdatModulesCommand.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace FD3;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class UpdateFlowdatModulesCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+            ->setName('ik:update:modules')
+            ->setDescription('Update flowdat modules to some release.')
+            ->setHelp('Update flowdat modules to some release.')
+            ->addArgument('ini_module_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
+	    ->addArgument('version', InputArgument::REQUIRED, 'Use the version expression.')
+	    ->addArgument('remote', InputArgument::OPTIONAL, 'Remote repository.', 'origin')
+	    ->addArgument('tag', InputArgument::OPTIONAL, 'If release is tag then true.', 'TRUE')
+            ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $file = $input->getArgument("ini_module_file");
+        $version = $input->getArgument("version");
+        $remote = $input->getArgument("remote");
+        $tag  = strtolower($input->getArgument("tag")) === 'true';
+
+	if ($tag) {
+            $values = explode('.', $version);
+            unset ($values[count($values) - 1]);
+            $versionOnly = implode ('.', $values);
+	} else {
+            $versionOnly = $version;
+	}
+
+        $realpath = realpath($file);
+        $dirname = dirname($realpath);
+        if (!chdir($dirname)) {
+            throw new \Exception("Can't change working directory to " . $dirname);
+        }
+
+        $realpathModule = realpath(".");
+        $dirnameModule = dirname($realpathModule);
+	
+	$content = parse_ini_file($realpath, true);
+	$error = '';
+	foreach ($content as $sec => $conf) {
+	    try {
+                $output->writeln('-------------------------------------------------------------------------------------');    
+	        $output->writeln('Module: ' . $sec);    
+	        if ($tag) {
+                    $command = 'cd  ' . $sec . ' && git stash && git checkout -B ' . $versionOnly . ' && git fetch ' . $remote . 
+	                       ' ' . $versionOnly . ':refs/tags/' . $versionOnly . ' && git merge -X theirs ' . $version;    
+                } else {
+                    $command = 'cd  ' . $sec . ' && git stash && git checkout -B ' . $versionOnly . ' && git fetch ' . $remote . ' ' . $version;
+                }
+                $output->writeln("\tComando: " . $command);  
+                $resp = shell_exec ($command);
+	        $output->writeln($resp);
+
+	        $command = "docker-compose exec " . $sec . " composer install";
+                $output->writeln("\tComando: " . $command);  
+	        $resp = shell_exec ($command);
+	        $output->writeln($resp);
+	    } catch (\Throwable $t) {
+		$error .= $t->getTraceAsString() . "\n";
+            }  
+	}
+	if (strlen($error) > 0) {
+            $output->writeln("SE PRODUJERON LOS SIGUIENTES ERRORES: \n" . $error);
+	    /**
+	     * SE PUEDEN PARAR LOS DOCKERS, BORRAR LOS DIRECTORIOS DE LOS MÓDULOS Y COPIARLOS DESDE EL BACKUP.
+	     * TENER CUIDADO CON LOS DIRECTORIOS mysql, mongo y extra PORQUE PUEDE AVANZAR DESDE EL BACKUP.
+	     */ 
+        }
+    }
+}
+