|
| 1 | +.. image:: https://odoo-community.org/readme-banner-image |
| 2 | + :target: https://odoo-community.org/get-involved?utm_source=readme |
| 3 | + :alt: Odoo Community Association |
| 4 | + |
| 5 | +====================================== |
| 6 | +server configuration environment files |
| 7 | +====================================== |
| 8 | + |
| 9 | +.. |
| 10 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 11 | + !! This file is generated by oca-gen-addon-readme !! |
| 12 | + !! changes will be overwritten. !! |
| 13 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 14 | + !! source digest: sha256:39cd61c3a9621d0b7ee7a346adf45f4a2c90e80e6a61e18f182386c6fc90fd19 |
| 15 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 16 | +
|
| 17 | +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png |
| 18 | + :target: https://odoo-community.org/page/development-status |
| 19 | + :alt: Production/Stable |
| 20 | +.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png |
| 21 | + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html |
| 22 | + :alt: License: LGPL-3 |
| 23 | +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github |
| 24 | + :target: https://github.com/OCA/server-env/tree/19.0/server_environment |
| 25 | + :alt: OCA/server-env |
| 26 | +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
| 27 | + :target: https://translation.odoo-community.org/projects/server-env-19-0/server-env-19-0-server_environment |
| 28 | + :alt: Translate me on Weblate |
| 29 | +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png |
| 30 | + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=19.0 |
| 31 | + :alt: Try me on Runboat |
| 32 | + |
| 33 | +|badge1| |badge2| |badge3| |badge4| |badge5| |
| 34 | + |
| 35 | +This module provides a way to define an environment in the main Odoo |
| 36 | +configuration file and to read some configurations from files depending |
| 37 | +on the configured environment: you define the environment in the main |
| 38 | +configuration file, and the values for the various possible environments |
| 39 | +are stored in the ``server_environment_files`` companion module. |
| 40 | + |
| 41 | +The ``server_environment_files`` module is optional, the values can be |
| 42 | +set using an environment variable with a fallback on default values in |
| 43 | +the database. |
| 44 | + |
| 45 | +The configuration read from the files are visible under the |
| 46 | +Configuration menu. If you are not in the 'dev' environment you will not |
| 47 | +be able to see the values contained in the defined secret keys (by |
| 48 | +default : '*passw*', '*key*', '*secret*' and '*token*'). |
| 49 | + |
| 50 | +**Table of contents** |
| 51 | + |
| 52 | +.. contents:: |
| 53 | + :local: |
| 54 | + |
| 55 | +Installation |
| 56 | +============ |
| 57 | + |
| 58 | +By itself, this module does little. See for instance the |
| 59 | +``mail_environment`` addon which depends on this one to allow |
| 60 | +configuring the incoming and outgoing mail servers depending on the |
| 61 | +environment. |
| 62 | + |
| 63 | +You can store your configuration values in a companion module called |
| 64 | +``server_environment_files``. You can copy and customize the provided |
| 65 | +``server_environment_files_sample`` module for this purpose. |
| 66 | +Alternatively, you can provide them in environment variables |
| 67 | +``SERVER_ENV_CONFIG`` and ``SERVER_ENV_CONFIG_SECRET``. |
| 68 | + |
| 69 | +Configuration |
| 70 | +============= |
| 71 | + |
| 72 | +To configure this module, you need to edit the main configuration file |
| 73 | +of your instance, and add a directive called ``running_env``. Commonly |
| 74 | +used values are 'dev', 'test', 'production': |
| 75 | + |
| 76 | +:: |
| 77 | + |
| 78 | + [options] |
| 79 | + running_env=dev |
| 80 | + |
| 81 | +Or set the ``RUNNING_ENV`` or ``ODOO_STAGE`` environment variable. If |
| 82 | +both all are set config file will take the precedence on environment and |
| 83 | +``RUNNING_ENV`` over ``ODOO_STAGE``. |
| 84 | + |
| 85 | +``ODOO_STAGE`` is used for odoo.sh platform where we can't set |
| 86 | +``RUNNING_ENV``, possible observed values are ``production``, |
| 87 | +``staging`` and ``dev`` |
| 88 | + |
| 89 | +Values associated to keys containing 'passw' are only displayed in the |
| 90 | +'dev' environment. |
| 91 | + |
| 92 | +If you don't provide any value, test is used as a safe default. |
| 93 | + |
| 94 | +You have several possibilities to set configuration values: |
| 95 | + |
| 96 | +server_environment_files |
| 97 | +------------------------ |
| 98 | + |
| 99 | +You can edit the settings you need in the ``server_environment_files`` |
| 100 | +addon. The ``server_environment_files_sample`` can be used as an |
| 101 | +example: |
| 102 | + |
| 103 | +- values common to all / most environments can be stored in the |
| 104 | + ``default/`` directory using the .ini file syntax; |
| 105 | +- each environment you need to define is stored in its own directory |
| 106 | + and can override or extend default values; |
| 107 | +- you can override or extend values in the main configuration file of |
| 108 | + your instance; |
| 109 | + |
| 110 | +Environment variable |
| 111 | +-------------------- |
| 112 | + |
| 113 | +You can define configuration in the environment variable |
| 114 | +``SERVER_ENV_CONFIG`` and/or ``SERVER_ENV_CONFIG_SECRET``. The 2 |
| 115 | +variables are handled the exact same way, this is only a convenience for |
| 116 | +the deployment where you can isolate the secrets in a different, |
| 117 | +encrypted, file. They are multi-line environment variables in the same |
| 118 | +configparser format than the files. If you used options in |
| 119 | +``server_environment_files``, the options set in the environment |
| 120 | +variable override them. |
| 121 | + |
| 122 | +The options in the environment variable are not dependent of |
| 123 | +``running_env``, the content of the variable must be set accordingly to |
| 124 | +the running environment. |
| 125 | + |
| 126 | +Example of setup: |
| 127 | + |
| 128 | +A public file, containing that will contain public variables: |
| 129 | + |
| 130 | +:: |
| 131 | + |
| 132 | + # These variables are not odoo standard variables, |
| 133 | + # they are there to represent what your file could look like |
| 134 | + export WORKERS='8' |
| 135 | + export MAX_CRON_THREADS='1' |
| 136 | + export LOG_LEVEL=info |
| 137 | + export LOG_HANDLER=":INFO" |
| 138 | + export DB_MAXCONN=5 |
| 139 | + |
| 140 | + # server environment options |
| 141 | + export SERVER_ENV_CONFIG=" |
| 142 | + [storage_backend.my_sftp] |
| 143 | + sftp_server=10.10.10.10 |
| 144 | + sftp_login=foo |
| 145 | + sftp_port=22200 |
| 146 | + directory_path=Odoo |
| 147 | + " |
| 148 | + |
| 149 | +A second file which is encrypted and contains secrets: |
| 150 | + |
| 151 | +:: |
| 152 | + |
| 153 | + # This variable is not an odoo standard variable, |
| 154 | + # it is there to represent what your file could look like |
| 155 | + export DB_PASSWORD='xxxxxxxxx' |
| 156 | + # server environment options |
| 157 | + export SERVER_ENV_CONFIG_SECRET=" |
| 158 | + [storage_backend.my_sftp] |
| 159 | + sftp_password=xxxxxxxxx |
| 160 | + " |
| 161 | + |
| 162 | +**WARNING** |
| 163 | + |
| 164 | + my_sftp must match the name of the record. If you want something more |
| 165 | + reliable use server.env.techname.mixin and use tech_name field to |
| 166 | + reference records. See "USAGE". |
| 167 | + |
| 168 | +Default values |
| 169 | +-------------- |
| 170 | + |
| 171 | +When using the ``server.env.mixin`` mixin, for each env-computed field, |
| 172 | +a companion field ``<field>_env_default`` is created. This field is not |
| 173 | +environment-dependent. It's a fallback value used when no key is set in |
| 174 | +configuration files / environment variable. |
| 175 | + |
| 176 | +When the default field is used, the field is made editable on Odoo. |
| 177 | + |
| 178 | +Note: empty environment keys always take precedence over default fields |
| 179 | + |
| 180 | +Server environment integration |
| 181 | +------------------------------ |
| 182 | + |
| 183 | +Read the documentation of the class |
| 184 | +`models/server_env_mixin.py <models/server_env_mixin.py>`__ and |
| 185 | +[models/server_env_tech_name_mixin.py] |
| 186 | +(models/server_env_tech_name_mixin.py) |
| 187 | + |
| 188 | +Usage |
| 189 | +===== |
| 190 | + |
| 191 | +You can include a mixin in your model and configure the env-computed |
| 192 | +fields by an override of ``_server_env_fields``. |
| 193 | + |
| 194 | +:: |
| 195 | + |
| 196 | + class StorageBackend(models.Model): |
| 197 | + _name = "storage.backend" |
| 198 | + _inherit = ["storage.backend", "server.env.mixin"] |
| 199 | + |
| 200 | + @property |
| 201 | + def _server_env_fields(self): |
| 202 | + return {"directory_path": {}} |
| 203 | + |
| 204 | +Read the documentation of the class and methods in |
| 205 | +`models/server_env_mixin.py <models/server_env_mixin.py>`__. |
| 206 | + |
| 207 | +If you want to have a technical name to reference: |
| 208 | + |
| 209 | +:: |
| 210 | + |
| 211 | + class StorageBackend(models.Model): |
| 212 | + _name = "storage.backend" |
| 213 | + _inherit = ["storage.backend", "server.env.techname.mixin"] |
| 214 | + |
| 215 | + [...] |
| 216 | + |
| 217 | +Known issues / Roadmap |
| 218 | +====================== |
| 219 | + |
| 220 | +- it is not possible to set the environment from the command line. A |
| 221 | + configuration file must be used. |
| 222 | +- the module does not allow to set low level attributes such as |
| 223 | + database server, etc. |
| 224 | +- server.env.techname.mixin's tech_name field could leverage the new |
| 225 | + option for computable / writable fields and get rid of some onchange |
| 226 | + / read / write code. |
| 227 | + |
| 228 | +Bug Tracker |
| 229 | +=========== |
| 230 | + |
| 231 | +Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_. |
| 232 | +In case of trouble, please check there if your issue has already been reported. |
| 233 | +If you spotted it first, help us to smash it by providing a detailed and welcomed |
| 234 | +`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
| 235 | + |
| 236 | +Do not contact contributors directly about support or help with technical issues. |
| 237 | + |
| 238 | +Credits |
| 239 | +======= |
| 240 | + |
| 241 | +Authors |
| 242 | +------- |
| 243 | + |
| 244 | +* Camptocamp |
| 245 | + |
| 246 | +Contributors |
| 247 | +------------ |
| 248 | + |
| 249 | +- Florent Xicluna (Wingo) <florent.xicluna@gmail.com> |
| 250 | +- Nicolas Bessi <nicolas.bessi@camptocamp.com> |
| 251 | +- Alexandre Fayolle <alexandre.fayolle@camptocamp.com> |
| 252 | +- Daniel Reis <dgreis@sapo.pt> |
| 253 | +- Holger Brunn <hbrunn@therp.nl> |
| 254 | +- Leonardo Pistone <leonardo.pistone@camptocamp.com> |
| 255 | +- Adrien Peiffer <adrien.peiffer@acsone.com> |
| 256 | +- Thierry Ducrest <thierry.ducrest@camptocamp.com> |
| 257 | +- Guewen Baconnier <guewen.baconnier@camptocamp.com> |
| 258 | +- Thomas Binfeld <thomas.binsfeld@acsone.eu> |
| 259 | +- Stéphane Bidoul <stefane.bidoul@acsone.com> |
| 260 | +- Simone Orsi <simahawk@gmail.com> |
| 261 | + |
| 262 | +Maintainers |
| 263 | +----------- |
| 264 | + |
| 265 | +This module is maintained by the OCA. |
| 266 | + |
| 267 | +.. image:: https://odoo-community.org/logo.png |
| 268 | + :alt: Odoo Community Association |
| 269 | + :target: https://odoo-community.org |
| 270 | + |
| 271 | +OCA, or the Odoo Community Association, is a nonprofit organization whose |
| 272 | +mission is to support the collaborative development of Odoo features and |
| 273 | +promote its widespread use. |
| 274 | + |
| 275 | +This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/19.0/server_environment>`_ project on GitHub. |
| 276 | + |
| 277 | +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
0 commit comments