Skip to content
Snippets Groups Projects
Commit 3018214afb36 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: use supprocess.call when not starting several dockers to allow the use of pdb

parent ac732db1c937
No related branches found
Tags 15.3.0
No related merge requests found
......@@ -214,6 +214,16 @@
else:
logging.info("Test image found")
# options is only used with subprocess call
options = [
'--name',
project_name,
'--rm',
'--publish',
'8069:8069',
'--tty',
'--interactive',
]
binds = []
arg = [
'start',
......@@ -257,6 +267,8 @@
# auto detect local ip
if use_host_network:
local_ip = '127.0.0.1'
options.append('--network')
options.append('host')
else:
local_ip = None
try:
......@@ -376,16 +388,18 @@
arg.append('--addons-path')
arg.append(','.join(all_addons_dir))
# add volumes
odoo_host_config = docker_client.create_host_config(
binds=binds,
port_bindings={8069: 8069},
network_mode='host' if use_host_network else 'bridge',
)
logging.debug('Creating odoo container')
odoo = docker_client.create_container(
name=project_name, host_config=odoo_host_config,
image=image, command=arg, tty=True)
logging.debug('Starting odoo container')
docker_client.start(odoo.get('Id'))
if start_postgresql:
# use docker-py to be able to stop both the database and odoo
# add volumes
odoo_host_config = docker_client.create_host_config(
binds=binds,
port_bindings={8069: 8069},
network_mode='host' if use_host_network else 'bridge',
)
logging.debug('Creating odoo container')
odoo = docker_client.create_container(
name=project_name, host_config=odoo_host_config,
image=image, command=arg, tty=True)
logging.debug('Starting odoo container')
docker_client.start(odoo.get('Id'))
......@@ -391,19 +405,19 @@
def signal_handler(code, frame):
if code == signal.SIGINT:
logging.debug('You pressed Ctrl+C!')
if isRunning(docker_client, odoo.get('Id')):
logging.info('Stopping odoo')
docker_client.stop(odoo.get('Id'))
logging.info('Removing container odoo')
docker_client.remove_container(odoo.get('Id'))
if start_postgresql:
logging.info('Stopping postgresql')
docker_client.stop(pg.get('Id'))
logging.info('Removing container postgresql')
docker_client.remove_container(pg.get('Id'))
sys.exit(0)
# TODO add a kill of pg when crashing
signal.signal(signal.SIGINT, signal_handler)
logging.info('Press Ctrl+C to quit')
def signal_handler(code, frame):
if code == signal.SIGINT:
logging.debug('You pressed Ctrl+C!')
if isRunning(docker_client, odoo.get('Id')):
logging.info('Stopping odoo')
docker_client.stop(odoo.get('Id'))
logging.info('Removing container odoo')
docker_client.remove_container(odoo.get('Id'))
if start_postgresql:
logging.info('Stopping postgresql')
docker_client.stop(pg.get('Id'))
logging.info('Removing container postgresql')
docker_client.remove_container(pg.get('Id'))
sys.exit(0)
# TODO add a kill of pg when crashing
signal.signal(signal.SIGINT, signal_handler)
logging.info('Press Ctrl+C to quit')
......@@ -409,12 +423,12 @@
# print docker logs of odoo
stream = docker_client.logs(odoo.get('Id'), stream=True, follow=True)
while isRunning(docker_client, odoo.get('Id')):
try:
for log in stream:
sys.stdout.write(log)
except ConnectionError:
# If there is no log for some time requests throw some errors
# we ignore them
pass
# print docker logs of odoo
stream = docker_client.logs(odoo.get('Id'), stream=True, follow=True)
while isRunning(docker_client, odoo.get('Id')):
try:
for log in stream:
sys.stdout.write(log)
except ConnectionError:
# If there is no log for some time requests throw some errors
# we ignore them
pass
......@@ -420,7 +434,19 @@
# Clean up, just in case
signal_handler(signal.SIGINT, None)
# TODO add handling of signal to restart odoo
# Clean up, just in case
signal_handler(signal.SIGINT, None)
# TODO add handling of signal to restart odoo
else:
# use call to allow usage of pdb
for bind in binds:
options.append('--volume')
options.append(bind)
cmd = ['docker', 'run']
cmd.extend(options)
cmd.append(image)
cmd.extend(arg)
logging.debug(cmd)
call(cmd)
def getVolume(docker_client, data_volume_name):
"""Return the volume passed in parameter, creating it if it does not exists
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment