From 8240246593d7cb3f0efa6ada32a9a864aa450bb8 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Sat, 10 Jun 2017 07:31:22 -0700 Subject: [PATCH 1/2] [IMP] Add option to automatically install repo requirements --- Dockerfile | 1 + build.d/100-dependencies | 18 +++++++++++++++++- lib/odoobaselib/__init__.py | 1 + .../custom/entrypoint.d/check-requirements | 2 ++ .../custom/src/dummy_repo/requirements.txt | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 tests/scaffoldings/dotd/custom/entrypoint.d/check-requirements create mode 100644 tests/scaffoldings/dotd/custom/src/dummy_repo/requirements.txt 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/build.d/100-dependencies b/build.d/100-dependencies index c93ff3c7..59304f04 100755 --- a/build.d/100-dependencies +++ b/build.d/100-dependencies @@ -4,7 +4,12 @@ import logging import os -from odoobaselib import CUSTOM_DIR, FILE_APT_BUILD, SRC_DIR +from odoobaselib import (addons_config, + AUTO_REQUIREMENTS, + CUSTOM_DIR, + FILE_APT_BUILD, + SRC_DIR, + ) from odoobaselib.installer import INSTALLERS @@ -20,6 +25,17 @@ for name, class_ in INSTALLERS.items(): class_(req_file).install() +if AUTO_REQUIREMENTS: + for repo in addons_config().keys(): + req_file = os.path.join( + SRC_DIR, repo, 'requirements.txt', + ) + try: + INSTALLERS['pip'](req_file).install() + except OSError: + logging.debug('Requirements file not found at %s' % req_file) + + # Deprecated req_file = os.path.join( SRC_DIR, 'requirements.txt', 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/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 From a3cdb78c2411efe6d71b4546ed381834c9dad418 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Fri, 11 Aug 2017 11:04:20 +0200 Subject: [PATCH 2/2] Saner auto requirements installation - Shortcut for installation that reduces the logic size. - Cannot install from repositories before aggregation. - Auto dependencies should come in before manual ones. - Drop support of deprecated /opt/custom/src/requirements.txt file. --- README.md | 5 -- build.d/100-dependencies | 51 ------------------- ...00-repos-aggregate => 100-repos-aggregate} | 0 build.d/200-dependencies | 28 ++++++++++ lib/odoobaselib/installer.py | 11 +++- 5 files changed, 37 insertions(+), 58 deletions(-) delete mode 100755 build.d/100-dependencies rename build.d/{200-repos-aggregate => 100-repos-aggregate} (100%) create mode 100755 build.d/200-dependencies 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 59304f04..00000000 --- a/build.d/100-dependencies +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# Copyright 2017 LasLabs Inc. - -import logging -import os - -from odoobaselib import (addons_config, - AUTO_REQUIREMENTS, - 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() - - -if AUTO_REQUIREMENTS: - for repo in addons_config().keys(): - req_file = os.path.join( - SRC_DIR, repo, 'requirements.txt', - ) - try: - INSTALLERS['pip'](req_file).install() - except OSError: - logging.debug('Requirements file not found at %s' % req_file) - - -# 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/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()