gabriel 6 lat temu
rodzic
commit
20273f3f15

+ 20 - 4
installerSupport.sh

@@ -82,8 +82,8 @@ then
     echo -e "Comando para instalar flowdat."
     echo -e "Si no se pasan parametros se ejecuta el script completo preguntando los datos necesarios"
     echo -e "Parametros:"
-    echo -e "    --develop    Si es 1, instala el codigo fuente. NUNCA UTILIZAR EN CLIENTES."
-    echo -e "    --cliente    Nombre del cliente que va a instalar. Se utiliza como dominio. NUNCA UTILIZAR EN CLIENTES."
+    echo -e "    --develop    Si es 1, instala el codigo fuente. ${RED}${BOLD}NUNCA UTILIZAR EN CLIENTES${NOCOLOR}."
+    echo -e "    --cliente    Nombre del cliente que va a instalar. Se utiliza como dominio."
     echo -e "    --ansible    Ejecuta la linea del ansible. Debe pasar el directorio donde se encuentra el playbook."
     exit 1
 fi
@@ -124,7 +124,7 @@ DIRINSTALL=${DIRINSTALLDEFAULT}
 echo -e "Ingrese el directorio absoluto de instalacion: (default: ${BOLD}${DIRINSTALLDEFAULT}${NOCOLOR})"
 read DIRINSTALL
 if [ "${DIRINSTALL}" = "" ];
-  then
+then
       DIRINSTALL=${DIRINSTALLDEFAULT}
 fi
 
@@ -206,6 +206,8 @@ then
         echo -e "    Puede ingresar el comando que desee ejecutar."
         read COMMAND
     else
+        echo -e "${BLUE}###############################################################${NOCOLOR}"
+        echo -e "Creando los archivos de instalacion."
         COMMAND=""
     fi
     if [ "${COMMAND}" = "" ];
@@ -293,6 +295,16 @@ then
             fi
         fi
     	fcCheckExecution
+    else
+    	echo -e "${BLUE}###############################################################${NOCOLOR}"
+        echo -e "Reconfigurando el nginx"
+        eval ${DOCKERFIXNGINX}
+    	fcCheckExecution
+        ###################################################################
+    	echo -e "${BLUE}###############################################################${NOCOLOR}"
+        echo -e "Registrando el servicio de docker"
+        eval ${DOCKERSERVICE}
+    	fcCheckExecution
     fi
     ###################################################################
     echo -e ""
@@ -385,7 +397,6 @@ then
             LSFULLCHAIN=`ls -td /etc/letsencrypt/archive/${CLIENTNAME}.${DOMAINNAME}/fullchain*.pem`
             LSPRIVKEY=`ls -td /etc/letsencrypt/archive/${CLIENTNAME}.${DOMAINNAME}/privkey*.pem`
 
-
             for var in ${LSCERT}
             do
                 LSCERT=${var}
@@ -418,6 +429,9 @@ fi
 ###################################################################
 if [ "$DEVELOP" = "1" ];
 then
+    echo -e "${BLUE}###############################################################${NOCOLOR}"
+    echo -e ""
+    echo -e ""
     echo -e ""
     echo -e ""
     echo -e "Creando archivo de ejecucion ansible"
@@ -427,6 +441,8 @@ then
     echo -e "Desea modificar el archivo? Default ${BOLD}NO${NOCOLOR} presione ${BOLD}enter${NOCOLOR}. En caso contrario ingrese las lineas del archivo a utilizar. "
     read COMMAND
 else
+    echo -e "${BLUE}###############################################################${NOCOLOR}"
+    echo -e "Ejecutando el ansible"
     COMANDO=""
 fi
 if [ "${COMMAND}" = "" ];

+ 1 - 174
tools/playbookUpdateSupport.yml

@@ -7,120 +7,6 @@
     - name: Docker mysql up
       command: "docker-compose up -d mysql"
 
