Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added config-expand script in entrypoint to allow more control over o… #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ It will be full of symlinks to the addons you selected in [`addons.yaml`][].

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

> :warning: **Deprecated**: Configuration file is now generated via environment
variables set as such `$ODOO_CFG_{ODOO_CFG_PARAMETER}`

It will have the result of merging all configurations under
`/opt/odoo/{common,custom}/conf.d/`, in that order.

Expand Down
34 changes: 30 additions & 4 deletions bin/config-generate
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
"""Generate Odoo server configuration from templates"""

import os
import sys
from contextlib import closing
from string import Template

from doodbalib import logger
from doodbalib import logger, ODOO_DIR

try:
# Python 2, where io.StringIO fails because it is unicode-only
from StringIO import StringIO
except ImportError:
from io import StringIO

try:
from odoo.tools.config import configmanager
except ImportError:
# For non-pip installations
sys.path.append(ODOO_DIR)
from odoo.tools.config import configmanager

try:
from configparser import RawConfigParser

parser = RawConfigParser(strict=False)
except ImportError:
# Python 2, where strict=True doesn't exist
# Python 2, where strict=True doesn"t exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you change this back to doesn't?

from ConfigParser import RawConfigParser

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

# Read all configuraiton files found in those folders
# Read all configuration files found in those folders
logger.info("Merging found configuration files in %s", TARGET_FILE)
for dir_ in CONFIG_DIRS:
try:
Expand All @@ -40,6 +47,25 @@ for dir_ in CONFIG_DIRS:
except OSError: # TODO Use FileNotFoundError when we drop python 2
continue


# Add configuration parameters sent via env vars
logger.info("Updating configuration file with set environment variables")
odoo_cfg = configmanager()
cfg_env_prefix = "ODOO_CFG_"

for k, val in os.environ.items():
if not val or not k.startswith(cfg_env_prefix):
continue

parameter = k.split(cfg_env_prefix)[1].lower()
if parameter in odoo_cfg.options:
parser.set("options", parameter, val)

# Warn user about all invalid parameters
invalid_params = set(parser.options) - set(odoo_cfg.options)
for param in invalid_params:
logger.warning("'%s' is not a valid Odoo configuration parameter")

# Write it to a memory string object
with closing(StringIO()) as resultfp:
parser.write(resultfp)
Expand Down