Skip to content

Commit aa723ae

Browse files
committed
Using environment variables to set odoo config parameters along with .conf template files
1 parent 5a5d94d commit aa723ae

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,13 @@ It will be full of symlinks to the addons you selected in [`addons.yaml`][].
402402

403403
#### `/opt/odoo/auto/odoo.conf`
404404

405+
> :warning: **Deprecated**: Configuration file is now generated via environment
406+
variables set as such `$ODOO_CFG_{ODOO_CFG_PARAMETER}`
407+
405408
It will have the result of merging all configurations under
406409
`/opt/odoo/{common,custom}/conf.d/`, in that order.
407410

411+
408412
## The `Dockerfile`
409413

410414
I will document all build arguments and environment variables some day, but for

bin/config-generate

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
"""Generate Odoo server configuration from templates"""
44

55
import os
6+
import sys
67
from contextlib import closing
78
from string import Template
89

9-
from doodbalib import logger
10+
from doodbalib import logger, ODOO_DIR
1011

1112
try:
1213
# Python 2, where io.StringIO fails because it is unicode-only
1314
from StringIO import StringIO
1415
except ImportError:
1516
from io import StringIO
1617

18+
try:
19+
from odoo.tools.config import configmanager
20+
except ImportError:
21+
# For non-pip installations
22+
sys.path.append(ODOO_DIR)
23+
from odoo.tools.config import configmanager
24+
1725
try:
1826
from configparser import RawConfigParser
1927

@@ -29,9 +37,8 @@ TARGET_FILE = os.environ.get("OPENERP_SERVER", "/opt/odoo/auto/odoo.conf")
2937
if ODOO_VERSION not in {"8.0", "9.0"}:
3038
TARGET_FILE = os.environ.get("ODOO_RC", TARGET_FILE)
3139
CONFIG_DIRS = ("/opt/odoo/common/conf.d", "/opt/odoo/custom/conf.d")
32-
CONFIG_FILES = []
3340

34-
# Read all configuraiton files found in those folders
41+
# Read all configuration files found in those folders
3542
logger.info("Merging found configuration files in %s", TARGET_FILE)
3643
for dir_ in CONFIG_DIRS:
3744
try:
@@ -40,6 +47,24 @@ for dir_ in CONFIG_DIRS:
4047
except OSError: # TODO Use FileNotFoundError when we drop python 2
4148
continue
4249

50+
51+
# Add configuration parameters sent via env vars
52+
odoo_cfg = configmanager()
53+
cfg_env_prefix = 'ODOO_CFG_'
54+
55+
for k, val in os.environ.items():
56+
if not val or not k.startswith(cfg_env_prefix):
57+
continue
58+
59+
parameter = k.split(cfg_env_prefix)[1].lower()
60+
if parameter in odoo_cfg.options:
61+
parser.set('options', parameter, val)
62+
63+
# Warn user about all invalid parameters
64+
invalid_params = set(parser.options) - set(odoo_cfg.options)
65+
for param in invalid_params:
66+
logger.warning("'%s' is not a valid Odoo configuration parameter")
67+
4368
# Write it to a memory string object
4469
with closing(StringIO()) as resultfp:
4570
parser.write(resultfp)

0 commit comments

Comments
 (0)