[FIX] make all the containers working great together !
This commit is contained in:
parent
3600c7e89c
commit
1028d74db2
|
|
@ -41,10 +41,10 @@ pytest:
|
||||||
- echo $PYTHONPATH
|
- echo $PYTHONPATH
|
||||||
- poetry run pytest --version
|
- poetry run pytest --version
|
||||||
|
|
||||||
# Create a postgresql container
|
# # Create a postgresql container
|
||||||
- docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --publish 9542:5432 --name db postgres:13
|
# - docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --publish 9542:5432 --name db postgres:13
|
||||||
|
|
||||||
- poetry run pytest --cov odoo_openupgrade_wizard --verbose --verbose --exitfirst tests/cli_A_init_test.py tests/cli_B_01_get_code_test.py tests/cli_B_02_docker_build_test.py tests/cli_B_03_run_test.py
|
- poetry run pytest --cov odoo_openupgrade_wizard --verbose --verbose --exitfirst tests/cli_A_init_test.py tests/cli_B_01_get_code_test.py tests/cli_B_02_docker_build_test.py tests/cli_B_03_run_test.py tests/cli_B_05_execute_script_sql_test.py
|
||||||
|
|
||||||
# tests/cli_B_04_execute_script_python_test.py
|
# tests/cli_B_04_execute_script_python_test.py
|
||||||
# tests/cli_B_05_upgrade_test.py
|
# tests/cli_B_06_upgrade_test.py
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ from odoo_openupgrade_wizard.cli_get_code import get_code
|
||||||
from odoo_openupgrade_wizard.cli_init import init
|
from odoo_openupgrade_wizard.cli_init import init
|
||||||
from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv
|
from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv
|
||||||
from odoo_openupgrade_wizard.cli_run import run
|
from odoo_openupgrade_wizard.cli_run import run
|
||||||
from odoo_openupgrade_wizard.cli_test_dev import test_dev
|
|
||||||
from odoo_openupgrade_wizard.cli_upgrade import upgrade
|
from odoo_openupgrade_wizard.cli_upgrade import upgrade
|
||||||
from odoo_openupgrade_wizard.tools_system import ensure_folder_exists
|
from odoo_openupgrade_wizard.tools_system import ensure_folder_exists
|
||||||
|
|
||||||
|
|
@ -63,6 +62,10 @@ def main(ctx, env_folder, filestore_folder, log_level):
|
||||||
# Define all the folder required by the tools
|
# Define all the folder required by the tools
|
||||||
env_folder_path = Path(env_folder)
|
env_folder_path = Path(env_folder)
|
||||||
src_folder_path = env_folder_path / Path("./src/")
|
src_folder_path = env_folder_path / Path("./src/")
|
||||||
|
# Note: postgres folder should be a subfolder, because
|
||||||
|
# the parent folder will contain a .gitignore file
|
||||||
|
# that the postgres docker image doesn't like
|
||||||
|
postgres_folder_path = env_folder_path / Path("./postgres_data/data")
|
||||||
script_folder_path = env_folder_path / Path("./scripts/")
|
script_folder_path = env_folder_path / Path("./scripts/")
|
||||||
log_folder_path = env_folder_path / Path("./log/")
|
log_folder_path = env_folder_path / Path("./log/")
|
||||||
if not filestore_folder:
|
if not filestore_folder:
|
||||||
|
|
@ -86,6 +89,7 @@ def main(ctx, env_folder, filestore_folder, log_level):
|
||||||
# Add all global values in the context
|
# Add all global values in the context
|
||||||
ctx.obj["env_folder_path"] = env_folder_path
|
ctx.obj["env_folder_path"] = env_folder_path
|
||||||
ctx.obj["src_folder_path"] = src_folder_path
|
ctx.obj["src_folder_path"] = src_folder_path
|
||||||
|
ctx.obj["postgres_folder_path"] = postgres_folder_path
|
||||||
ctx.obj["script_folder_path"] = script_folder_path
|
ctx.obj["script_folder_path"] = script_folder_path
|
||||||
ctx.obj["log_folder_path"] = log_folder_path
|
ctx.obj["log_folder_path"] = log_folder_path
|
||||||
ctx.obj["log_prefix"] = log_prefix
|
ctx.obj["log_prefix"] = log_prefix
|
||||||
|
|
@ -114,4 +118,3 @@ main.add_command(install_from_csv)
|
||||||
main.add_command(upgrade)
|
main.add_command(upgrade)
|
||||||
main.add_command(execute_script_python)
|
main.add_command(execute_script_python)
|
||||||
main.add_command(execute_script_sql)
|
main.add_command(execute_script_sql)
|
||||||
main.add_command(test_dev)
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,18 @@ def init(
|
||||||
ctx.obj["filestore_folder_path"], mode="777", git_ignore_content=True
|
ctx.obj["filestore_folder_path"], mode="777", git_ignore_content=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# 5. ensure main configuration file exists
|
# 5. ensure postgres data folder exists
|
||||||
|
ensure_folder_exists(
|
||||||
|
ctx.obj["postgres_folder_path"].parent,
|
||||||
|
mode="777",
|
||||||
|
git_ignore_content=True,
|
||||||
|
)
|
||||||
|
ensure_folder_exists(
|
||||||
|
ctx.obj["postgres_folder_path"],
|
||||||
|
mode="777",
|
||||||
|
)
|
||||||
|
|
||||||
|
# 6. ensure main configuration file exists
|
||||||
ensure_file_exists_from_template(
|
ensure_file_exists_from_template(
|
||||||
ctx.obj["config_file_path"],
|
ctx.obj["config_file_path"],
|
||||||
templates.CONFIG_YML_TEMPLATE,
|
templates.CONFIG_YML_TEMPLATE,
|
||||||
|
|
@ -124,7 +135,7 @@ def init(
|
||||||
odoo_versions=odoo_versions,
|
odoo_versions=odoo_versions,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 6. Ensure module list file exists
|
# 7. Ensure module list file exists
|
||||||
ensure_file_exists_from_template(
|
ensure_file_exists_from_template(
|
||||||
ctx.obj["module_file_path"],
|
ctx.obj["module_file_path"],
|
||||||
templates.MODULES_CSV_TEMPLATE,
|
templates.MODULES_CSV_TEMPLATE,
|
||||||
|
|
@ -133,7 +144,7 @@ def init(
|
||||||
odoo_versions=odoo_versions,
|
odoo_versions=odoo_versions,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 7. Create one folder per version and add files
|
# 8. Create one folder per version and add files
|
||||||
for odoo_version in odoo_versions:
|
for odoo_version in odoo_versions:
|
||||||
# Create main path for each version
|
# Create main path for each version
|
||||||
path_version = get_odoo_env_path(ctx, odoo_version)
|
path_version = get_odoo_env_path(ctx, odoo_version)
|
||||||
|
|
@ -178,7 +189,7 @@ def init(
|
||||||
path_version / Path("src"), git_ignore_content=True
|
path_version / Path("src"), git_ignore_content=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# 8. Create one folder per step and add files
|
# 9. Create one folder per step and add files
|
||||||
ensure_folder_exists(ctx.obj["script_folder_path"])
|
ensure_folder_exists(ctx.obj["script_folder_path"])
|
||||||
|
|
||||||
for step in steps:
|
for step in steps:
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ def install_from_csv(ctx, database):
|
||||||
odoo_instance = OdooInstance(ctx, database)
|
odoo_instance = OdooInstance(ctx, database)
|
||||||
|
|
||||||
default_country_code = ctx.obj["config"].get(
|
default_country_code = ctx.obj["config"].get(
|
||||||
"default_country_code", False
|
"odoo_default_country_code", False
|
||||||
)
|
)
|
||||||
if "account" in module_names:
|
if "account" in module_names and default_country_code:
|
||||||
# Then, set correct country to the company of the current user
|
# Then, set correct country to the company of the current user
|
||||||
# Otherwise, due to poor design of Odoo, when installing account
|
# Otherwise, due to poor design of Odoo, when installing account
|
||||||
# the US localization will be installed.
|
# the US localization will be installed.
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ from odoo_openupgrade_wizard.tools_postgres import ensure_database
|
||||||
def run(ctx, step, database, stop_after_init, init_modules):
|
def run(ctx, step, database, stop_after_init, init_modules):
|
||||||
|
|
||||||
migration_step = get_migration_step_from_options(ctx, step)
|
migration_step = get_migration_step_from_options(ctx, step)
|
||||||
ensure_database(database, state="present")
|
ensure_database(ctx, database, state="present")
|
||||||
try:
|
try:
|
||||||
run_odoo(
|
run_odoo(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import click
|
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
|
||||||
@click.pass_context
|
|
||||||
def test_dev(ctx):
|
|
||||||
client = get_docker_client()
|
|
||||||
client.containers.list(filters={"name": "db"})[0]
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
CONFIG_YML_TEMPLATE = """
|
CONFIG_YML_TEMPLATE = """
|
||||||
project_name: {{ project_name }}
|
project_name: {{ project_name }}
|
||||||
|
|
||||||
host_odoo_xmlrpc_port: 9069
|
postgres_image_name: postgres:13
|
||||||
|
postgres_container_name: {{project_name}}-db
|
||||||
|
postgres_host_port: 9432
|
||||||
|
|
||||||
host_postgres_port: 9432
|
odoo_host_xmlrpc_port: 9069
|
||||||
|
odoo_default_country_code: FR
|
||||||
default_country_code: FR
|
|
||||||
|
|
||||||
odoo_versions:
|
odoo_versions:
|
||||||
{% for odoo_version in odoo_versions %}
|
{% for odoo_version in odoo_versions %}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,11 @@ def build_image(path, tag):
|
||||||
def run_container(
|
def run_container(
|
||||||
image_name,
|
image_name,
|
||||||
container_name,
|
container_name,
|
||||||
command=False,
|
command=None,
|
||||||
ports=False,
|
ports=False,
|
||||||
volumes=False,
|
volumes=False,
|
||||||
links=False,
|
environments={},
|
||||||
|
links={},
|
||||||
detach=False,
|
detach=False,
|
||||||
auto_remove=False,
|
auto_remove=False,
|
||||||
):
|
):
|
||||||
|
|
@ -54,12 +55,16 @@ def run_container(
|
||||||
if links:
|
if links:
|
||||||
for k, v in links.items():
|
for k, v in links.items():
|
||||||
debug_docker_command += " --link {k}:{v}\\\n".format(k=k, v=v)
|
debug_docker_command += " --link {k}:{v}\\\n".format(k=k, v=v)
|
||||||
|
if environments:
|
||||||
|
for k, v in environments.items():
|
||||||
|
debug_docker_command += " --env {k}={v}\\\n".format(k=k, v=v)
|
||||||
if auto_remove:
|
if auto_remove:
|
||||||
debug_docker_command += " --rm"
|
debug_docker_command += " --rm"
|
||||||
if detach:
|
if detach:
|
||||||
debug_docker_command += " --detach"
|
debug_docker_command += " --detach"
|
||||||
debug_docker_command += " %s\\\n" % (image_name)
|
debug_docker_command += " %s" % (image_name)
|
||||||
debug_docker_command += " %s" % (command)
|
if command:
|
||||||
|
debug_docker_command += " \\\n%s" % (command)
|
||||||
logger.debug("DOCKER COMMAND:\n %s" % debug_docker_command)
|
logger.debug("DOCKER COMMAND:\n %s" % debug_docker_command)
|
||||||
|
|
||||||
container = client.containers.run(
|
container = client.containers.run(
|
||||||
|
|
@ -68,6 +73,12 @@ def run_container(
|
||||||
command=command,
|
command=command,
|
||||||
ports=ports,
|
ports=ports,
|
||||||
volumes=volumes,
|
volumes=volumes,
|
||||||
|
environment=environments,
|
||||||
|
# environment=[
|
||||||
|
# "POSTGRES_USER=odoo",
|
||||||
|
# "POSTGRES_PASSWORD=odoo",
|
||||||
|
# "POSTGRES_DB=postgres",
|
||||||
|
# ],
|
||||||
links=links,
|
links=links,
|
||||||
detach=detach,
|
detach=detach,
|
||||||
auto_remove=auto_remove,
|
auto_remove=auto_remove,
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,17 @@ def run_odoo(
|
||||||
shell: bool = False,
|
shell: bool = False,
|
||||||
demo: bool = False,
|
demo: bool = False,
|
||||||
):
|
):
|
||||||
# TODO, check if stop_after_init and detached_container are redondant.
|
logger.info(
|
||||||
|
"Launching Odoo Container (Release {release}) for {db_text}"
|
||||||
|
" in {action} mode. Demo Data is {demo_text}.".format(
|
||||||
|
release=migration_step["release"],
|
||||||
|
db_text=database and "database '%s'" % database or "any databases",
|
||||||
|
action=migration_step["action"] == "update"
|
||||||
|
and "regular"
|
||||||
|
or "OpenUpgrade",
|
||||||
|
demo_text=demo and "enabled" or "disabled",
|
||||||
|
)
|
||||||
|
)
|
||||||
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
||||||
env_path = ctx.obj["env_folder_path"]
|
env_path = ctx.obj["env_folder_path"]
|
||||||
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
|
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
|
||||||
|
|
@ -167,14 +177,14 @@ def run_odoo(
|
||||||
get_docker_container_name(ctx, migration_step),
|
get_docker_container_name(ctx, migration_step),
|
||||||
command=command,
|
command=command,
|
||||||
ports={
|
ports={
|
||||||
"8069": ctx.obj["config"]["host_odoo_xmlrpc_port"],
|
"8069": ctx.obj["config"]["odoo_host_xmlrpc_port"],
|
||||||
"5432": ctx.obj["config"]["host_postgres_port"],
|
# "5432": ctx.obj["config"]["postgres_host_port"],
|
||||||
},
|
},
|
||||||
volumes=[
|
volumes=[
|
||||||
"%s:/env/" % (env_path),
|
"%s:/env/" % (env_path),
|
||||||
"%s:/odoo_env/" % (odoo_env_path),
|
"%s:/odoo_env/" % (odoo_env_path),
|
||||||
],
|
],
|
||||||
links={"db": "db"},
|
links={ctx.obj["config"]["postgres_container_name"]: "db"},
|
||||||
detach=detached_container,
|
detach=detached_container,
|
||||||
auto_remove=True,
|
auto_remove=True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
def get_odoo_url(ctx) -> str:
|
def get_odoo_url(ctx) -> str:
|
||||||
return "http://0.0.0.0:%d" % (ctx.obj["config"]["host_odoo_xmlrpc_port"])
|
return "http://0.0.0.0:%d" % (ctx.obj["config"]["odoo_host_xmlrpc_port"])
|
||||||
|
|
||||||
|
|
||||||
_ODOO_RPC_MAX_TRY = 10
|
_ODOO_RPC_MAX_TRY = 10
|
||||||
|
|
@ -30,7 +30,7 @@ class OdooInstance:
|
||||||
rpc_connexion = odoorpc.ODOO(
|
rpc_connexion = odoorpc.ODOO(
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
"jsonrpc",
|
"jsonrpc",
|
||||||
port=ctx.obj["config"]["host_odoo_xmlrpc_port"],
|
port=ctx.obj["config"]["odoo_host_xmlrpc_port"],
|
||||||
timeout=_ODOO_RPC_TIMEOUT,
|
timeout=_ODOO_RPC_TIMEOUT,
|
||||||
)
|
)
|
||||||
# connexion is OK
|
# connexion is OK
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,58 @@
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
from odoo_openupgrade_wizard.tools_docker import (
|
||||||
|
get_docker_client,
|
||||||
|
run_container,
|
||||||
|
)
|
||||||
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
||||||
|
|
||||||
|
|
||||||
def get_postgres_container():
|
def get_postgres_container(ctx):
|
||||||
client = get_docker_client()
|
client = get_docker_client()
|
||||||
containers = client.containers.list(filters={"name": "db"})
|
image_name = ctx.obj["config"]["postgres_image_name"]
|
||||||
if not containers:
|
container_name = ctx.obj["config"]["postgres_container_name"]
|
||||||
raise Exception("Postgresql container not found with name 'db'.")
|
containers = client.containers.list(filters={"name": container_name})
|
||||||
|
if containers:
|
||||||
return containers[0]
|
return containers[0]
|
||||||
|
|
||||||
|
logger.info("Launching Postgres Container. (Image %s)" % image_name)
|
||||||
|
container = run_container(
|
||||||
|
image_name,
|
||||||
|
container_name,
|
||||||
|
ports={
|
||||||
|
"5432": ctx.obj["config"]["postgres_host_port"],
|
||||||
|
},
|
||||||
|
environments={
|
||||||
|
"POSTGRES_USER": "odoo",
|
||||||
|
"POSTGRES_PASSWORD": "odoo",
|
||||||
|
"POSTGRES_DB": "postgres",
|
||||||
|
"PGDATA": "/var/lib/postgresql/data/pgdata",
|
||||||
|
},
|
||||||
|
volumes=[
|
||||||
|
"%s:/env/" % ctx.obj["env_folder_path"],
|
||||||
|
"%s:/var/lib/postgresql/data/pgdata/"
|
||||||
|
% ctx.obj["postgres_folder_path"],
|
||||||
|
],
|
||||||
|
detach=True,
|
||||||
|
)
|
||||||
|
# TODO, improve me.
|
||||||
|
time.sleep(3)
|
||||||
|
return container
|
||||||
|
|
||||||
def execute_sql_file(request):
|
|
||||||
|
def execute_sql_file(ctx, request, sql_file):
|
||||||
|
# TODO.
|
||||||
|
# Note : work on path in a docker context.
|
||||||
|
# container = get_postgres_container(ctx)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def execute_sql_request(request, database="postgres"):
|
def execute_sql_request(ctx, request, database="postgres"):
|
||||||
container = get_postgres_container()
|
container = get_postgres_container(ctx)
|
||||||
docker_command = (
|
docker_command = (
|
||||||
"psql"
|
"psql"
|
||||||
" --username=odoo"
|
" --username=odoo"
|
||||||
|
|
@ -47,7 +79,7 @@ def execute_sql_request(request, database="postgres"):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def ensure_database(database: str, state="present"):
|
def ensure_database(ctx, database: str, state="present"):
|
||||||
"""
|
"""
|
||||||
- Connect to postgres container.
|
- Connect to postgres container.
|
||||||
- Check if the database exist.
|
- Check if the database exist.
|
||||||
|
|
@ -56,7 +88,7 @@ def ensure_database(database: str, state="present"):
|
||||||
"""
|
"""
|
||||||
request = "select datname FROM pg_database WHERE datistemplate = false;"
|
request = "select datname FROM pg_database WHERE datistemplate = false;"
|
||||||
|
|
||||||
result = execute_sql_request(request)
|
result = execute_sql_request(ctx, request)
|
||||||
|
|
||||||
if state == "present":
|
if state == "present":
|
||||||
if [database] in result:
|
if [database] in result:
|
||||||
|
|
@ -66,14 +98,14 @@ def ensure_database(database: str, state="present"):
|
||||||
request = "CREATE DATABASE {database} owner odoo;".format(
|
request = "CREATE DATABASE {database} owner odoo;".format(
|
||||||
database=database
|
database=database
|
||||||
)
|
)
|
||||||
execute_sql_request(request)
|
execute_sql_request(ctx, request)
|
||||||
else:
|
else:
|
||||||
if [database] not in result:
|
if [database] not in result:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info("Drop database '%s' ..." % database)
|
logger.info("Drop database '%s' ..." % database)
|
||||||
request = "DROP DATABASE {database};".format(database=database)
|
request = "DROP DATABASE {database};".format(database=database)
|
||||||
execute_sql_request(request)
|
execute_sql_request(ctx, request)
|
||||||
|
|
||||||
|
|
||||||
def execute_sql_files_pre_migration(
|
def execute_sql_files_pre_migration(
|
||||||
|
|
@ -86,6 +118,9 @@ def execute_sql_files_pre_migration(
|
||||||
script_folder / Path(f)
|
script_folder / Path(f)
|
||||||
for f in os.listdir(script_folder)
|
for f in os.listdir(script_folder)
|
||||||
if os.path.isfile(os.path.join(script_folder, f))
|
if os.path.isfile(os.path.join(script_folder, f))
|
||||||
and f[-3:] == ".sql"
|
and f[-4:] == ".sql"
|
||||||
]
|
]
|
||||||
sql_files = sorted(sql_files)
|
sql_files = sorted(sql_files)
|
||||||
|
|
||||||
|
for sql_file in sql_files:
|
||||||
|
execute_sql_file(ctx, database, sql_file)
|
||||||
|
|
|
||||||
2
tests/cli_B_05_execute_script_sql_test.py
Normal file
2
tests/cli_B_05_execute_script_sql_test.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
def test_cli_execute_script_sql():
|
||||||
|
return
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
|
|
||||||
project_name: test-cli
|
project_name: test-cli
|
||||||
|
|
||||||
host_odoo_xmlrpc_port: 9069
|
postgres_image_name: postgres:13
|
||||||
|
postgres_container_name: test-cli-db
|
||||||
|
postgres_host_port: 9432
|
||||||
|
|
||||||
host_postgres_port: 9432
|
odoo_host_xmlrpc_port: 9069
|
||||||
|
odoo_default_country_code: FR
|
||||||
default_country_code: FR
|
|
||||||
|
|
||||||
odoo_versions:
|
odoo_versions:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user