linuxserver / docker-babybuddy

GNU General Public License v3.0
38 stars 12 forks source link

Allow custom DJANGO_SETTINGS_MODULE via env vars #22

Closed tpansino closed 1 year ago

tpansino commented 1 year ago

linuxserver.io



Description:

Benefits of this PR and context:

Django's settings system is incredibly flexible. Allowing users to volume-mount a custom settings file, and point to it via the customary DJANGO_SETTINGS_MODULE env var allows the user to do things like this:

(Taken from my own settings file)

# Extend the existing settings of the project
from .base import *

# Enable Django's Remote User header authentication feature, for use with Authelia/Authentik/Oauth2 Proxy
# See https://docs.djangoproject.com/en/4.0/howto/auth-remote-user/
# This is something Baby Buddy doesn't officially support, but thanks to Django, we can just turn it on with a few settings
REMOTE_USER_AUTH = bool(strtobool(os.getenv("REMOTE_USER_AUTH", "False")))

if REMOTE_USER_AUTH:
  REMOTE_USER_AUTH_HEADER = os.getenv("REMOTE_USER_AUTH_HEADER", "HTTP_REMOTE_USER")

  MIDDLEWARE.append('babybuddy.remote_user_middleware.CustomRemoteUserMiddleware')
  AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.RemoteUserBackend']
  REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] = ['rest_framework.authentication.RemoteUserAuthentication']

# Override some security settings that the project doesn't support setting via env vars
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

# Enable the logging functionality, which the project doesn't do
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'root': {
        'handlers': ['console'],
        'level': 'WARNING',
    },
}

And also - in the 2 files I edited, this was the only env var that wasn't customizable, so it seemed like a simple oversight 😅

How Has This Been Tested?

I have been pointing to the a custom settings module for several months with no issues.

Source / References:

LinuxServer-CI commented 1 year ago

I am a bot, here are the test results for this PR: https://ci-tests.linuxserver.io/lspipepr/babybuddy/v1.13.2-pkg-db765aef-pr-22/index.html https://ci-tests.linuxserver.io/lspipepr/babybuddy/v1.13.2-pkg-db765aef-pr-22/shellcheck-result.xml

aptalca commented 1 year ago

Thanks for the PR, but it wasn't oversight. We use the settings upstream uses and provides.

Making it customizable would lead to too many support requests we are simply not equipped to deal with.

Feel free to map your own custom babybuddy.settings.base into the app folder. Keep in mind that you'll be on your own.

tpansino commented 1 year ago

Hang on though - upstream also has a custom production.example.py file, which sets some of the things I'm setting in my snippet above. That's how I figured out this pattern.

I get where you're coming from about the support here, but if there's no way to fork production.example.py and point to it, then how are you supposed to set some of those settings like SESSION_COOKIE_SECURE?

tpansino commented 1 year ago

Feel free to map your own custom babybuddy.settings.base into the app folder. Keep in mind that you'll be on your own.

Also, I did do that, but my hacks broke today because of the reconfiguration of the S6 stuff. Which is fine, I'm just trying to give back so others don't have to be broken by future changes like that.

github-actions[bot] commented 1 year ago

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.