[REF] refactor docker 'volumes' arg

This commit is contained in:
Sylvain LE GAL 2022-05-06 15:09:56 +02:00
parent a0eb99fd48
commit 5a4f777fd4
3 changed files with 20 additions and 30 deletions

View File

@ -27,7 +27,7 @@ def run_container(
container_name,
command=None,
ports=False,
volumes=False,
volumes={},
environments={},
links={},
detach=False,
@ -44,20 +44,14 @@ def run_container(
internal_port=internal_port, host_port=host_port
)
)
if volumes:
for volume in volumes:
external_path, internal_path = volume.split(":")
debug_docker_command += (
" --volume {external_path}:{internal_path}\\\n".format(
external_path=external_path, internal_path=internal_path
)
)
if links:
for k, v in links.items():
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)
for k, v in volumes.items():
debug_docker_command += " --volume {k}:{v}\\\n".format(
k=str(k), v=str(v)
)
for k, v in environments.items():
debug_docker_command += " --env {k}={v}\\\n".format(k=k, v=v)
for k, v in links.items():
debug_docker_command += " --link {k}:{v}\\\n".format(k=k, v=v)
if auto_remove:
debug_docker_command += " --rm"
if detach:
@ -72,13 +66,8 @@ def run_container(
name=container_name,
command=command,
ports=ports,
volumes=volumes,
volumes=[str(k) + ":" + str(v) for k, v in volumes.items()],
environment=environments,
# environment=[
# "POSTGRES_USER=odoo",
# "POSTGRES_PASSWORD=odoo",
# "POSTGRES_DB=postgres",
# ],
links=links,
detach=detach,
auto_remove=auto_remove,

View File

@ -186,10 +186,10 @@ def run_odoo(
and alternative_xml_rpc_port
or ctx.obj["config"]["odoo_host_xmlrpc_port"],
},
volumes=[
"%s:/env/" % (env_path),
"%s:/odoo_env/" % (odoo_env_path),
],
volumes={
env_path: "/env/",
odoo_env_path: "/odoo_env/",
},
links={ctx.obj["config"]["postgres_container_name"]: "db"},
detach=detached_container,
auto_remove=True,

View File

@ -32,11 +32,12 @@ def get_postgres_container(ctx):
"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"],
],
volumes={
ctx.obj["env_folder_path"]: "/env/",
ctx.obj[
"postgres_folder_path"
]: "/var/lib/postgresql/data/pgdata/",
},
detach=True,
)
# TODO, improve me.