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:
		@@ -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',
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
									
								
							
							
						
						
									
										0
									
								
								CalibreWebCompanion/manage.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -11,7 +11,7 @@ RUN pip install -r requirements.txt
 | 
			
		||||
RUN apk add nginx supervisor
 | 
			
		||||
 | 
			
		||||
# do nginx stuff
 | 
			
		||||
RUN adduser -D -g 'www' www
 | 
			
		||||
# RUN adduser -D -g 'www' www
 | 
			
		||||
RUN mkdir -p /run/nginx
 | 
			
		||||
COPY ./deployment/nginx.conf /etc/nginx/
 | 
			
		||||
 | 
			
		||||
@@ -19,11 +19,9 @@ COPY ./deployment/nginx.conf /etc/nginx/
 | 
			
		||||
COPY ./CalibreWebCompanion ./CalibreWebCompanion
 | 
			
		||||
 | 
			
		||||
## gunicorn borks started with supervisord
 | 
			
		||||
COPY ./supervisord.conf /etc/
 | 
			
		||||
COPY ./deployment/supervisord.conf /etc/
 | 
			
		||||
ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf
 | 
			
		||||
 | 
			
		||||
# create some dirs
 | 
			
		||||
RUN mkdir /usr/src/app/logs
 | 
			
		||||
 | 
			
		||||
# docker run --publish 8000:80 \
 | 
			
		||||
# -v '/home/massiveatoms/Desktop/logs:/usr/src/app/data' \
 | 
			
		||||
@@ -3,7 +3,7 @@ worker_processes 1;
 | 
			
		||||
# user nobody nogroup;
 | 
			
		||||
# user massiveatoms;  # TEMP disabled
 | 
			
		||||
# 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;
 | 
			
		||||
 | 
			
		||||
events {
 | 
			
		||||
@@ -49,10 +49,10 @@ http {
 | 
			
		||||
    keepalive_timeout 5;
 | 
			
		||||
 | 
			
		||||
    # # MASSIVEATOMS
 | 
			
		||||
    #   location /download/ {
 | 
			
		||||
    #     alias "/run/media/massiveatoms/1AEEEA6EEEEA421D/Documents and Settings/MassiveAtoms/Documents/Calibre Library/";
 | 
			
		||||
    #     # Never forget the fact that this little statement being root instead of alias caused us to lose more than a day troubleshooting
 | 
			
		||||
    # }
 | 
			
		||||
      location /download/ {
 | 
			
		||||
        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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
          location /static/ {
 | 
			
		||||
        alias "/usr/src/app/CalibreWebCompanion/static/";
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user