Commit 9648f155 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Rework settings for compatibility with multiple deployments

Settings have been reorganized and how different parameters are
determined has been reworked to be compatible with both a Puppet-based
VM deployment and a containerized deployment
parent 411bde82
......@@ -2,7 +2,7 @@ FROM ligo/base:stretch
LABEL name="LIGO GraceDB Django application" \
maintainer="tanner.prestegard@ligo.org" \
date="20181206"
ARG SETTINGS_MODULE="config.settings.container"
ARG SETTINGS_MODULE="config.settings.container.dev"
WORKDIR /app
ADD . /app/gracedb_project
......@@ -39,7 +39,6 @@ RUN pip install -r requirements.txt
# Give pip-installed packages priority over distribution packages
ENV PYTHONPATH /usr/local/lib/python2.7/dist-packages:$PYTHONPATH
ENV VIRTUAL_ENV dummy
# Collect static components. First step: set settings module and
# fake a few other required environment variables
......
......@@ -3,7 +3,7 @@
import os
from django.core.exceptions import ImproperlyConfigured
from .base import *
from ..base import *
# Get required variables from environment variables ---------------------------
# Get database password from environment and check
......
# Settings for a test/dev GraceDB instance running in a container
#import socket
from .base import *
CONFIG_NAME = "TEST"
# Debug settings
DEBUG = True
# Override EMBB email address
# TP (8 Aug 2017): not sure why?
EMBB_MAIL_ADDRESS = 'gracedb@{fqdn}'.format(fqdn=SERVER_FQDN)
# Add middleware
debug_middleware = 'debug_toolbar.middleware.DebugToolbarMiddleware'
MIDDLEWARE += [
debug_middleware,
#'silk.middleware.SilkyMiddleware',
#'core.middleware.profiling.ProfileMiddleware',
#'core.middleware.admin.AdminsOnlyMiddleware',
]
# Add to installed apps
INSTALLED_APPS += [
'debug_toolbar',
#'silk'
]
# Add testserver to ALLOWED_HOSTS
ALLOWED_HOSTS += ['testserver']
# Settings for django-silk profiler
SILKY_AUTHENTICATION = True
SILKY_AUTHORISATION = True
if 'silk' in INSTALLED_APPS:
# Needed to prevent RequestDataTooBig for files > 2.5 MB
# when silk is being used. This setting is typically used to
# prevent DOS attacks, so should not be changed in production.
DATA_UPLOAD_MAX_MEMORY_SIZE = 20*(1024**2)
# Tuple of IPs which are marked as internal, useful for debugging.
# Tanner (5 Dec. 2017): DON'T CHANGE THIS! Django Debug Toolbar exposes
# some headers which we want to keep hidden. So to be safe, we only allow
# it to be used through this server. You need to configure a SOCKS proxy
# on your local machine to use DJDT (see admin docs).
# FIXME
#INTERNAL_IPS = [
# socket.gethostbyname(SERVER_HOSTNAME),
#]
# Settings for a production GraceDB instance running in a container
from .base import *
DEBUG = False
# LVAlert Overseer settings
ALERT_XMPP_SERVERS = ["lvalert.cgca.uwm.edu"]
LVALERT_OVERSEER_PORTS = {
"lvalert.cgca.uwm.edu": 8000,
}
# Turn on alerts
SEND_XMPP_ALERTS = True
SEND_PHONE_ALERTS = True
SEND_EMAIL_ALERTS = True
# For running a VM that is provisioned by Puppet with a secret.py file
# for secret settings
from ..base import *
# Get secret settings:
# DEFAULT_DB_PASSWORD, DEFAULT_SECRET_KEY, TWILIO_ACCOUNT_SID,
# TWILIO_AUTH_TOKEN
from .base import *
from .secret import *
# DB_PASSWORD, SECRET_KEY, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN
from ..secret import *
import socket
# Nested dict of settings for all databases
......@@ -14,16 +12,13 @@ DATABASES = {
'NAME': 'gracedb',
'ENGINE': 'django.db.backends.mysql',
'USER': 'gracedb',
'PASSWORD': DEFAULT_DB_PASSWORD,
'PASSWORD': DB_PASSWORD,
'OPTIONS': {
'init_command': 'SET storage_engine=MyISAM',
},
}
}
# Secret key for a Django installation
SECRET_KEY = DEFAULT_SECRET_KEY
# Set up allowed hosts
SERVER_FQDN = socket.getfqdn()
SERVER_HOSTNAME = socket.gethostname()
......
......@@ -2,7 +2,7 @@
# provisioning. Starts with vm.py settings (which inherits from base.py
# settings) and overrides or adds to them.
import socket
from .vm import *
from .base import *
CONFIG_NAME = "TEST"
......
# Settings for a production GraceDB instance running on a VM with Puppet
# provisioning. Starts with vm.py settings (which inherits from base.py
# settings) and overrides or adds to them.
from .vm import *
from .base import *
# LVAlert Overseer settings
ALERT_XMPP_SERVERS = ["lvalert.cgca.uwm.edu"]
......
......@@ -3,12 +3,8 @@ import sys
from os.path import abspath, dirname, join
# Parameters
DEFAULT_SETTINGS_MODULE = 'config.settings.dev'
DEFAULT_SETTINGS_MODULE = 'config.settings.vm.dev'
PROJECT_ROOT_NAME = 'gracedb'
VENV_NAME = 'djangoenv'
# Set DJANGO_SETTINGS_MODULE environment variable if not already set
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
# Set up base dir of repository
BASE_DIR = abspath(join(dirname(__file__), ".."))
......@@ -17,15 +13,11 @@ BASE_DIR = abspath(join(dirname(__file__), ".."))
sys.path.append(BASE_DIR)
sys.path.append(join(BASE_DIR, PROJECT_ROOT_NAME))
# Activate the virtual environment
if ('VIRTUAL_ENV' not in os.environ):
VIRTUALENV_ACTIVATOR = abspath(join(BASE_DIR, '..', VENV_NAME, 'bin',
'activate_this.py'))
execfile(VIRTUALENV_ACTIVATOR, dict(__file__=VIRTUALENV_ACTIVATOR))
# Set DJANGO_SETTINGS_MODULE environment variable if it's not already set
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
# Matplotlib config directory
os.environ['MPLCONFIGDIR'] = '/tmp/'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#!/usr/bin/env python
import os
from os.path import abspath, dirname, join
from os.path import abspath, dirname, exists, join
import sys
# Parameters
DEFAULT_SETTINGS_MODULE = 'config.settings.dev'
DEFAULT_SETTINGS_MODULE = 'config.settings.vm.dev'
PROJECT_ROOT_NAME = 'gracedb'
VENV_NAME = 'djangoenv'
BASE_DIR = abspath(dirname(__file__))
VENV_PATH = abspath(join(BASE_DIR, '..', 'djangoenv'))
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
# Add the project root to the python path.
BASE_DIR = abspath(dirname(__file__))
sys.path.append(join(BASE_DIR, PROJECT_ROOT_NAME))
# Set up virtualenv if not active
if ('VIRTUAL_ENV' not in os.environ):
VIRTUALENV_ACTIVATOR = abspath(join(BASE_DIR, '..', VENV_NAME, 'bin',
# Set up virtualenv if it exists and is not active
if (exists(VENV_PATH) and 'VIRTUAL_ENV' not in os.environ):
VIRTUALENV_ACTIVATOR = abspath(join(VENV_PATH, 'bin',
'activate_this.py'))
execfile(VIRTUALENV_ACTIVATOR, dict(__file__=VIRTUALENV_ACTIVATOR))
# Set DJANGO_SETTINGS_MODULE environment variable
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
try:
from django.core.management import execute_from_command_line
except ImportError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment