Improve production setup

This commit is contained in:
Sascha Ißbrücker
2019-07-05 01:26:52 +02:00
parent c489f354c5
commit 70f9fb9818
15 changed files with 120 additions and 77 deletions

View File

@@ -0,0 +1,5 @@
# Use dev settings as default, use production if dev settings do not exist
try:
from .dev import *
except:
from .prod import *

View File

@@ -13,7 +13,8 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
@@ -22,9 +23,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'kgq$h3@!!vbb6*nzfz(dbze=*)zsroqa8gvc0#1gx$3cd8z99^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']
# Application definition
@@ -38,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'sass_processor',
'widget_tweaks',
'django_generate_secret_key',
]
MIDDLEWARE = [
@@ -123,8 +125,9 @@ STATIC_URL = '/static/'
# Collect static files in static folder
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# Turn off SASS compilation by default
SASS_PROCESSOR_ENABLED = False
# Location where generated CSS files are saved
SASS_PROCESSOR_ENABLED = True
SASS_PROCESSOR_ROOT = os.path.join(BASE_DIR, 'tmp', 'build', 'styles')
# Add SASS preprocessor finder to resolve generated CSS
@@ -138,26 +141,3 @@ STATICFILES_FINDERS = [
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'bookmarks', 'styles'),
]
# Logging with SQL statements
LOGGING = {
'version': 1,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
}
},
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['console'],
}
}
}

View File

@@ -0,0 +1 @@
# Placeholder, can be mounted in a Docker container with a custom settings

40
siteroot/settings/dev.py Normal file
View File

@@ -0,0 +1,40 @@
"""
Development settings for linkding webapp
"""
# Start from development settings
# noinspection PyUnresolvedReferences
from .base import *
# Turn on debug mode
DEBUG = True
# Turn on SASS compilation
SASS_PROCESSOR_ENABLED = True
# Enable debug logging
# Logging with SQL statements
LOGGING = {
'version': 1,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
}
},
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['console'],
}
}
}
# Import custom settings
# noinspection PyUnresolvedReferences
from .custom import *

33
siteroot/settings/prod.py Normal file
View File

@@ -0,0 +1,33 @@
"""
Production settings for linkding webapp
"""
# Start from development settings
# noinspection PyUnresolvedReferences
import os
from .base import *
# Turn of debug mode
DEBUG = False
# Turn off SASS compilation
SASS_PROCESSOR_ENABLED = False
# Try read secret key from file
try:
with open(os.path.join(BASE_DIR, 'secretkey.txt')) as f:
SECRET_KEY = f.read().strip()
except:
pass
# Set ALLOWED_HOSTS
# By default look in the HOST_NAME environment variable, if that is not set then allow all hosts
host_name = os.environ.get('HOST_NAME')
if host_name:
ALLOWED_HOSTS = [host_name]
else:
ALLOWED_HOSTS = ['*']
# Import custom settings
# noinspection PyUnresolvedReferences
from .custom import *

View File

@@ -1 +0,0 @@
# Placeholder, can be overridden in Docker container with a custom settings like ALLOWED_HOSTS

View File

@@ -1,18 +0,0 @@
"""
Production settings for linkding webapp
"""
# Start from development settings
# noinspection PyUnresolvedReferences
from .settings import *
# Turn of debug mode
DEBUG = False
# Turn off SASS compilation
SASS_PROCESSOR_ENABLED = False
ALLOWED_HOSTS = ['*']
# Import custom settings
# noinspection PyUnresolvedReferences
from .settings_custom import *