Skip to content

Commit

Permalink
🔧(databases) improve flexibility of mysql and mogodb settings
Browse files Browse the repository at this point in the history
We want to be able to configure separately each part of the
database settings (e.g. db name versus password) so that they
can come from different sources and be injected differently.
For example the password comes from a vault and is injected
via environment variables versus the database name comes from
a yaml file and is injected by mounting the file in the container.
  • Loading branch information
sampaccoud committed Sep 14, 2018
1 parent e27bff3 commit 0789ef9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
40 changes: 32 additions & 8 deletions config/cms/docker_run_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,25 @@

USER_TASKS_ARTIFACT_STORAGE = COURSE_IMPORT_EXPORT_STORAGE

# Databases

DATABASE_ENGINE = config("DATABASE_ENGINE", default="django.db.backends.mysql")
DATABASE_HOST = config("DATABASE_HOST", default="mysql")
DATABASE_PORT = config("DATABASE_PORT", default=3306, formatter=int)
DATABASE_NAME = config("DATABASE_NAME", default="edxapp")
DATABASE_USER = config("DATABASE_USER", default="edxapp_user")
DATABASE_PASSWORD = config("DATABASE_PASSWORD", default="password")

DATABASES = config(
"DATABASES",
default={
"default": {
"ENGINE": "django.db.backends.mysql",
"HOST": "mysql",
"PORT": "3306",
"NAME": "edxapp",
"USER": "fun",
"PASSWORD": "password",
"ENGINE": DATABASE_ENGINE,
"HOST": DATABASE_HOST,
"PORT": DATABASE_PORT,
"NAME": DATABASE_NAME,
"USER": DATABASE_USER,
"PASSWORD": DATABASE_PASSWORD,
}
},
formatter=json.loads,
Expand All @@ -417,9 +426,24 @@
config("MODULESTORE", default=MODULESTORE, formatter=json.loads)
)

MONGODB_PASSWORD = config("MONGODB_PASSWORD", default="")
MONGODB_HOST = config("MONGODB_HOST", default="mongodb")
MONGODB_PORT = config("MONGODB_PORT", default=27017, formatter=int)
MONGODB_NAME = config("MONGODB_NAME", default="edxapp")
MONGODB_USER = config("MONGODB_USER", default=None)
MONGODB_SSL = config("MONGODB_SSL", default=False, formatter=bool)

DOC_STORE_CONFIG = config(
"DOC_STORE_CONFIG",
default={"db": "edxapp", "host": "mongodb"},
default={
"collection": "modulestore",
"host": MONGODB_HOST,
"port": MONGODB_PORT,
"db": MONGODB_NAME,
"user": MONGODB_USER,
"password": MONGODB_PASSWORD,
"ssl": MONGODB_SSL,
},
formatter=json.loads,
)

Expand All @@ -438,7 +462,7 @@
CONTENTSTORE = config(
"CONTENTSTORE",
default={
"DOC_STORE_CONFIG": {"host": ["mongodb"], "db": "edxapp", "port": 27017},
"DOC_STORE_CONFIG": DOC_STORE_CONFIG,
"ENGINE": "xmodule.contentstore.mongo.MongoContentStore",
},
formatter=json.loads,
Expand Down
44 changes: 36 additions & 8 deletions config/lms/docker_run_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,18 +631,28 @@
"FILE_UPLOAD_STORAGE_PREFIX", default=FILE_UPLOAD_STORAGE_PREFIX
)

# Databases

# If there is a database called 'read_replica', you can use the use_read_replica_if_available
# function in util/query.py, which is useful for very large database reads

DATABASE_ENGINE = config("DATABASE_ENGINE", default="django.db.backends.mysql")
DATABASE_HOST = config("DATABASE_HOST", default="mysql")
DATABASE_PORT = config("DATABASE_PORT", default=3306, formatter=int)
DATABASE_NAME = config("DATABASE_NAME", default="edxapp")
DATABASE_USER = config("DATABASE_USER", default="edxapp_user")
DATABASE_PASSWORD = config("DATABASE_PASSWORD", default="password")

DATABASES = config(
"DATABASES",
default={
"default": {
"ENGINE": "django.db.backends.mysql",
"HOST": "mysql",
"PORT": "3306",
"NAME": "edxapp",
"USER": "fun",
"PASSWORD": "password",
"ENGINE": DATABASE_ENGINE,
"HOST": DATABASE_HOST,
"PORT": DATABASE_PORT,
"NAME": DATABASE_NAME,
"USER": DATABASE_USER,
"PASSWORD": DATABASE_PASSWORD,
}
},
formatter=json.loads,
Expand All @@ -658,16 +668,34 @@
MODULESTORE = convert_module_store_setting_if_needed(
config("MODULESTORE", default=MODULESTORE, formatter=json.loads)
)

MONGODB_PASSWORD = config("MONGODB_PASSWORD", default="")
MONGODB_HOST = config("MONGODB_HOST", default="mongodb")
MONGODB_PORT = config("MONGODB_PORT", default=27017, formatter=int)
MONGODB_NAME = config("MONGODB_NAME", default="edxapp")
MONGODB_USER = config("MONGODB_USER", default=None)
MONGODB_SSL = config("MONGODB_SSL", default=False, formatter=bool)

DOC_STORE_CONFIG = config(
"DOC_STORE_CONFIG",
default={"host": "mongodb", "db": "edxapp"},
default={
"collection": "modulestore",
"host": MONGODB_HOST,
"port": MONGODB_PORT,
"db": MONGODB_NAME,
"user": MONGODB_USER,
"password": MONGODB_PASSWORD,
"ssl": MONGODB_SSL,
},
formatter=json.loads,
)

MONGODB_LOG = config("MONGODB_LOG", default={}, formatter=json.loads)

CONTENTSTORE = config(
"CONTENTSTORE",
default={
"DOC_STORE_CONFIG": {"host": ["mongodb"], "db": "edxapp", "port": 27017},
"DOC_STORE_CONFIG": DOC_STORE_CONFIG,
"ENGINE": "xmodule.contentstore.mongo.MongoContentStore",
},
formatter=json.loads,
Expand Down
2 changes: 1 addition & 1 deletion env.d/development
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DJANGO_SETTINGS_MODULE: lms.envs.fun.docker_run
MYSQL_ROOT_PASSWORD=
MYSQL_ALLOW_EMPTY_PASSWORD=yes
MYSQL_DATABASE=edxapp
MYSQL_USER=fun
MYSQL_USER=edxapp_user
MYSQL_PASSWORD=password

# Email
Expand Down

0 comments on commit 0789ef9

Please sign in to comment.