From 80e5e3ad8740d9bbb3236974da3e6601907faf70 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 27 Jun 2022 15:56:28 +0200 Subject: [PATCH] [REF] Dockerfiles : switch from odoo/odoo to acsone/odoo-bedrock --- INTERNAL_NOTES.md | 5 +++ odoo_openupgrade_wizard/cli/cli_init.py | 11 ++++- .../configuration_version_dependant.py | 41 ++++++++++++++----- .../templates/config.yml.j2 | 8 ++++ .../templates/odoo/Dockerfile.j2 | 25 +++++------ .../templates/odoo/debian_requirements.txt.j2 | 1 - .../templates/odoo/python_requirements.txt.j2 | 2 +- tests/data/output_expected/config.yml | 8 ++++ 8 files changed, 72 insertions(+), 29 deletions(-) diff --git a/INTERNAL_NOTES.md b/INTERNAL_NOTES.md index 68339d3..9a84987 100644 --- a/INTERNAL_NOTES.md +++ b/INTERNAL_NOTES.md @@ -50,3 +50,8 @@ in modules.csv.j2 : # TODO, this value are usefull for test for analyse between 13 and 14. # move that values in data/extra_script/modules.csv # and let this template with only 'base' module. + + + +TODO when launching container : +- install odoo : ``pip install -e /odoo/src/odoo`` diff --git a/odoo_openupgrade_wizard/cli/cli_init.py b/odoo_openupgrade_wizard/cli/cli_init.py index 24f6ac4..57c47f5 100644 --- a/odoo_openupgrade_wizard/cli/cli_init.py +++ b/odoo_openupgrade_wizard/cli/cli_init.py @@ -3,9 +3,10 @@ from pathlib import Path import click from odoo_openupgrade_wizard.configuration_version_dependant import ( + get_odoo_version_settings, get_odoo_versions, - get_python_libraries, get_python_major_version, + get_python_minor_version_short, get_version_options, ) from odoo_openupgrade_wizard.tools.tools_odoo import get_odoo_env_path @@ -68,6 +69,9 @@ def init( odoo_versions = get_odoo_versions( float(initial_version), float(final_version) ) + odoo_version_settings = get_odoo_version_settings( + float(initial_version), float(final_version) + ) # 2. Compute Migration Steps @@ -133,6 +137,7 @@ def init( project_name=project_name, steps=steps, odoo_versions=odoo_versions, + odoo_version_settings=odoo_version_settings, ) # 7. Ensure module list file exists @@ -154,7 +159,6 @@ def init( ensure_file_exists_from_template( path_version / Path("python_requirements.txt"), "odoo/python_requirements.txt.j2", - python_libraries=get_python_libraries(odoo_version), ) # Create debian requirements file @@ -183,6 +187,9 @@ def init( "odoo/Dockerfile.j2", odoo_version=odoo_version, python_major_version=get_python_major_version(odoo_version), + python_minor_version_short=get_python_minor_version_short( + odoo_version + ), ) # Create 'src' folder that will contain all the odoo code diff --git a/odoo_openupgrade_wizard/configuration_version_dependant.py b/odoo_openupgrade_wizard/configuration_version_dependant.py index d135b89..d379158 100644 --- a/odoo_openupgrade_wizard/configuration_version_dependant.py +++ b/odoo_openupgrade_wizard/configuration_version_dependant.py @@ -6,44 +6,42 @@ _ODOO_VERSION_TEMPLATES = [ { "version": 8.0, "python_major_version": "python2", - "python_libraries": [], + "python_minor_version_short": "py27", }, { "version": 9.0, "python_major_version": "python2", - "python_libraries": ["openupgradelib==2.0.0"], + "python_minor_version_short": "py27", }, { "version": 10.0, "python_major_version": "python2", - "python_libraries": ["openupgradelib==2.0.0"], + "python_minor_version_short": "py27", }, { "version": 11.0, "python_major_version": "python3", - "python_libraries": ["openupgradelib==2.0.0"], + "python_minor_version_short": "py36", }, { "version": 12.0, "python_major_version": "python3", - "python_libraries": [ - "git+https://github.com/grap/openupgradelib.git" - "@2.0.1#egg=openupgradelib" - ], + "python_minor_version_short": "py37", }, { "version": 13.0, "python_major_version": "python3", - "python_libraries": ["openupgradelib"], + "python_minor_version_short": "py37", }, { "version": 14.0, "python_major_version": "python3", - "python_libraries": ["openupgradelib"], + "python_minor_version_short": "py39", }, { "version": 15.0, "python_major_version": "python3", + "python_minor_version_short": "py39", "python_libraries": ["openupgradelib"], }, ] @@ -71,6 +69,12 @@ def get_python_major_version(version: float) -> str: return get_version_template(version)["python_major_version"] +def get_python_minor_version_short(version: float) -> str: + """Return the default minor python version (py27, py38) of Odoo for + a given version""" + return get_version_template(version)["python_minor_version_short"] + + def get_version_options(mode: str) -> list: """Get options available for version click argument. Arguments: @@ -88,10 +92,27 @@ def get_version_options(mode: str) -> list: return version_options +def get_odoo_version_settings( + initial_version: float, final_version: float +) -> list: + """Return a list of odoo version settings from the initial version to the final + version + """ + result = [] + for version_template in _ODOO_VERSION_TEMPLATES: + if ( + version_template["version"] >= initial_version + and version_template["version"] <= final_version + ): + result.append(version_template) + return result + + def get_odoo_versions(initial_version: float, final_version: float) -> list: """Return a list of odoo versions from the initial version to the final version """ + # TODO, call get_odoo_version_settings() and call keys() result = [] for version_template in _ODOO_VERSION_TEMPLATES: if ( diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index a3ba7ba..d3209b5 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -12,6 +12,14 @@ odoo_versions: - {{ odoo_version }} {%- endfor %} + +odoo_version_settings: +{%- for setting in odoo_version_settings %} + {{setting['version']}}: + python_minor_version_short: {{setting['python_minor_version_short']}} +{%- endfor %} + + migration_steps: {%- for step in steps %} - name: {{ step['name'] }} diff --git a/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 b/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 index a2d32e4..2620928 100644 --- a/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 +++ b/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 @@ -1,22 +1,17 @@ -FROM odoo:{{ odoo_version }} -MAINTAINER GRAP, Coop It Easy - -# Set User root for installations -USER root - -# 1. Make available files in the containers +FROM ghcr.io/acsone/odoo-bedrock:{{ odoo_version }}-{{python_minor_version_short}}-latest +COPY ./src/odoo /odoo/src/odoo COPY debian_requirements.txt /debian_requirements.txt - COPY python_requirements.txt /python_requirements.txt # 2. Install extra debian packages -RUN apt-get update || true &&\ - xargs apt-get install -y --no-install-recommends