Commit eea58121 authored by Dylan Page's avatar Dylan Page Committed by Guillaume Binet

Add docker support for installing package dependencies (#1245)

parent 5273c2e5
...@@ -63,6 +63,10 @@ def install_packages(req_path: Path): ...@@ -63,6 +63,10 @@ def install_packages(req_path: Path):
Return an exc_info if it fails otherwise None. Return an exc_info if it fails otherwise None.
""" """
def is_docker():
with open('/proc/1/cgroup') as d:
return 'docker' in d.read()
log.info('Installing packages from "%s".', req_path) log.info('Installing packages from "%s".', req_path)
# use sys.executable explicitly instead of just 'pip' because depending on how the bot is deployed # use sys.executable explicitly instead of just 'pip' because depending on how the bot is deployed
# 'pip' might not be available on PATH: for example when installing errbot on a virtualenv and # 'pip' might not be available on PATH: for example when installing errbot on a virtualenv and
...@@ -75,6 +79,9 @@ def install_packages(req_path: Path): ...@@ -75,6 +79,9 @@ def install_packages(req_path: Path):
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and (sys.base_prefix != sys.prefix)): if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and (sys.base_prefix != sys.prefix)):
# this is a virtualenv, so we can use it directly # this is a virtualenv, so we can use it directly
subprocess.check_call(pip_cmdline + ['install', '--requirement', str(req_path)]) subprocess.check_call(pip_cmdline + ['install', '--requirement', str(req_path)])
elif is_docker():
# this is a docker container, so we can use it directly
subprocess.check_call(pip_cmdline + ['install', '--requirement', str(req_path)])
else: else:
# otherwise only install it as a user package # otherwise only install it as a user package
subprocess.check_call(pip_cmdline + ['install', '--user', '--requirement', str(req_path)]) subprocess.check_call(pip_cmdline + ['install', '--user', '--requirement', str(req_path)])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment