diff --git a/Dockerfile b/Dockerfile index 353407d6..c2292adf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ ONBUILD ARG DEPTH_MERGE=100 ONBUILD ARG CLEAN=true ONBUILD ARG COMPILE=true ONBUILD ARG CONFIG_BUILD=true +ONBUILD ARG AUTO_REQUIREMENTS=true ONBUILD ARG PIP_INSTALL_ODOO=true ONBUILD ARG ADMIN_PASSWORD=admin ONBUILD ARG SMTP_SERVER=smtp diff --git a/README.md b/README.md index ceb3400a..10773921 100644 --- a/README.md +++ b/README.md @@ -881,11 +881,6 @@ Dockerfile similar to this one: FROM tecnativa/odoo-base@sha256:fba69478f9b0616561aa3aba4d18e4bcc2f728c9568057946c98d5d3817699e1 ``` -### What is `/opt/odoo/custom/src/requirements.txt`? - -This is the deprecated file path for the PIP requirements. Use -`/opt/odoo/custom/dependencies/pip.txt` instead. - ### How can I help? Just [head to our project](https://github.com/Tecnativa/docker-odoo-base) and diff --git a/build.d/100-dependencies b/build.d/100-dependencies deleted file mode 100755 index c93ff3c7..00000000 --- a/build.d/100-dependencies +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# Copyright 2017 LasLabs Inc. - -import logging -import os - -from odoobaselib import CUSTOM_DIR, FILE_APT_BUILD, SRC_DIR -from odoobaselib.installer import INSTALLERS - - -if os.path.isfile(FILE_APT_BUILD): - INSTALLERS['apt'](FILE_APT_BUILD).install() - - -for name, class_ in INSTALLERS.items(): - req_file = os.path.join( - CUSTOM_DIR, 'dependencies', '%s.txt' % name, - ) - if os.path.isfile(req_file): - class_(req_file).install() - - -# Deprecated -req_file = os.path.join( - SRC_DIR, 'requirements.txt', -) -if os.path.isfile(req_file): - new_file = os.path.join( - CUSTOM_DIR, 'dependencies', 'pip.txt', - ) - logging.warning( - 'The "%s" path is deprecated. Please use "%s" instead.', - req_file, new_file, - ) - INSTALLERS['pip'](req_file).install() diff --git a/build.d/200-repos-aggregate b/build.d/100-repos-aggregate similarity index 100% rename from build.d/200-repos-aggregate rename to build.d/100-repos-aggregate diff --git a/build.d/200-dependencies b/build.d/200-dependencies new file mode 100755 index 00000000..6722feec --- /dev/null +++ b/build.d/200-dependencies @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# Copyright 2017 LasLabs Inc. + +from os.path import join + +from odoobaselib import ( + addons_config, + AUTO_REQUIREMENTS, + CUSTOM_DIR, + FILE_APT_BUILD, + SRC_DIR, +) +from odoobaselib.installer import install, INSTALLERS + + +# Build dependencies installed before any others +install("apt", FILE_APT_BUILD) + +for name in INSTALLERS: + req_files = [] + # pip `requirements.txt` files found in repositories + if name == "pip" and AUTO_REQUIREMENTS: + for repo in addons_config(): + req_files.append(join(SRC_DIR, repo, 'requirements.txt')) + # Normal dependency installation + req_files.append(join(CUSTOM_DIR, 'dependencies', '%s.txt' % name)) + for req_file in req_files: + install(name, req_file) diff --git a/lib/odoobaselib/__init__.py b/lib/odoobaselib/__init__.py index da85a0c0..9aad6ec9 100644 --- a/lib/odoobaselib/__init__.py +++ b/lib/odoobaselib/__init__.py @@ -10,6 +10,7 @@ ADDONS_YAML = os.path.join(SRC_DIR, 'addons') ADDONS_DIR = "/opt/odoo/auto/addons" CLEAN = os.environ.get("CLEAN") == "true" +AUTO_REQUIREMENTS = os.environ.get("AUTO_REQUIREMENTS") == "true" LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR") FILE_APT_BUILD = os.path.join( CUSTOM_DIR, 'dependencies', 'apt_build.txt', diff --git a/lib/odoobaselib/installer.py b/lib/odoobaselib/installer.py index 652df317..134eafe4 100644 --- a/lib/odoobaselib/installer.py +++ b/lib/odoobaselib/installer.py @@ -26,10 +26,12 @@ def cleanup(self): def install(self): """Install the requirements from the given file.""" if self._requirements: - self._run_command(self._install_command + self._requirements) + return not self._run_command( + self._install_command + self._requirements) else: logging.info("No installable requirements found in %s", self.file_path) + return False def remove(self): """Uninstall the requirements from the given file.""" @@ -102,7 +104,7 @@ class PipInstaller(Installer): def requirements(self): """Pip will use its ``--requirements`` feature.""" - return [self.file_path] + return [self.file_path] if exists(self.file_path) else [] INSTALLERS = { @@ -111,3 +113,8 @@ def requirements(self): "npm": NpmInstaller, "pip": PipInstaller, } + + +def install(installer, file_path): + """Perform a given type of installation from a given file.""" + return INSTALLERS[installer](file_path).install() diff --git a/tests/scaffoldings/dotd/custom/entrypoint.d/check-requirements b/tests/scaffoldings/dotd/custom/entrypoint.d/check-requirements new file mode 100755 index 00000000..f71069e8 --- /dev/null +++ b/tests/scaffoldings/dotd/custom/entrypoint.d/check-requirements @@ -0,0 +1,2 @@ +#!/usr/bin/env python +from cfssl import CFSSL diff --git a/tests/scaffoldings/dotd/custom/src/dummy_repo/requirements.txt b/tests/scaffoldings/dotd/custom/src/dummy_repo/requirements.txt new file mode 100644 index 00000000..0139cd0a --- /dev/null +++ b/tests/scaffoldings/dotd/custom/src/dummy_repo/requirements.txt @@ -0,0 +1 @@ +cfssl