-- name: Configure mysql database. Tag=configure_mysql
-  hosts: mysql
-  connection: docker
-  gather_facts: no
-  tags: configure_mysql
-  tasks:
-    - name: Wait for mysql be ready
-      wait_for:
-        host: 127.0.0.1
-        port: 3306
-        state: started
-        delay: 5
-        connect_timeout: 15
-        timeout: 360
-
-    - name: Create database fd_session
-      mysql_db:
-        name: fd_session
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database freeradius
-      mysql_db:
-        name: freeradius
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database grafana
-      mysql_db:
-        name: grafana
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database statsd_db
-      mysql_db:
-        name: statsd_db
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database base
-      mysql_db:
-        name: fd3_base
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database ftth
-      mysql_db:
-        name: fd3_ftth
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database stats
-      mysql_db:
-        name: fd3_stats
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database cablemodem
-      mysql_db:
-        name: fd3_cablemodem
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database Radius
-      mysql_db:
-        name: fd3_radius
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database dhcp
-      mysql_db:
-        name: fd3_dhcp
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - name: Create database kea
-      mysql_db:
-        name: kea
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: present
-
-    - copy:
-        src: "{{ playbook_dir }}/freeradius_schema.sql"
-        dest: /tmp/freeradius_schema.sql
-
-    - name: Create freeradius MySQL schema
-      mysql_db:
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: import
-        name: freeradius
-        target: "/tmp/freeradius_schema.sql"
-
-    - name: Create user iksop
-      mysql_user:
-        name: 'iksop'
-        password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        priv: '*.*:ALL'
-        state: present
-
-    - copy:
-        src: "{{ playbook_dir }}/mysql_scripts.sql"
-        dest: /tmp/mysql_scripts.sql
-
-    - name: Replace password mysql_scripts.sql
-      shell: "sed -i -- 's/#password#/{{ lookup('env', 'MYSQL_PASSWORD') }}/g' /tmp/mysql_scripts.sql"
-
-    - name: Run SQL commands against DB to create table
-      mysql_db:
-        login_password: "{{ lookup('env', 'MYSQL_PASSWORD') }}"
-        state: import
-        name: fd_session
-        target: "/tmp/mysql_scripts.sql"
-
 - name: Launch docker for amqp. Tag=start_amqp
   hosts: 127.0.0.1
   connection: local
@@ -170,46 +56,9 @@
       with_items: "{{ lookup('env', 'MODULES_INSTALL').split(',') }}"
 
     - name: Create oauth client
-      shell: "bin/console oauth:client:createRedirects {{ uris }} > oauth.data.log"
-      args:
-        executable: /bin/bash
-
-    - name: Update variable usersetting
-      set_fact:
-        usersetting: "{{ lookup('file', '{{ playbook_dir }}/user_system.json')|from_json }}"
-
-    - name: Create user iksop
-      shell: "bin/console user:create {{ item.user }} {{ item.email }} {{ item.password }} {{ item.tenancy }} {{ item.extra }}"
-      args:
-        executable: /bin/bash
-      with_items: "{{ usersetting.users }}"
-
-    - name: Promote users to ADMIN
-      shell: " bin/console fos:user:promote admin ROLE_ADMIN"
-      args:
-        executable: /bin/bash
-
-    - name: Promote users to IKSOP
-      shell: " bin/console fos:user:promote iksop ROLE_SUPER_ADMIN"
-      args:
-        executable: /bin/bash
-
-    - name: Copy file oauth.data.log to host
-      fetch:
-        src: /opt/base/oauth.data.log
-        dest: /tmp/
-        flat: yes
-
-- name: Configure oauth data for other container. Tag=configure_oauth
-  hosts: 127.0.0.1
-  connection: local
-  tags: configure_oauth
-  tasks:
-    - name: "Add outh client id"
-      shell:  "cp /tmp/oauth.data.log {{ item }}.oauth.env"
+      shell: "bin/console oauth:client:updateRedirects {{ uris }} "
       args:
         executable: /bin/bash
-      with_items: "{{ lookup('env', 'MODULES_INSTALL').split(',') }}"
 
 - name: "Launch docker's. Tag=launch_dockers"
   hosts: 127.0.0.1
@@ -248,28 +97,6 @@
     - name: "Make static assets"
       shell: "bin/console assets:install web"
 
-  # Generate self-signed cert files for Nginx (intended for development, please replace with proper ones)
-- name: "Generate self-signed cert files for Nginx"
-  hosts: 127.0.0.1
-  connection: local
-  tags: self_cert
-  tasks:
-    - name: "Make sure certs dir exists"
-      shell: "mkdir -p /opt/flowdat/certs"
-    - name: "Generate self-signed certs for Nginx"
-      shell: "openssl req -x509 -nodes -batch -days 365 -newkey rsa:2048 -keyout /opt/flowdat/certs/privkey.pem -out /opt/flowdat/certs/fullchain.pem -subj '/C=AR/ST=Santa Fe/L=Rosario/O=Interlink/OU=R&D/CN=*.{{ lookup('env','CLIENT') }}.{{ lookup('env','DOMAIN') }}/emailAddress=idev@interlink.com.ar'"
-
-- name: "Copy certs dir to nginx/certs"
-  hosts: 127.0.0.1
-  connection: local
-  tags: copy_cert
-  tasks:
-    - name: "Create certs directory"
-      shell: "mkdir -p /opt/flowdat/nginx/certs"
-    - name: "Copy certs directory"
-      shell: "cp -nr /opt/flowdat/certs/* /opt/flowdat/nginx/certs"
-
-
 - name: "Run up all. Tag=up_all"
   hosts: 127.0.0.1
   connection: local

+ 1 - 1
tools/src/FixNginx.php

