Removed hardcoded paths, make workflow changes

I removed some hardcoded paths for logging and where the default db should be located.
I also organized deployment stuff a bit
This commit is contained in:
TinyAtoms
2020-08-15 02:40:03 -03:00
parent 1b8d81bd3c
commit 75099ca05e
7 changed files with 60 additions and 43 deletions

View File

@ -66,36 +66,37 @@ STATIC_ROOT = BASE_DIR + "/static/"
# logfile = usersettings["LOGFILE"]
# LOGGING = {
# "version": 1,
# "disable_existing_loggers": False,
# "root": {"level": "INFO", "handlers": ["file"]},
# "handlers": {
# "file": {
# "level": "INFO",
# "class": "logging.FileHandler",
# "filename": usersettings["LOGFILE"],
# "formatter": "app",
# },
# },
# "loggers": {
# "django": {
# "handlers": ["file"],
# "level": "INFO",
# "propagate": True
# },
# },
# "formatters": {
# "app": {
# "format": (
# u"%(asctime)s [%(levelname)-8s] "
# "(%(module)s.%(funcName)s) %(message)s"
# ),
# "datefmt": "%Y-%m-%d %H:%M:%S",
# },
# },
# }
logfile = usersettings["LOGFOLDER"] + "django.log"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"root": {"level": "INFO", "handlers": ["file"]},
"handlers": {
"file": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": logfile,
"formatter": "app",
},
},
"loggers": {
"django": {
"handlers": ["file"],
"level": "INFO",
"propagate": True
},
},
"formatters": {
"app": {
"format": (
u"%(asctime)s [%(levelname)-8s] "
"(%(module)s.%(funcName)s) %(message)s"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
}
## ##
########################################################################
@ -188,10 +189,15 @@ WSGI_APPLICATION = 'CalibreWebCompanion.wsgi.application'
## DATBASE ##
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
if usersettings["ISDOCKER"]:
defaultdb_path = "/usr/src/app/data/"
else:
defaultdb_path = BASE_DIR
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME': os.path.join(defaultdb_path, 'db.sqlite3'),
},
'calibre': {
'ENGINE': 'django.db.backends.sqlite3',

View File

@ -1,4 +1,6 @@
import multiprocessing
import os
import json
bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1
@ -6,9 +8,20 @@ preload_app = True # By preloading an application you can save some RAM resource
keepalive = 5
# daemon = True # Detaches the server from the controlling terminal and enters the background. disabled for now
# logging
# errorlog = "/usr/src/app/data/logs/gunicorn_error.log"
with open("settings.json", "r") as jfile:
settings = json.load(jfile)
errorlog = settings["LOGFOLDER"] + "/gunicorn_error.log"
loglevel = "warning"
# accesslog = "/usr/src/app/data/logs/gunicorn_access.log"
accesslog = settings["LOGFOLDER"] + "/gunicorn_access.log"
if not os.path.isdir("/usr/src/app/data/logs"):
os.mkdir("/usr/src/app/data/logs")
if not os.path.isfile(errorlog):
os.system('touch {}'.format(errorlog))
if not os.path.isfile(accesslog):
os.system('touch {}'.format(accesslog))
capture_output = True
# debug settings which need to be commented out in prod

View File

@ -15,7 +15,7 @@ def filters(request):
unique_authors = Author.objects.only('name', "id").annotate(num_books=Count('book')).order_by('name')
unique_tags = Tag.objects.annotate(num_books=Count('book')).order_by('name')
unique_publishers = Publisher.objects.annotate(num_books=Count('book')).order_by('name')
unique_languages = Language.objects.annotate(num_books=Count('book')).order_by('rating')
unique_languages = Language.objects.annotate(num_books=Count('book'))
unique_ratings = Rating.objects.annotate(num_books=Count('book'))
unique_series = Series.objects.annotate(num_books=Count('book')).order_by('sort')

0
CalibreWebCompanion/manage.py Normal file → Executable file
View File