Cookiecutter-django: Docs fail to build due to missing CELERY_BROKER_URL environment variable

Created on 29 Jul 2020  路  3Comments  路  Source: pydanny/cookiecutter-django

What happened?

My project is configured to use Celery and Docker. When I run docker-compose -f local.yml up (after building) I get the following error message from the docs container:

docs            | Running Sphinx v3.1.2
docs            | /usr/local/lib/python3.8/site-packages/environ/environ.py:437: UserWarning: Engine not recognized from url: {'NAME': '', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', 'ENGINE': ''}
docs            |   warnings.warn("Engine not recognized from url: {0}".format(config))
docs            | 
docs            | Configuration error:
docs            | There is a programmable error in your configuration file:
docs            | 
docs            | Traceback (most recent call last):
docs            |   File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 273, in get_value
docs            |     value = self.ENVIRON[var]
docs            |   File "/usr/local/lib/python3.8/os.py", line 675, in __getitem__
docs            |     raise KeyError(key) from None
docs            | KeyError: 'CELERY_BROKER_URL'
docs            | 
docs            | During handling of the above exception, another exception occurred:
docs            | 
docs            | Traceback (most recent call last):
docs            |   File "/usr/local/lib/python3.8/site-packages/sphinx/config.py", line 319, in eval_config_file
docs            |     execfile_(filename, namespace)
docs            |   File "/usr/local/lib/python3.8/site-packages/sphinx/util/pycompat.py", line 88, in execfile_
docs            |     exec(code, _globals)
docs            |   File "/docs/conf.py", line 22, in <module>
docs            |     django.setup()
docs            |   File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
docs            |     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
docs            |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
docs            |     self._setup(name)
docs            |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
docs            |     self._wrapped = Settings(settings_module)
docs            |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
docs            |     mod = importlib.import_module(self.SETTINGS_MODULE)
docs            |   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
docs            |     return _bootstrap._gcd_import(name[level:], package, level)
docs            |   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
docs            |   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
docs            |   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
docs            |   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
docs            |   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
docs            |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
docs            |   File "/app/config/settings/local.py", line 1, in <module>
docs            |     from .base import *  # noqa
docs            |   File "/app/config/settings/base.py", line 259, in <module>
docs            |     CELERY_BROKER_URL = env("CELERY_BROKER_URL")
docs            |   File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 123, in __call__
docs            |     return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
docs            |   File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 277, in get_value
docs            |     raise ImproperlyConfigured(error_msg)
docs            | django.core.exceptions.ImproperlyConfigured: Set the CELERY_BROKER_URL environment variable

Tracing back through the code I can see that indeed the CELERY_BROKER_URL environment variable is not set in the docs container, because it usually set in the entrypoint script that the django container uses. I have not used sphinx before so I don't understand why it needs this environment variable to proceed.

Manually setting the environment variable in the docs Dockerfile solves the issue, but I don't know if this proliferation of environment variable setting is best for the project so I won't submit that as a fix at this point.

I would appreciate any input on a decent way of solving this problem, I am happy to write a PR following that guidance or leave it to someone else if they want to write one.

Thanks,
Adam

Most helpful comment

Add this line to your local env file CELERY_BROKER_URL=REDIS_URL

All 3 comments

@adammsteele did you resolve this? I am also running into this. I will look into it.

  • Fresh pull as of yesterday (new project)
  • Docker version:
    image

@adammsteele did you resolve this? I am also running into this. I will look into it.

  • Fresh pull as of yesterday (new project)
  • Docker version:
    image

I ended up just deleting the docs service in local.yml as I didn鈥檛 want/need it. As I mentioned you could also add the environment variable to the docs Dockerfile and it works fine as a quick solution.

Add this line to your local env file CELERY_BROKER_URL=REDIS_URL

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bluesurfer picture bluesurfer  路  4Comments

webyneter picture webyneter  路  3Comments

StupidTAO picture StupidTAO  路  3Comments

webyneter picture webyneter  路  3Comments

huydbui picture huydbui  路  3Comments