Commit c69de514 authored by David Haynes's avatar David Haynes 🙆

Migrate to consolidated settings model

- plus CI now uses pipenv
parent cb93750f
Pipeline #3718 failed with stage
in 1 minute and 30 seconds
...@@ -12,8 +12,9 @@ before_script: ...@@ -12,8 +12,9 @@ before_script:
- apt-get update -qy - apt-get update -qy
- apt-get install -y mysql-client default-libmysqlclient-dev python-mysqldb - apt-get install -y mysql-client default-libmysqlclient-dev python-mysqldb
gdal-bin libproj-dev proj-data proj-bin binutils gdal-bin libproj-dev proj-data proj-bin binutils
- pip install -r requirements/test.txt
- cd whats-open/ - cd whats-open/
- pip install pipenv
- pipenv install --system --deploy
- export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" - export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9"
| fold -w 60 | head -n1 2>/dev/null) | fold -w 60 | head -n1 2>/dev/null)
- export WOPEN_EMAIL_DOMAIN="@masonlive.gmu.edu" - export WOPEN_EMAIL_DOMAIN="@masonlive.gmu.edu"
......
...@@ -27,3 +27,4 @@ services: ...@@ -27,3 +27,4 @@ services:
- WOPEN_DB_HOST=db - WOPEN_DB_HOST=db
- WOPEN_DB_PORT=3306 - WOPEN_DB_PORT=3306
- WOPEN_SUPERUSER=admin - WOPEN_SUPERUSER=admin
- WOPEN_ENV="dev"
...@@ -6,7 +6,6 @@ done ...@@ -6,7 +6,6 @@ done
export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null) export WOPEN_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
python whats-open/manage.py flush --no-input
python whats-open/manage.py makemigrations python whats-open/manage.py makemigrations
python whats-open/manage.py makemigrations api python whats-open/manage.py makemigrations api
python whats-open/manage.py migrate python whats-open/manage.py migrate
......
...@@ -11,6 +11,9 @@ http://www.django-rest-framework.org/api-guide/routers/ ...@@ -11,6 +11,9 @@ http://www.django-rest-framework.org/api-guide/routers/
from django.urls import include, path from django.urls import include, path
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
# Other Imports
from rest_framework.routers import DefaultRouter
# App Imports # App Imports
from .views import ( from .views import (
CategoryViewSet, CategoryViewSet,
...@@ -20,9 +23,6 @@ from .views import ( ...@@ -20,9 +23,6 @@ from .views import (
AlertViewSet, AlertViewSet,
) )
# Other Imports
from rest_framework.routers import DefaultRouter
# Instantiate our DefaultRouter # Instantiate our DefaultRouter
ROUTER = DefaultRouter() ROUTER = DefaultRouter()
......
...@@ -8,8 +8,8 @@ Do not touch at all. This is the main entry point for interacting with Django. ...@@ -8,8 +8,8 @@ Do not touch at all. This is the main entry point for interacting with Django.
import os import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.local") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/local.py
Development settings and globals.
"""
# Import the base settings and override where necessary
from .base import *
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
settings/production.py
Production settings and globals.
"""
# Python std. lib imports
from os import environ
# Django Imports
from django.core.exceptions import ImproperlyConfigured
# Import the base settings and override where necessary
from .base import *
def get_env_setting(setting):
"""
Get the environment setting or return exception
"""
try:
return environ[setting]
except KeyError as ex:
print(str(ex))
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
"""
HOST CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production
ALLOWED_HOSTS = ["*"]
"""
DEBUG CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False
"""
CACHE CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
"""
SECRET CONFIGURATION
"""
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = get_env_setting("WOPEN_SECRET_KEY")
########## END SECRET CONFIGURATION
...@@ -6,23 +6,34 @@ settings/base.py ...@@ -6,23 +6,34 @@ settings/base.py
Base Django settings for whats-open. Base Django settings for whats-open.
""" """
# Python std. lib. imports # Python std. lib. imports
import os
import sys import sys
from os.path import abspath, dirname, join, normpath from os import path, environ
from sys import path
# DEV vs PROD
if environ["WOPEN_ENV"] != "production":
DEBUG = True
# dummy cache for development-- doesn't actually cache things
CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
else:
DEBUG = False
CACHES = {
"default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": "localhost:6379"}
}
ALLOWED_HOSTS = ["*"]
SECRET_KEY = environ["WOPEN_SECRET_KEY"]
""" """
PATH CONFIGURATION PATH CONFIGURATION
""" """
# Absolute filesystem path to the Django project directory: # Absolute filesystem path to the Django project directory:
DJANGO_ROOT = dirname(dirname(abspath(__file__))) DJANGO_ROOT = path.dirname(path.dirname(path.abspath(__file__)))
# Absolute filesystem path to the top-level project folder: # Absolute filesystem path to the top-level project folder:
SITE_ROOT = dirname(DJANGO_ROOT) SITE_ROOT = path.dirname(DJANGO_ROOT)
# Add our project to our pythonpath, this way we don't need to type our project # Add our project to our pythonpath, this way we don't need to type our project
# name in our dotted import paths: # name in our dotted import paths:
path.append(DJANGO_ROOT) sys.path.append(DJANGO_ROOT)
""" """
MANAGER CONFIGURATION MANAGER CONFIGURATION
...@@ -71,7 +82,7 @@ MEDIA CONFIGURATION ...@@ -71,7 +82,7 @@ MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
# Absolute filesystem path to the directory that will hold user-uploaded files. # Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/" # Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = normpath(join(SITE_ROOT, "media")) MEDIA_ROOT = path.normpath(path.join(SITE_ROOT, "media"))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
# URL that handles the media served from MEDIA_ROOT. Make sure to use a # URL that handles the media served from MEDIA_ROOT. Make sure to use a
...@@ -87,7 +98,7 @@ STATIC FILE CONFIGURATION ...@@ -87,7 +98,7 @@ STATIC FILE CONFIGURATION
# Don't put anything in this directory yourself; store your static files # Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/" # Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = normpath(join(SITE_ROOT, "static")) STATIC_ROOT = path.normpath(path.join(SITE_ROOT, "static"))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
# URL prefix for static files. # URL prefix for static files.
...@@ -122,7 +133,7 @@ ALLOWED_HOSTS = ["*"] ...@@ -122,7 +133,7 @@ ALLOWED_HOSTS = ["*"]
FIXTURE CONFIGURATION FIXTURE CONFIGURATION
""" """
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (normpath(join(SITE_ROOT, "fixtures")),) FIXTURE_DIRS = (path.normpath(path.join(SITE_ROOT, "fixtures")),)
""" """
DATABASE CONFIGURATION DATABASE CONFIGURATION
...@@ -132,11 +143,11 @@ DATABASE CONFIGURATION ...@@ -132,11 +143,11 @@ DATABASE CONFIGURATION
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.contrib.gis.db.backends.mysql", "ENGINE": "django.contrib.gis.db.backends.mysql",
"NAME": os.environ["WOPEN_DB_NAME"], "NAME": environ["WOPEN_DB_NAME"],
"USER": os.environ["WOPEN_DB_USER"], "USER": environ["WOPEN_DB_USER"],
"PASSWORD": os.environ["WOPEN_DB_PASSWORD"], "PASSWORD": environ["WOPEN_DB_PASSWORD"],
"HOST": os.environ["WOPEN_DB_HOST"], "HOST": environ["WOPEN_DB_HOST"],
"PORT": os.environ["WOPEN_DB_PORT"], "PORT": environ["WOPEN_DB_PORT"],
} }
} }
...@@ -148,9 +159,9 @@ TEMPLATES = [ ...@@ -148,9 +159,9 @@ TEMPLATES = [
"BACKEND": "django.template.backends.django.DjangoTemplates", "BACKEND": "django.template.backends.django.DjangoTemplates",
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
"DIRS": [ "DIRS": [
normpath(join(SITE_ROOT, "templates")), path.normpath(path.join(SITE_ROOT, "templates")),
# may specify to avoid requiring paths # may specify to avoid requiring paths
normpath(join(SITE_ROOT, "api/templates")), path.normpath(path.join(SITE_ROOT, "api/templates")),
], ],
"OPTIONS": { "OPTIONS": {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
......
...@@ -21,8 +21,8 @@ urlpatterns = [ ...@@ -21,8 +21,8 @@ urlpatterns = [
path("admin/doc/", include("django.contrib.admindocs.urls")), path("admin/doc/", include("django.contrib.admindocs.urls")),
# /admin - The admin panels # /admin - The admin panels
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
# /api-auth - API Auth page # /auth - API Auth page
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), path("auth/", include("rest_framework.urls", namespace="rest_framework")),
# /logout - Redirect to the homepage on logout # /logout - Redirect to the homepage on logout
path("logout/", django.contrib.auth.views.logout, {"next_page": "/"}), path("logout/", django.contrib.auth.views.logout, {"next_page": "/"}),
] ]
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