Skip to content
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
1 change: 1 addition & 0 deletions changes.d/+5eef8dbb.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
otools-convert: give better instructions of what is left to do after the conversion has run
1 change: 1 addition & 0 deletions changes.d/83.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
otools-conversion: handle the conversion of the ADDONS_PATH environment variable in Dockerfile
75 changes: 59 additions & 16 deletions odoo_tools/conversion/convert_new_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@
import sys
from dataclasses import dataclass

try:
import odoorpc
except ImportError:
print(
"WARNING: odoorpc is not available, you will not be able to fetch "
"the list of installed modules from a running instance. "
"To fix this, run `pip install odoorpc`.",
file=sys.stderr,
)
odoorpc = None

from ..config import get_conf_key
from ..utils.path import root_path
from ..utils.proj import get_current_version
Expand Down Expand Up @@ -62,16 +51,16 @@ def generate_report():

1. check the diff between Dockerfile and Dockerfile.bak.

* update the ADDONS_PATH environment variable (`odoo/src` and
`odoo/external-src/enterprise` have moved,
`odoo-cloud-platform` must be removed)
* check the ADDONS_PATH environment variable: the paths have changed and the script may not know of
the specificities of your project (esp. paid addons)
* check other environment variables which could have been set
* check the differences introduced by an ongoing migration process

meld Dockerfile Dockerfile.bak


2. check the diff between docker-compose.yml and docker-compose.yml.bak
2. check the diff between docker-compose.yml and docker-compose.yml.bak and restore any customizations
you could have done (environment variables...)

meld docker-compose.yml docker-compose.yml.bak

Expand All @@ -82,7 +71,18 @@ def generate_report():
files for these that are placed in patches/odoo and patches/enterprise/
respectively. They will be processed by alphabetical order.

5. run `docker build .` and fix any build issues
* if you have patch files in the  `patches/` directory that don't match any pending merge in
`pending-merges.d/src.yml` or `pending-merges.d/enterprise.yml`, remove them
* if you have pending merges in `pending-merges.d/src.yml` (resp. `pending-merges.d/enterprise.yml`)
and you have the matching patch files in the `patches/` directory, move the patch files to `patches/odoo/`
(resp. `patches/enterprise/`)
* if you have pending merges in `pending-merges.d/src.yml` (resp. `pending-merges.d/enterprise.yml`)
but you don't have the matching patch files in the `patches/`, you can regenerate them with
`otools-pending add <url-to-commit>`

5. run `docker build .` and fix any build issues. The base Python version may have changed, so you
could need to update the version of some dependencies that were frozen to be compatible with Python 3.9
for instance.

6. configure github actions on your repository -> see
https://confluence.camptocamp.com/confluence/display/DEV/How+to+deploy+Github+Actions+on+odoo+projects
Expand Down Expand Up @@ -281,9 +281,52 @@ def remove_files():
raise ValueError(f"unexpected file {name}. Is it a symlink?")


def convert_env_lines(old_env_lines):
new_env_lines = []
for line in old_env_lines:
new_line = (
line.replace(
"/odoo/src/addons", "/odoo/src/odoo/odoo/addons, /odoo/src/odoo/addons"
Copy link
Member

Choose a reason for hiding this comment

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

/odoo/src/odoo/odoo/addons I don't remember seeing it. It exists or is it a typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's the path of the base addons. Not sure why I had issues without this. I'll double check

Copy link
Member

Choose a reason for hiding this comment

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

/odoo/src/addons + /odoo/src/odoo/addons should be enough IMO, the other one doesn't exist

Copy link
Member

Choose a reason for hiding this comment

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

The replace seems strange. I may be missing something.

Copy link
Member Author

Choose a reason for hiding this comment

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

there is 1 directory in the "old style" image, and I had to replace it with the 2 addons directories of Odoo (addons/ and odoo/addons/ ) in the new style image

)
.replace("/odoo/external-src/paid-modules", "/odoo/odoo/paid-modules")
.replace("/odoo/external-src/enterprise", "/odoo/src/enterprise")
.replace("/odoo/external-src", "/odoo/odoo/external-src")
.replace("/odoo/local-src", "/odoo/odoo/addons")
)
if "odoo-cloud-platform" in new_line:
continue
new_env_lines.append(new_line)
return new_env_lines


def copy_dockerfile():
shutil.move("odoo/Dockerfile", "Dockerfile.bak")
old_env_lines = []
with open("Dockerfile.bak") as old_dockerfile:
found_env = False
for line in old_dockerfile:
Comment on lines 303 to +307
Copy link
Contributor

Choose a reason for hiding this comment

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

Now pathlib is mandatory for this repo.

Suggested change
shutil.move("odoo/Dockerfile", "Dockerfile.bak")
old_env_lines = []
with open("Dockerfile.bak") as old_dockerfile:
found_env = False
for line in old_dockerfile:
old_dockerfile = Path("odoo/Dockerfile").rename("Dockerfile.bak")
new_dockerfile = Path("Dockerfile")
old_env_lines = []
found_env = False
with old_dockerfile.open() as fobj:
for line in fobj:

if line.strip().startswith("ENV ADDONS"):
found_env = True
if found_env:
old_env_lines.append(line)
if not line.strip().endswith("\\"):
found_env = False
subprocess.run(["git", "rm", "-f", "odoo/Dockerfile"], check=False)
new_env_lines = convert_env_lines(old_env_lines)
new_docker_file_lines = []
with open("Dockerfile") as new_dockerfile:
found_env = False
for line in new_dockerfile:
Comment on lines +317 to +319
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with open("Dockerfile") as new_dockerfile:
found_env = False
for line in new_dockerfile:
found_env = False
with new_dockerfile.open() as fobj:
for line in fobj:

if line.strip().startswith("ENV ADDONS"):
found_env = True
new_docker_file_lines += new_env_lines
if found_env:
if not line.strip().endswith("\\"):
found_env = False
else:
new_docker_file_lines.append(line)
with open("Dockerfile", "w") as new_dockerfile:
new_dockerfile.writelines(new_docker_file_lines)
Comment on lines +328 to +329
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with open("Dockerfile", "w") as new_dockerfile:
new_dockerfile.writelines(new_docker_file_lines)
with new_dockerfile.open("w") as fobj:
fobj.writelines(new_docker_file_lines)



def parse_args():
Expand Down