[GH-ISSUE #187] hc/settings.py template -> resolve from env variables #133

Closed
opened 2026-02-25 23:41:18 +03:00 by kerem · 1 comment
Owner

Originally created by @lukasmrtvy on GitHub (Sep 19, 2018).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/187

Is possible to do in hc/settings.py something like this ?

import os
...
if os.environ.get("DB_TYPE") == "mysql" or os.environ.get("DB_TYPE") == "postgres" :
 DATABASES = {
                    'default': {
                        'ENGINE':   'django.db.backends' + os.environ['DB_TYPE'],
                        'HOST':     os.environ['DB_HOST'],
                        'PORT':     os.environ['DB_PORT'],
                        'NAME':     os.environ['DB_NAME'],
                        'USER':     os.environ['DB_USER'],
                        'PASSWORD': os.environ['DB_PASSWORD'],
                        'TEST': {'CHARSET': 'UTF8'}
                     }
                }

SLACK_CLIENT_ID = repr(os.environ.get('SLACK_CLIENT_ID','default'))
REGISTRATION_OPEN = os.environ.get("REGISTRATION_OPEN",'True') == "True"
PUSHOVER_EMERGENCY_EXPIRATION = os.environ.get('PUSHOVER_EMERGENCY_EXPIRATION','13370')
...

It would be a great if this can be a resolved from env variables.
It will not break a default behaviour if You set a default values.
Thanks

Originally created by @lukasmrtvy on GitHub (Sep 19, 2018). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/187 Is possible to do in hc/settings.py something like this ? ``` import os ... if os.environ.get("DB_TYPE") == "mysql" or os.environ.get("DB_TYPE") == "postgres" : DATABASES = { 'default': { 'ENGINE': 'django.db.backends' + os.environ['DB_TYPE'], 'HOST': os.environ['DB_HOST'], 'PORT': os.environ['DB_PORT'], 'NAME': os.environ['DB_NAME'], 'USER': os.environ['DB_USER'], 'PASSWORD': os.environ['DB_PASSWORD'], 'TEST': {'CHARSET': 'UTF8'} } } SLACK_CLIENT_ID = repr(os.environ.get('SLACK_CLIENT_ID','default')) REGISTRATION_OPEN = os.environ.get("REGISTRATION_OPEN",'True') == "True" PUSHOVER_EMERGENCY_EXPIRATION = os.environ.get('PUSHOVER_EMERGENCY_EXPIRATION','13370') ... ``` It would be a great if this can be a resolved from env variables. It will not break a default behaviour if You set a default values. Thanks
kerem closed this issue 2026-02-25 23:41:18 +03:00
Author
Owner

@cuu508 commented on GitHub (Sep 19, 2018):

I've been thinking about putting this in a local_settings.py.example file but you make a good point–if the default behavior doesn't change then this can go in the settings.py.

I've also been thinking about what prefix to use for the environment variables. I have used HC_SOME_SETTING myself in the past. I've also seen HEALTHCHECKS_SOME_SETTING in several Dockerfiles. Going with plain SOME_SETTING would be the nicest.

So, in short, I like this idea.

os.environ.get can be a little bit more concise: os.getenv

<!-- gh-comment-id:422797037 --> @cuu508 commented on GitHub (Sep 19, 2018): I've been thinking about putting this in a `local_settings.py.example` file but you make a good point–if the default behavior doesn't change then this can go in the `settings.py`. I've also been thinking about what prefix to use for the environment variables. I have used `HC_SOME_SETTING` myself in the past. I've also seen `HEALTHCHECKS_SOME_SETTING` in several Dockerfiles. Going with plain `SOME_SETTING` would be the nicest. So, in short, I like this idea. `os.environ.get` can be a little bit more concise: `os.getenv`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#133
No description provided.