Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Docker container with a specific user #5556

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/development/buildenvironments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ option.
After this image is downloaded, you can update your settings to use the new
image -- see `Configuration`_.

.. warning::

There is a known bug when using our Docker images on Linux to build project's documentation that uses Conda.
In case you need to work locally with projects that need Conda to build,
you will need to re-build our Docker image to adjust some filesystem user persmissions.
See our `current work in progress guide`_ for more information.

.. _`Docker`: http://docker.com
.. _`Docker Hub repository`: https://hub.docker.com/r/readthedocs/build/
.. _`container image repo`: https://github.com/rtfd/readthedocs-docker-images
.. _`current work in progress guide`: https://github.com/rtfd/readthedocs.org/pull/4608

Configuration
-------------
Expand Down
1 change: 1 addition & 0 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ def create_container(self):
host_config=self.get_container_host_config(),
detach=True,
environment=self.environment,
user=settings.DOCKER_USER,
)
client.start(container=self.container_id)
except ConnectionError:
Expand Down
9 changes: 9 additions & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ def USE_PROMOS(self): # noqa
# This settings has been deprecated in favor of DOCKER_IMAGE_SETTINGS
DOCKER_BUILD_IMAGES = None
DOCKER_LIMITS = {'memory': '200m', 'time': 600}

# User used to create the container.
# In production we use the same user than the one defined by the
# ``USER docs`` instruction inside the Dockerfile.
# In development, we can use the "UID:GID" of the current user running the
# instance to avoid file permissions issues.
# https://docs.docker.com/engine/reference/run/#user
DOCKER_USER = 'docs:docs'

DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
DOCKER_VERSION = 'auto'
DOCKER_DEFAULT_VERSION = 'latest'
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def DATABASES(self): # noqa
# Disable password validators on development
AUTH_PASSWORD_VALIDATORS = []

# UID and GID used to create the Docker container. It defaults to the
# current UID and GID that it's running the Django app.
DOCKER_USER = f'{os.geteuid()}:{os.getegid()}'

@property
def LOGGING(self): # noqa - avoid pep8 N802
logging = super().LOGGING
Expand Down