|
13 | 13 | from datetime import datetime
|
14 | 14 |
|
15 | 15 | from readthedocs.core.utils import slugify
|
| 16 | +from django.conf import settings |
16 | 17 | from django.utils.translation import ugettext_lazy as _, ugettext_noop
|
17 | 18 | from docker import Client
|
18 | 19 | from docker.utils import create_host_config
|
@@ -662,6 +663,42 @@ def get_client(self):
|
662 | 663 | )
|
663 | 664 | )
|
664 | 665 |
|
| 666 | + def get_container_host_config(self): |
| 667 | + """ |
| 668 | + Create the ``host_config`` settings for the container. |
| 669 | +
|
| 670 | + It mainly generates the proper path bindings between the Docker |
| 671 | + container and the Host by mounting them with the proper permissions. |
| 672 | + Besides, it mounts the ``GLOBAL_PIP_CACHE`` if it's set and we are under |
| 673 | + ``DEBUG``. |
| 674 | +
|
| 675 | + The object returned is passed to Docker function |
| 676 | + ``client.create_container``. |
| 677 | + """ |
| 678 | + binds = { |
| 679 | + SPHINX_TEMPLATE_DIR: { |
| 680 | + 'bind': SPHINX_TEMPLATE_DIR, |
| 681 | + 'mode': 'ro', |
| 682 | + }, |
| 683 | + MKDOCS_TEMPLATE_DIR: { |
| 684 | + 'bind': MKDOCS_TEMPLATE_DIR, |
| 685 | + 'mode': 'ro', |
| 686 | + }, |
| 687 | + self.project.doc_path: { |
| 688 | + 'bind': self.project.doc_path, |
| 689 | + 'mode': 'rw', |
| 690 | + }, |
| 691 | + } |
| 692 | + |
| 693 | + if getattr(settings, 'GLOBAL_PIP_CACHE', False) and settings.DEBUG: |
| 694 | + binds.update({ |
| 695 | + self.project.pip_cache_path: { |
| 696 | + 'bind': self.project.pip_cache_path, |
| 697 | + 'mode': 'rw', |
| 698 | + } |
| 699 | + }) |
| 700 | + return create_host_config(binds=binds) |
| 701 | + |
665 | 702 | @property
|
666 | 703 | def container_id(self):
|
667 | 704 | """Return id of container if it is valid."""
|
@@ -715,20 +752,7 @@ def create_container(self):
|
715 | 752 | exit=DOCKER_TIMEOUT_EXIT_CODE)),
|
716 | 753 | name=self.container_id,
|
717 | 754 | hostname=self.container_id,
|
718 |
| - host_config=create_host_config(binds={ |
719 |
| - SPHINX_TEMPLATE_DIR: { |
720 |
| - 'bind': SPHINX_TEMPLATE_DIR, |
721 |
| - 'mode': 'ro' |
722 |
| - }, |
723 |
| - MKDOCS_TEMPLATE_DIR: { |
724 |
| - 'bind': MKDOCS_TEMPLATE_DIR, |
725 |
| - 'mode': 'ro' |
726 |
| - }, |
727 |
| - self.project.doc_path: { |
728 |
| - 'bind': self.project.doc_path, |
729 |
| - 'mode': 'rw' |
730 |
| - }, |
731 |
| - }), |
| 755 | + host_config=self.get_container_host_config(), |
732 | 756 | detach=True,
|
733 | 757 | environment=self.environment,
|
734 | 758 | mem_limit=self.container_mem_limit,
|
|
0 commit comments