@@ -36,7 +36,7 @@ class FixNginx extends Command
         }
 
         if ($modules != null) {
-            $dirReal = $dirReal . "/extra/nginx/conf.d/";
+            $dirReal = $dirReal . "/nginx/conf.d/";
             $dirOpen = opendir($dirReal);
             while (false !== ($entrada = readdir($dirOpen))) {
                 if ($entrada != ".." && $entrada != ".") {

+ 30 - 11
tools/src/ReleaseImages.php

@@ -307,7 +307,7 @@ class ReleaseImages extends Command
             // cargo las fuentes a clonar
             $this->createGitClone($input);
             // creo el archivo docker-compose.yml
-            $this->getDockerComposer($version, "host.env", "docker.infra.flowdat.com/");
+            $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
@@ -390,9 +390,10 @@ class ReleaseImages extends Command
     /**
      * @param InputInterface $input InputInterface
      * @param OutputInterface $output OutputInterface
+     * @param bool $update
      * @return string Return all modules selected.
      */
-    public function selectInstallModules(InputInterface $input, OutputInterface $output)
+    public function selectInstallModules(InputInterface $input, OutputInterface $output, $update = false)
     {
         $modules = [];
         $output->writeln("Seleccione los módulos que desea instalar:");
@@ -408,13 +409,26 @@ class ReleaseImages extends Command
                         implode(",", $value['DEPENDS']) . "</blue>");
                 } else {
                     $helper = $this->getHelper('question');
-                    $def = "(<bold>Y</bold>/n)";
+                    $defaultQuestionYes = "(<bold><green>Y</green></bold>/n)";
+                    $defaultQuestionNo = "(y/<bold><red>N</red></bold>)";
+                    $def = $defaultQuestionYes;
                     if (!$value["DEFAULTINSTALATION"]) {
-                        $def = "(y/<bold>N</bold>)";
+                        $def = $defaultQuestionNo;
+                    }
+                    if ($value['INSTALLED']) {
+                        $installed = " <red>*** MODULO YA INSTALADO ***</red>   ";
+                        if ($update) {
+                            $def = $defaultQuestionYes;
+                        }
+                    } else {
+                        $installed = "";
+                        if ($update) {
+                            $def = $defaultQuestionNo;
+                        }
                     }
-                    $installed = $value['INSTALLED'] ? " <red>*** MODULO YA INSTALADO ***</red>   " : "";
                     $question = new ConfirmationQuestion($installed . (isset($value['HELP']) ? ($value['HELP'] . ". ") : "") .
-                        strtoupper($name) . "? $def ", "(<bold>Y</bold>/n)" == $def);
+                        strtoupper($name) . "? $def ",
+                        $defaultQuestionYes == $def);
                     if ($helper->ask($input, $output, $question)) {
                         $modules [] = $name;
                         $value['REQUIRED'] = true;
@@ -432,13 +446,18 @@ class ReleaseImages extends Command
     function getHostEnv()
     {
         $resp = array();
+        // agrego todos los host. Esto se necesita para cuando no se instala completo
+        foreach ($this->_modules_all as $key => $values) {
+            if (isset($values['HOST_ENV']) && $values['HOST_ENV']) {
+                $resp ["HOST_" . strtoupper($key)] = "";
+            }
+        }
+        // agrego las url solo a los que voy a instalar
         foreach ($this->_modules as $key => $values) {
             if (isset($values['HOST_ENV']) && $values['HOST_ENV']) {
                 $resp ["HOST_" . strtoupper($key)] = $this->getDomain($key);
             }
-
         }
-
         return $resp;
     }
 
@@ -453,7 +472,7 @@ class ReleaseImages extends Command
         return $resp;
     }
 
-    function getDockerComposer($version = "latest", $host_env_file = "host.env", $registry = "docker.infra.flowdat.com/")
+    function getDockerComposer($version = "latest", $registry = "docker.infra.flowdat.com/")
     {
         $composer = new FileFormat("../", "3.7");
         $this->registerVolumes($composer);
@@ -463,7 +482,7 @@ class ReleaseImages extends Command
 
         $base_vars = array(
             "version" => $version,
-            "host_env_file" => $host_env_file,
+            "host_env_file" => $this->_host_env,
             "registry" => $registry);
 
         $ip = explode(".", $this->_network_ip);
@@ -645,7 +664,7 @@ class ReleaseImages extends Command
         foreach ($hostEnvConfig as $var => $val) {
             $env_content .= $var . "=" . $val . "\n";
         }
-        $this->_dObj->file('host.env')->content($env_content);
+        $this->_dObj->file($this->_host_env)->content($env_content);
     }
 
     /**

+ 2 - 2
tools/src/UpdateImages.php

@@ -95,7 +95,7 @@ class UpdateImages extends ReleaseImages
             $this->directory = realpath($this->directory) . "/";
             $this->checkInstalledModules();
             // seteo todos los modulos a instalar por defecto
-            $modules = $this->selectInstallModules($input, $output);
+            $modules = $this->selectInstallModules($input, $output, true);
             $this->AddModules(explode(",", $modules));
             $this->setParametersFormFile($input);
             $this->_domain = $input->getOption("domain");
@@ -131,7 +131,7 @@ class UpdateImages extends ReleaseImages
             // creo el archivo de log de como se ejecuto
             $this->createFileRunning($input, $output);
             // creo el archivo docker-compose.yml
-            $this->getDockerComposer($version, "host.env", "docker.infra.flowdat.com/");
+            $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

+ 168 - 0
updateSupport.sh

@@ -0,0 +1,168 @@
+#!/usr/bin/env bash
+
+#################################################################
+# COLORS
+BOLD="\e[1m"
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+BLUE="\033[0;34m"
+NOCOLOR="\033[0m"
+
+
+###################################################################
+ROOT=$(id -u)
+if [ "$ROOT" != "0" ];
+then
+    echo -e "${RED} Este comando debe ejecutarse como root.${NOCOLOR}"
+    exit 0
+fi
+###################################################################
+DEVELOP=0
+CLIENT=""
+HELP=0
+ANSIBLE=0
+for VAR in "$@"
+do
+    KEY="$(cut -d'=' -f1 <<<"$VAR")"
+    VALUE="$(cut -d'=' -f2 <<<"$VAR")"
+    if [ "$KEY" = "--help" ] || [ "$VAR" = "-h" ];
+    then
+        HELP=1
+    fi
+    if [ "$KEY" = "--ansible" ];
+    then
+        ANSIBLE=1
+    fi
+    if [ "$KEY" = "--cliente" ];
+    then
+        CLIENT=${VALUE}
+    fi
+done
+
+if [ "$HELP" = "1" ];
+then
+    echo -e "Comando para instalar flowdat."
+    echo -e "Si no se pasan parametros se ejecuta el script completo preguntando los datos necesarios"
+    echo -e "Parametros:"
+    echo -e "    --cliente    Nombre del cliente que va a instalar. Se utiliza como dominio. NUNCA UTILIZAR EN CLIENTES."
+    echo -e "    --ansible    Ejecuta la linea del ansible. Debe pasar el directorio donde se encuentra el playbook."
+    exit 1
+fi
+
+###################################################################
+fcGetYesNo() {
+    while true;
+    do
+        read VALUEYESNO
+        if [ "$VALUEYESNO" = "" ] || [ "$VALUEYESNO" = "y" ] || [ "$VALUEYESNO" = "Y" ] || [ "$VALUEYESNO" = "yes" ] || [ "$VALUEYESNO" = "YES" ];
+        then
+            VALUEYESNO=1
+            return
+        fi
+        if [ "$VALUEYESNO" = "n" ] || [ "$VALUEYESNO" = "N" ] || [ "$VALUEYESNO" = "no" ] || [ "$VALUEYESNO" = "NO" ];
+        then
+            VALUEYESNO=0
+            return
+        fi
+    done
+}
+
+fcCheckExecution () {
+    if [ $? -eq 0 ];
+    then
+        return
+    else
+        echo -e "${RED}Algunos comandos no se ejecutaron correctamente.${NOCOLOR}"
+        exit 0
+    fi
+}
+###################################################################
+DIRINSTALLDEFAULT="/opt/flowdat"
+FILEANSIBLE="#!/bin/bash\neval \$(cat mysql.host.env running.env) ansible-playbook -i inventory.ini -u root playbook.yml "
+###################################################################
+
+DIRINSTALL=${DIRINSTALLDEFAULT}
+echo -e "Ingrese el directorio absoluto de instalacion: (default: ${BOLD}${DIRINSTALLDEFAULT}${NOCOLOR})"
+read DIRINSTALL
+if [ "${DIRINSTALL}" = "" ];
+then
+      DIRINSTALL=${DIRINSTALLDEFAULT}
+fi
+
+cd ${DIRINSTALL}
+if [ "$ANSIBLE" = "0" ];
+then
+    echo -e ""
+    echo -e ""
+    echo -e ""
+    echo -e ""
+    echo -e "${BLUE}###############################################################${NOCOLOR}"
+    echo -e "Parando las imagenes actauales"
+    docker stop $(docker ps -q)
+    sleep 20
+    echo -e "Recuperando las nuevas imagenes"
+    docker-compose pull
+    ###################################################################
+    if [ "$CLIENT" = "" ];
+    then
+        echo -e "Ingrese el nombre del cliente para la instalacion. Ej.: ${BOLD}galvez${NOCOLOR}"
+        read CLIENTNAME
+    else
+        CLIENTNAME=${CLIENT}
+    fi
+    DOMAINNAME="flowdat.net"
+    echo -e ""
+    echo -e ""
+    echo -e "Las url seran ${GREEN}base.${CLIENTNAME}.${DOMAINNAME}${NOCOLOR}. Si esto NO es correcto aborte la ejecucion con ctrl+c"
+    echo -e ""
+    echo -e ""
+    echo -e "${BLUE}###############################################################${NOCOLOR}"
+    echo -e "Ingresando al directorio ${BOLD}${DIRINSTALL}${NOCOLOR}"
+    cd ${DIRINSTALL}
+    fcCheckExecution
+    ###################################################################
+    BRANCH=""
+    echo -e "Ingrese la rama a instalar. (default: ${BOLD}latest${NOCOLOR})"
+    read BRANCH
+    if [ "$BRANCH" = "" ];
+    then
+        BRANCH="latest"
+    fi
+    fcCheckExecution
+    ###################################################################
+    DOCKERIMAGEINSTALLERBASE="docker.infra.flowdat.com/fd3/installer:$BRANCH"
+    DOCKERIMAGEINSTALLER="dind"
+    DOCKERMAKEINSTALL="docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock ${DOCKERIMAGEINSTALLER} make:updateImages ${DIRINSTALL} --client=${CLIENTNAME} --domain=${DOMAINNAME} --branch=${BRANCH} --develop=${DEVELOP}"
+    DOCKERFIXNGINX="docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock ${DOCKERIMAGEINSTALLER} fix:nginx ${DIRINSTALL}"
+    ###################################################################
+    docker pull ${DOCKERIMAGEINSTALLERBASE}
+    docker tag ${DOCKERIMAGEINSTALLERBASE} ${DOCKERIMAGEINSTALLER}
+    ###################################################################
+    echo -e "${BLUE}###############################################################${NOCOLOR}"
+    echo -e "Creando los archivos de instalacion."
+    COMMAND=""
+    eval ${DOCKERMAKEINSTALL}
+    fcCheckExecution
+    ###################################################################
+#    echo -e ""
+#    echo -e ""
+#    echo -e ""
+#    echo -e ""
+#    echo -e "${BLUE}###############################################################${NOCOLOR}"
+#    echo -e "Reconfigurando el nginx"
+#    eval ${DOCKERFIXNGINX}
+#    fcCheckExecution
+fi
+###################################################################
+echo -e ""
+echo -e ""
+echo -e ""
+echo -e ""
+echo -e "${BLUE}###############################################################${NOCOLOR}"
+echo -e "Ejecutando el ansible"
+echo -e "${FILEANSIBLE}" > ${DIRINSTALL}/ansible.run
+docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock dind ansible ${DIRINSTALL}
+echo -e "Borrando las imagenes que no se necesitandb."
+docker system prune -f
+fcCheckExecution
+exit 1