Pārlūkot izejas kodu

Merge branch 'dind-test' of bitbucket.org:ikflowdat/installer

Conflicts:
	tools/playbook.yml
	tools/src/Release.php
iksop 7 gadi atpakaļ
vecāks
revīzija
254216ed2b
3 mainītis faili ar 62 papildinājumiem un 25 dzēšanām
  1. 1 6
      tools/mysql_scripts.sql
  2. 26 9
      tools/playbook.yml
  3. 35 10
      tools/src/Release.php

+ 1 - 6
tools/mysql_scripts.sql

@@ -6,9 +6,4 @@ CREATE TABLE IF NOT EXISTS `fd_session`.`sessions` (
   `sess_time` int(10) unsigned NOT NULL,
   `sess_lifetime` mediumint(9) NOT NULL,
   PRIMARY KEY (`sess_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-
-INSERT INTO `fd3_base`.`tenancy`
-(`id`, `name`, `enabled`) VALUES
-(1,    'Base', 1),
-(2,    'Inicial', 1);
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

+ 26 - 9
tools/playbook.yml

@@ -99,6 +99,18 @@
         priv: '*.*:ALL'
         state: present
 
+    - name: Copy file mysql_scripts.sql
+      copy:
+        src: "{{ playbook_dir }}/mysql_scripts.sql"
+        dest: /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 module base. Tag=start_base
   hosts: 127.0.0.1
   connection: local
@@ -134,15 +146,20 @@
       args:
         executable: /bin/bash
 
-    - name: Create user iksop
-      shell: "bin/console user:create iksop soporte@interlink.com.ar gran5pe --super-admin 1"
-      args:
-        executable: /bin/bash
+    - name: Copy file user_system.json
+      copy:
+        src: "{{ playbook_dir }}/user_system.json"
+        dest: /tmp/user_system.json
+
+    - name: Update variable usersetting
+      set_fact:
+        usersetting: "{{ lookup('file','/tmp/user_system.json')|from_json }}"
 
-    - name: Create user admin
-      shell: "bin/console user:create admin admi@interlink.com.ar admin 2"
+    - 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"
@@ -151,9 +168,9 @@
 
     - name: Copy file oauth.data.log to host
       fetch:
-          src: /opt/base/oauth.data.log
-          dest: /tmp/
-          flat: yes
+        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

+ 35 - 10
tools/src/Release.php

@@ -50,9 +50,9 @@ class Release extends Command
      */
     private $_domain;
     /**
-     * @var string Contiene el dominio que se agrega al final de la linea.
+     * @var string Contiene el nombre del cliente.
      */
-    private $_domain_behind;
+    private $_client;
     /**
      * @var array Contiene todos los modulos para la instalacion.
      */
@@ -61,6 +61,10 @@ class Release extends Command
      * @var array Contiene la configuracion de los modulos.
      */
     private $_modules;
+    /**
+     * @var array Contiene los usuarios que van a poder acceder al sistema.
+     */
+    private $_user_system;
 
     /**
      * Constructor.
@@ -76,8 +80,13 @@ class Release extends Command
         $this->_mysql_user = "iksop";
         $this->_mysql_pass = "235r2342gtfsw";
         $this->_mysql_root_pass = "235r2342gtfsw";
-        $this->_domain_behind = "flowdat.com";
         $this->_docker_restart_default = "on-failure:10";
+        $this->_user_system = ['users' =>
+            [
+                ['user' => 'admin', 'password' => 'admin', 'tenancy' => 1, 'email' => 'soporte@interlink.com.ar', 'extra' => '--super-admin '],
+                ['user' => 'iksop', 'password' => 'gran5pe', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => ''],
+                ['user' => 'interno', 'password' => 'gran5pe1nterno', 'tenancy' => 2, 'email' => 'admin@interlink.com.ar', 'extra' => '']
+            ]];
         $this->_modules = array();
         $this->_ansible_vars = array();
         $this->_modules_all = array(
@@ -236,13 +245,17 @@ class Release extends Command
             }
             $this->_domain = $input->getOption("domain");
             $this->_client = $input->getOption("client");
-	        if (!$this->_client) {
+
+            if (!$this->_client) {
                 $this->_client = basename(realpath($dir));
-	        }
+            }
+
             $docker_tag = $input->getOption("docker-tag");
 
             $this->_ansible_vars["DOMAIN"] = $this->_domain;
             $this->_ansible_vars["CLIENT"] = $this->_client;
+            $this->_ansible_vars["CMD_USERNAME"] = $this->_user_system['users']['user'];
+            $this->_ansible_vars["CMD_PASSWORD"] = $this->_user_system['users']['password'];
 
             $dObj = new DevOps\FileSystem(realpath($dir));
             $dObj->dirExists()->realpath();
@@ -264,6 +277,8 @@ class Release extends Command
             $this->writeOAUTH();
             // escribo un archivo con variables para ansible
             $this->writeEnvVariables();
+            // escribo un archivo con los usuarios del sistema
+            $this->writeUserSystem();
 
             $dObj->file('install.yml')->content(
                 yaml::dump(array(
@@ -285,8 +300,6 @@ class Release extends Command
         } catch (\Throwable $error) {
             var_dump($error->getTraceAsString(), $error->getCode(), $error->getMessage());
         } finally {
-            $this->_OAUTH_CLIENT_SECRET = null;
-            $this->_OAUTH_CLIENT_ID = null;
             $this->_dObj = null;
             $this->_modules = null;
         }
@@ -744,6 +757,7 @@ class Release extends Command
             ->addLinks("base")
             ->addLinks("amqp")
             ->addLinks("nginx", $this->getDomain("base"))
+            ->addEnv_file("running.env")
             ->addVolumes("./base/", "/opt/base");
 
         $composer
@@ -756,6 +770,7 @@ class Release extends Command
             ->addLinks("base")
             ->addLinks("amqp")
             ->addLinks("nginx", $this->getDomain("base"))
+            ->addEnv_file("running.env")
             ->addVolumes("./ftth/", "/opt/ftth");
 
         $composer
@@ -768,6 +783,7 @@ class Release extends Command
             ->addLinks("base")
             ->addLinks("amqp")
             ->addLinks("nginx", $this->getDomain("base"))
+            ->addEnv_file("running.env")
             ->addVolumes("./ftth/", "/opt/ftth");
 
         $composer
@@ -999,7 +1015,7 @@ class Release extends Command
      */
     private function getDomain($module)
     {
-        return $module . "." . $this->_domain . "." . $this->_domain_behind;
+        return $module . "." . $this->_client . "." . $this->_domain;
     }
 
     /**
@@ -1027,6 +1043,15 @@ class Release extends Command
             ->content($tmp);
     }
 
+    /**
+     * Crea el archivo con los usuarios del sistema para que lea el ansible.
+     */
+    private function writeUserSystem()
+    {
+        $this->_dObj->file("user_system.json")
+            ->content(json_encode($this->_user_system));
+    }
+
     /**
      * Crea el archivo con las variables para ejecutar el ansible.
      */
@@ -1036,8 +1061,8 @@ class Release extends Command
         $all = "[all]\n";
         foreach ($composer->getServices() as $key => $value) {
             $tmp .= "[$key]\n";
-            $tmp .= $this->_domain . "_" . $key . "_1\n\n";
-            $all .= $this->_domain . "_" . $key . "_1\n";
+            $tmp .= $this->_client . "_" . $key . "_1\n\n";
+            $all .= $this->_client . "_" . $key . "_1\n";
         }
 
         $this->_dObj->file("inventory.ini")->content($tmp . $all);