Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

Commit 4a06c6b8 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Rework settings to use envvars for containerized service

parent 2af807de
......@@ -16,24 +16,3 @@ Description of settings files:
dev.py - defines settings for a development or testing server.
Imports base.py settings and overrides/adds settings.
"""
# Import either production or test settings
try:
from .local import IS_PRODUCTION_SERVER
if IS_PRODUCTION_SERVER:
settings_file = 'production'
else:
# If IS_PRODUCTION_SERVER is not defined, use development/test settings
settings_file = 'dev'
except ImportError:
# If local.py does not exist, use development/test settings
settings_file = 'dev'
settings_module = __import__(settings_file, globals(), locals())
# Put these settings into the local scope
for setting in dir(settings_module):
# Only add uppercase variables. We use lowercase as
# temporary variables in the settings files.
if setting == setting.upper():
locals()[setting] = getattr(settings_module, setting)
from cloghandler import ConcurrentRotatingFileHandler
from datetime import datetime, timedelta
import os, time, logging
from os.path import abspath, dirname, join
from datetime import datetime, timedelta
from cloghandler import ConcurrentRotatingFileHandler
# Get local settings:
# SERVER_HOSTNAME, SERVER_FQDN, IS_PRODUCTION_SERVER, ADMINS, GRACEDB_PATHS
from .local import *
# Get secret settings:
# DEFAULT_DB_PASSWORD, DEFAULT_SECRET_KEY, TWILIO_ACCOUNT_SID,
# TWILIO_AUTH_TOKEN, TWIML_BIN
from .secret import *
import socket
# Set up path to root of project
BASE_DIR = abspath(join(dirname(__file__), "..", ".."))
......@@ -19,6 +12,10 @@ PROJECT_ROOT = join(BASE_DIR, "gracedb")
# Other useful paths
PROJECT_DATA_DIR = join(BASE_DIR, "..", "project_data")
# Server hostname and FQDN
SERVER_HOSTNAME = socket.gethostname()
SERVER_FQDN = socket.getfqdn()
# Unauthenticated access ------------------------------------------------------
# This variable controls whether unauthenticated access is allowed *ANYWHERE*
# on this service, except the home page, which is always public.
......@@ -40,6 +37,9 @@ TEST_RUNNER = 'django.test.runner.DiscoverRunner'
# ADMINS defines who gets code error notifications.
# MANAGERS defines who gets broken link notifications when
# BrokenLinkEmailsMiddleware is enabled
ADMINS = [
("Tanner Prestegard", "tanner.prestegard@ligo.org"),
]
MANAGERS = ADMINS
# Client versions allowed - pip-like specifier strings,
......@@ -55,6 +55,12 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Base URL for TwiML bins (for Twilio phone/text alerts)
TWIML_BASE_URL = 'https://handler.twilio.com/twiml/'
# TwiML bin SIDs (for Twilio)
TWIML_BIN = {
'create': 'EH761b6a35102737e3d21830a484a98a08',
'label': 'EHb596a53b9c92a41950ce1a47335fd834',
'test': 'EH6c0a168b0c6b011047afa1caeb49b241',
}
# Use timezone-aware datetimes internally
USE_TZ = True
......@@ -206,8 +212,6 @@ UPTIME_REPORT_DIR = PROJECT_DATA_DIR
RATE_INFO_FILE = join(PROJECT_DATA_DIR, "rate_info.json")
# URL prefix for serving report information (usually plots and tables)
# This is aliased to GRACEDB_PATHS["latency"] in the Apache virtualhost
# configuration. If you change this, you will need to change that.
REPORT_INFO_URL_PREFIX = "/report_info/"
# Directory for CBC IFAR Reports
......@@ -222,19 +226,6 @@ FEED_MAX_RESULTS = 50
# Django and server settings --------------------------------------------------
# Nested dict of settings for all databases
DATABASES = {
'default' : {
'NAME' : 'gracedb',
'ENGINE' : 'django.db.backends.mysql',
'USER' : 'gracedb',
'PASSWORD' : DEFAULT_DB_PASSWORD,
'OPTIONS' : {
'init_command': 'SET storage_engine=MyISAM',
},
}
}
# Location of database
GRACEDB_DATA_DIR = join(BASE_DIR, "..", "db_data")
# First level subdirs with 2 chars, second level with 1 char
......@@ -252,10 +243,6 @@ CACHES = {
}
}
# Secret key for a Django installation
# Make this unique, and don't share it with anybody.
SECRET_KEY = DEFAULT_SECRET_KEY
# List of settings for all template engines. Each item is a dict
# containing options for an individual engine
TEMPLATES = [
......
# For running a containerized version of the service that gets secrets
# from environment variables. Builds on base.py settings.
import os
from django.core.exceptions import ImproperlyConfigured
from .base import *
# Get database password from environment and check
DB_PASSWORD = os.environ.get('DJANGO_DB_PASSWORD', None)
if DB_PASSWORD is None:
raise ImproperlyConfigured('Could not get database password from envvars.')
# Secret key for a Django installation
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', None)
if SECRET_KEY is None:
raise ImproperlyConfigured('Could not get secret key from envvars.')
# Get Twilio account information from environment
# FIXME
TWILIO_ACCOUNT_SID = os.environ.get('DJANGO_TWILIO_ACCOUNT_SID', 'abcd')
TWILIO_AUTH_TOKEN = os.environ.get('DJANGO_TWILIO_AUTH_TOKEN', 'abcd')
# Database settings
DATABASES = {
'default' : {
'NAME': 'gracedb',
'ENGINE': 'django.db.backends.mysql',
'USER': os.environ.get('DJANGO_DB_USER', 'gracedb'),
'PASSWORD': DB_PASSWORD,
'HOST': os.environ.get('DJANGO_DB_HOST', ''),
'PORT': os.environ.get('DJANGO_DB_PORT', ''),
'OPTIONS': {
'init_command': 'SET storage_engine=MyISAM',
},
}
}
# Settings for a test GraceDB instance.
# Starts with base.py settings and overrides or adds to them.
from .base import *
# Settings for a test/dev 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.
import socket
from .vm import *
CONFIG_NAME = "TEST"
......@@ -45,5 +46,5 @@ if 'silk' in INSTALLED_APPS:
# it to be used through this server. You need to configure a SOCKS proxy
# on your local machine to use DJDT (see admin docs).
INTERNAL_IPS = [
socket.gethostbyname(socket.gethostname()),
socket.gethostbyname(SERVER_HOSTNAME),
]
# Settings for a production GraceDB instance.
# Starts with base.py settings and overrides or adds to them.
from .base import *
# TP 12/22/2016: I don't think we need this anymore.
#SHIB_AUTHENTICATION_SESSION_INITIATOR = 'https://archie.phys.uwm.edu/Shibboleth.sso/Login'
CONFIG_NAME = "PRODUCTION"
# TP 12/22/2016: Doesn't seem to be used anywhere.
SITE_ID = 3
# 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 *
# LVAlert Overseer settings
ALERT_XMPP_SERVERS = ["lvalert.cgca.uwm.edu"]
......
# For running a VM that is provisioned by Puppet with
# a secret.py file for secret settings
# Get secret settings:
# DEFAULT_DB_PASSWORD, DEFAULT_SECRET_KEY, TWILIO_ACCOUNT_SID,
# TWILIO_AUTH_TOKEN
from .base import *
from .secret import *
# Nested dict of settings for all databases
DATABASES = {
'default' : {
'NAME': 'gracedb',
'ENGINE': 'django.db.backends.mysql',
'USER': 'gracedb',
'PASSWORD': DEFAULT_DB_PASSWORD,
'OPTIONS': {
'init_command': 'SET storage_engine=MyISAM',
},
}
}
# Secret key for a Django installation
SECRET_KEY = DEFAULT_SECRET_KEY
......@@ -3,12 +3,12 @@ import sys
from os.path import abspath, dirname, join
# Parameters
SETTINGS_MODULE = 'config.settings'
DEFAULT_SETTINGS_MODULE = 'config.settings.dev'
PROJECT_ROOT_NAME = 'gracedb'
VENV_NAME = 'djangoenv'
# Set DJANGO_SETTINGS_MODULE environment variable if not already set
os.environ.setdefault('DJANGO_SETTINGS_MODULE', SETTINGS_MODULE)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
# Set up base dir of repository
BASE_DIR = abspath(join(dirname(__file__), ".."))
......
......@@ -5,12 +5,12 @@ from os.path import abspath, dirname, join
import sys
# Parameters
SETTINGS_MODULE = 'config.settings'
DEFAULT_SETTINGS_MODULE = 'config.settings.dev'
PROJECT_ROOT_NAME = 'gracedb'
VENV_NAME = 'djangoenv'
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', SETTINGS_MODULE)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)
# Add the project root to the python path.
BASE_DIR = abspath(dirname(__file__))
......
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