Skip to content

MDBF-423: Change default connection to database to use host different than dock… #3

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

Closed
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DJANGO_DEBUG=True
#
# There will also be a test_{DJANGO_DB_NAME} database used for running tests.
DJANGO_DB_NAME='feedback_plugin'
DJANGO_DB_HOST='db'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on #8 it seems that one need to have docker_db_1 as an default host based on the docker_default network

DJANGO_DB_USER_NAME='feedback'
DJANGO_DB_USER_PASSWORD='A;p4rqgDt-Mf7L{z'

Expand Down
30 changes: 20 additions & 10 deletions src/feedback_plugin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ['DJANGO_DEBUG'])

ALLOWED_HOSTS = [os.environ['DJANGO_ALLOWED_HOSTS']]

DEBUG = bool(os.environ.get('DJANGO_DEBUG'))
if DEBUG == None:
DEBUG = True

if os.environ.get('DJANGO_ALLOWED_HOSTS'):
ALLOWED_HOSTS = os.environ['DJANGO_ALLOWED_HOSTS'].split(',')
# DB_HOST default value will be DNS on docker_default network for easier usage in docker-compose
# DB_HOST empty means localhost, instead one should set the unix socket and/or other host
DB_HOST = os.environ.get('DJANGO_DB_HOST')
if DB_HOST == None:
DB_HOST = 'docker_db_1'

LOG_LEVEL = os.environ.get('DJANGO_LOG_LEVEL')
if LOG_LEVEL == None:
LOG_LEVEL = 'ERROR'

# Application definition

Expand Down Expand Up @@ -72,14 +83,13 @@

WSGI_APPLICATION = 'feedback_plugin.wsgi.application'


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['DJANGO_DB_NAME'],
'NAME': os.environ.get('DJANGO_DB_NAME'),
'USER': os.environ['DJANGO_DB_USER_NAME'],
'PASSWORD': os.environ['DJANGO_DB_USER_PASSWORD'],
'HOST': 'db',
'HOST': DB_HOST,
'OPTIONS': {'charset': 'utf8',
'use_unicode': True},
'TEST': {
Expand Down Expand Up @@ -150,12 +160,12 @@
'loggers': {
'django': {
'handlers': ['console'],
'level': os.environ['DJANGO_LOG_LEVEL'],
'level': LOG_LEVEL,
'propagate': False,
},
'views': {
'handlers': ['console'],
'level': os.environ['DJANGO_LOG_LEVEL'],
'level': LOG_LEVEL,
'propagate': False,
},
},
Expand Down