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

View File

@ -1,4 +1,6 @@
import multiprocessing import multiprocessing
import os
import json
bind = "127.0.0.1:8000" bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1 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 keepalive = 5
# daemon = True # Detaches the server from the controlling terminal and enters the background. disabled for now # daemon = True # Detaches the server from the controlling terminal and enters the background. disabled for now
# logging # 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" 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 capture_output = True
# debug settings which need to be commented out in prod # 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_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_tags = Tag.objects.annotate(num_books=Count('book')).order_by('name')
unique_publishers = Publisher.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_ratings = Rating.objects.annotate(num_books=Count('book'))
unique_series = Series.objects.annotate(num_books=Count('book')).order_by('sort') unique_series = Series.objects.annotate(num_books=Count('book')).order_by('sort')

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

View File

@ -11,7 +11,7 @@ RUN pip install -r requirements.txt
RUN apk add nginx supervisor RUN apk add nginx supervisor
# do nginx stuff # do nginx stuff
RUN adduser -D -g 'www' www # RUN adduser -D -g 'www' www
RUN mkdir -p /run/nginx RUN mkdir -p /run/nginx
COPY ./deployment/nginx.conf /etc/nginx/ COPY ./deployment/nginx.conf /etc/nginx/
@ -19,11 +19,9 @@ COPY ./deployment/nginx.conf /etc/nginx/
COPY ./CalibreWebCompanion ./CalibreWebCompanion COPY ./CalibreWebCompanion ./CalibreWebCompanion
## gunicorn borks started with supervisord ## gunicorn borks started with supervisord
COPY ./supervisord.conf /etc/ COPY ./deployment/supervisord.conf /etc/
ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf
# create some dirs
RUN mkdir /usr/src/app/logs
# docker run --publish 8000:80 \ # docker run --publish 8000:80 \
# -v '/home/massiveatoms/Desktop/logs:/usr/src/app/data' \ # -v '/home/massiveatoms/Desktop/logs:/usr/src/app/data' \

View File

@ -3,7 +3,7 @@ worker_processes 1;
# user nobody nogroup; # user nobody nogroup;
# user massiveatoms; # TEMP disabled # user massiveatoms; # TEMP disabled
# user nobody nobody; # for systems with 'nobody' as a group instead # user nobody nobody; # for systems with 'nobody' as a group instead
# error_log /home/massiveatoms/Desktop/logs/nginx.log warn; error_log /usr/src/app/data/logs/nginx.log warn;
# pid /var/run/nginx.pid; # pid /var/run/nginx.pid;
events { events {
@ -49,10 +49,10 @@ http {
keepalive_timeout 5; keepalive_timeout 5;
# # MASSIVEATOMS # # MASSIVEATOMS
# location /download/ { location /download/ {
# alias "/run/media/massiveatoms/1AEEEA6EEEEA421D/Documents and Settings/MassiveAtoms/Documents/Calibre Library/"; alias "/usr/src/app/calibredir";
# # Never forget the fact that this little statement being root instead of alias caused us to lose more than a day troubleshooting # Never forget the fact that this little statement being root instead of alias caused us to lose more than a day troubleshooting
# } }
location /static/ { location /static/ {
alias "/usr/src/app/CalibreWebCompanion/static/"; alias "/usr/src/app/CalibreWebCompanion/static/";