|
| 1 | +:banner: banners/odoo-sh.jpg |
| 2 | + |
| 3 | +================================== |
| 4 | +Containers |
| 5 | +================================== |
| 6 | + |
| 7 | +Overview |
| 8 | +======== |
| 9 | + |
| 10 | +Each build is isolated within its own container (Linux namespaced container). |
| 11 | + |
| 12 | +The base is an Ubuntu 16.04 system, where all of Odoo's required dependencies, |
| 13 | +as well as common useful packages, are installed. |
| 14 | + |
| 15 | +The Odoo.sh team is open to install any system packages |
| 16 | +as long as they are distributed in the official Ubuntu repositories. |
| 17 | +`Leave us a feedback <https://www.odoo.sh/feedback>`_ if you would like a package not yet installed. |
| 18 | + |
| 19 | +If your project requires additional Python dependencies, or more recent releases, |
| 20 | +you can define a :file:`requirements.txt` file in the root of your branches listing them. |
| 21 | +The platform will take care to install these dependencies in your containers. |
| 22 | +`The pip requirements specifiers <https://pip.pypa.io/en/stable/reference/pip_install/#requirement-specifiers>`_ |
| 23 | +documentation can help you write a :file:`requirements.txt` file. |
| 24 | +To have a concrete example, |
| 25 | +check out the `requirements.txt file of Odoo <https://github.com/odoo/odoo/blob/11.0/requirements.txt>`_. |
| 26 | + |
| 27 | +The :file:`requirements.txt` files of submodules are taken into account as well. The platform |
| 28 | +looks for :file:`requirements.txt` files in each folder containing Odoo modules: Not in the module folder itself, |
| 29 | +but in their parent folder. |
| 30 | + |
| 31 | +Directory structure |
| 32 | +=================== |
| 33 | + |
| 34 | +As the containers are Ubuntu based, their directory structure follows the linux Filesystem Hierarchy Standard. |
| 35 | +`Ubuntu's filesystem tree overview <https://help.ubuntu.com/community/LinuxFilesystemTreeOverview#Main_directories>`_ |
| 36 | +explains the main directories. |
| 37 | + |
| 38 | +Here are the Odoo.sh pertinent directories: |
| 39 | + |
| 40 | +:: |
| 41 | + |
| 42 | + . |
| 43 | + ├── home |
| 44 | + │ └── odoo |
| 45 | + │ ├── src |
| 46 | + │ │ ├── odoo Odoo Community source code |
| 47 | + │ │ │ └── odoo-bin Odoo server executable |
| 48 | + │ │ ├── enterprise Odoo Enterprise source code |
| 49 | + │ │ ├── themes Odoo Themes source code |
| 50 | + │ │ └── user Your repository branch source code |
| 51 | + │ ├── data |
| 52 | + │ │ ├── filestore database attachments, as well as the files of binary fields |
| 53 | + │ │ └── sessions visitors and users sessions |
| 54 | + │ └── logs |
| 55 | + │ ├── install.log Database installation logs |
| 56 | + │ ├── odoo.log Running server logs |
| 57 | + │ ├── update.log Database updates logs |
| 58 | + │ └── pip.log Python packages installation logs |
| 59 | + └── usr |
| 60 | + ├── lib |
| 61 | + │ ├── python2.7 |
| 62 | + │ └── dist-packages Python 2.7 standard libraries |
| 63 | + │ ├── python3 |
| 64 | + │ └── dist-packages Python 3 standard libraries |
| 65 | + │ └── python3.5 |
| 66 | + │ └── dist-packages Python 3.5 standard libraries |
| 67 | + ├── local |
| 68 | + │ └── lib |
| 69 | + │ ├── python2.7 |
| 70 | + │ │ └── dist-packages Python 2.7 third-party libraries |
| 71 | + │ └── python3.5 |
| 72 | + │ └── dist-packages Python 3.5 third-party libraries |
| 73 | + └── usr |
| 74 | + └── bin |
| 75 | + ├── python2.7 Python 2.7 executable |
| 76 | + └── python3.5 Python 3.5 executable |
| 77 | + |
| 78 | +Both Python 2.7 and 3.5 are installed in the containers. However: |
| 79 | + |
| 80 | +* If your project is configured to use Odoo 10.0, the Odoo server runs with Python 2.7. |
| 81 | +* If your project is configured to use Odoo 11.0, the Odoo server runs with Python 3.5. |
| 82 | + |
| 83 | +Database shell |
| 84 | +============== |
| 85 | + |
| 86 | +While accessing a container with the shell, you can access the database using *psql*. |
| 87 | + |
| 88 | +.. code-block:: bash |
| 89 | +
|
| 90 | + odoo@odoo-addons-master-1.odoo.sh:~$ psql |
| 91 | + psql (9.5.2, server 9.5.11) |
| 92 | + SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) |
| 93 | + Type "help" for help. |
| 94 | +
|
| 95 | + odoo-addons-master-1=> |
| 96 | +
|
| 97 | +**Be careful !** |
| 98 | +`Use transactions <https://www.postgresql.org/docs/current/static/sql-begin.html>`_ (*BEGIN...COMMIT/ROLLBACK*) |
| 99 | +for every *sql* statements leading to changes |
| 100 | +(*UPDATE*, *DELETE*, *ALTER*, ...), especially for your production database. |
| 101 | + |
| 102 | +The transaction mechanism is your safety net in case of mistake. |
| 103 | +You simply have to rollback your changes to revert your database to its previous state. |
| 104 | + |
| 105 | +For example, it may happen that you forget to set your *WHERE* condition. |
| 106 | + |
| 107 | +.. code-block:: sql |
| 108 | +
|
| 109 | + odoo-addons-master-1=> BEGIN; |
| 110 | + BEGIN |
| 111 | + odoo-addons-master-1=> UPDATE res_users SET password = '***'; |
| 112 | + UPDATE 457 |
| 113 | + odoo-addons-master-1=> ROLLBACK; |
| 114 | + ROLLBACK |
| 115 | +
|
| 116 | +In such a case, you can rollback to revert the unwanted changes that you just mistakenly did, and rewrite the statement: |
| 117 | + |
| 118 | +.. code-block:: sql |
| 119 | +
|
| 120 | + odoo-addons-master-1=> BEGIN; |
| 121 | + BEGIN |
| 122 | + odoo-addons-master-1=> UPDATE res_users SET password = '***' WHERE id = 1; |
| 123 | + UPDATE 1 |
| 124 | + odoo-addons-master-1=> COMMIT; |
| 125 | + COMMIT |
| 126 | +
|
| 127 | +However, do not forget to either commit or rollback your transaction after having done it. |
| 128 | +Open transactions may lock records in your tables |
| 129 | +and your running database may wait for them to be released. It can cause a server to hang indefinitely. |
| 130 | + |
| 131 | +In addition, when possible, use your staging databases to test your statements first. It gives you an extra safety net. |
| 132 | + |
| 133 | +Run an Odoo server |
| 134 | +================== |
| 135 | + |
| 136 | +You can start an Odoo server instance from a container shell. You won't be able to access it from the outside world |
| 137 | +with a browser, but you can for instance: |
| 138 | + |
| 139 | +* use the Odoo shell, |
| 140 | + |
| 141 | +.. code-block:: bash |
| 142 | +
|
| 143 | + $ ~/src/odoo/odoo-bin shell -d odoo-addons-master-1 --addons-path=~/src/user,~/src/enterprise,~/src/themes,~/src/odoo/addons,~/src/odoo/odoo/addons --workers=0 --max-cron-threads=0 |
| 144 | + >>> partner = env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1) |
| 145 | + >>> partner.name |
| 146 | + 'ASUSTeK' |
| 147 | + >>> partner.name = 'Odoo' |
| 148 | + >>> env['res.partner'].search([('email', '=', 'asusteK@yourcompany.example.com')], limit=1).name |
| 149 | + 'Odoo' |
| 150 | +
|
| 151 | +* install a module, |
| 152 | + |
| 153 | +.. code-block:: bash |
| 154 | +
|
| 155 | + $ ~/src/odoo/odoo-bin -d odoo-addons-master-1 --addons-path=~/src/user,~/src/enterprise,~/src/themes,~/src/odoo/addons,~/src/odoo/odoo/addons -i sale --workers=0 --max-cron-threads=0 --stop-after-init |
| 156 | +
|
| 157 | +* update a module, |
| 158 | + |
| 159 | +.. code-block:: bash |
| 160 | +
|
| 161 | + $ ~/src/odoo/odoo-bin -d odoo-addons-master-1 --addons-path=~/src/user,~/src/enterprise,~/src/themes,~/src/odoo/addons,~/src/odoo/odoo/addons -u sale --workers=0 --max-cron-threads=0 --stop-after-init |
| 162 | +
|
| 163 | +* run the tests for a module, |
| 164 | + |
| 165 | +.. code-block:: bash |
| 166 | +
|
| 167 | + $ ~/src/odoo/odoo-bin -d odoo-addons-master-1 --addons-path=~/src/user,~/src/enterprise,~/src/themes,~/src/odoo/addons,~/src/odoo/odoo/addons -i sale --test-enable --log-level=test --workers=0 --max-cron-threads=0 --stop-after-init |
| 168 | +
|
| 169 | +In the above commands, the argument: |
| 170 | + |
| 171 | +* *--addons-path* is to specify the directories containing the modules, |
| 172 | + the part *~/src/user* can vary, according to your branch code structure, |
| 173 | +* *--workers=0* is to run your server using multi-threading instead of multiple workers, |
| 174 | +* *--max-cron-threads=0* is to prevent the scheduled tasks to run, |
| 175 | +* *--stop-after-init* is to immediately shutdown the server instance after it completed the operations you asked. |
| 176 | + |
| 177 | +More options are available and detailed in the |
| 178 | +`CLI documentation <https://www.odoo.com/documentation/11.0/reference/cmdline.html>`_. |
| 179 | + |
| 180 | +You can find in the logs (*~/logs/odoo.log*) the addons path used by Odoo.sh to run your server. |
| 181 | +Look for "*odoo: addons paths*": |
| 182 | + |
| 183 | +:: |
| 184 | + |
| 185 | + 2018-02-19 10:51:39,267 4 INFO ? odoo: Odoo version 11.0 |
| 186 | + 2018-02-19 10:51:39,268 4 INFO ? odoo: Using configuration file at /home/odoo/.config/odoo/odoo.conf |
| 187 | + 2018-02-19 10:51:39,268 4 INFO ? odoo: addons paths: ['/home/odoo/data/addons/11.0', '/home/odoo/src/user', '/home/odoo/src/enterprise', '/home/odoo/src/themes', '/home/odoo/src/odoo/addons', '/home/odoo/src/odoo/odoo/addons'] |
| 188 | + |
| 189 | +**Be careful**, especially with your production database. |
| 190 | +Operations that you perform running this Odoo server instance are not isolated: |
| 191 | +Changes will be effective in the database. Always, make your tests in your staging databases. |
0 commit comments