From 7bbe8c900dd8c59bb9bbf5a0bd10ab6ac7f2ada9 Mon Sep 17 00:00:00 2001 From: MartenBE Date: Sun, 9 Aug 2020 15:51:24 +0200 Subject: [PATCH 1/7] Added cron to the Dockerfile as temporary fix until we have periodic file scanning in the backend --- .gitignore | 2 ++ README.md | 12 +++++++----- config.json | 1 - docker/Dockerfile | 28 +++++++++++++++++++++------ docker/config.json | 1 + docker/development.docker-compose.yml | 5 +++-- 6 files changed, 35 insertions(+), 14 deletions(-) delete mode 100755 config.json create mode 100644 docker/config.json diff --git a/.gitignore b/.gitignore index 765a1e4..0cca9b6 100755 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,8 @@ dmypy.json # End of https://www.gitignore.io/api/python 0 config.backup.json +config.json +!docker/config.json uwsgi.ini installer.log pyshelf_nginx.conf diff --git a/README.md b/README.md index f72142a..cbe5467 100755 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ From the main directory `pip install -r requirements.txt` +`./configure` + `cd src` `python manage.py makemigrations` @@ -90,10 +92,10 @@ From the main directory `cd ..` -`./configure` - `./importBooks` +`uwsgi --ini uwsgi.ini` + Browse to the site as defined in your apache | nginx config Running via the [Django](https://www.djangoproject.com/) test server might be possible, albeit not recomended. @@ -113,7 +115,7 @@ services: - "POSTGRES_USER=pyshelf" - "POSTGRES_DB=pyshelf" volumes: - - "pgdata:/var/lib/postgresql/data/" + - "db_data:/var/lib/postgresql/data/" pyshelf: image: "pyshelf/pyshelf" @@ -125,7 +127,7 @@ services: - db volumes: - pgdata: + db_data: ``` You'll also need a `.env` file wich sets the `LOCAL_BOOK_DIR` variable, for example: @@ -134,7 +136,7 @@ You'll also need a `.env` file wich sets the `LOCAL_BOOK_DIR` variable, for exam LOCAL_BOOK_DIR=/home/someone/books ``` -The Docker image is still new, so there could still be some issues and missing features. Feel free to create a bug-issue when you encounter a bug. Development of the Docker image is discussed in https://github.com/th3r00t/pyShelf/pull/53 . Currently the database needs to be [PostgreSQL](https://www.postgresql.org/) with the account details shown in the example `docker-compose.yml` . +The Docker image is still new, so there could still be some issues and missing features. Feel free to create a bug-issue when you encounter a bug. Development of the Docker image is discussed in https://github.com/th3r00t/pyShelf/pull/53 . Currently the database needs to be [PostgreSQL](https://www.postgresql.org/) with the account details shown in the example `docker-compose.yml`. It should become db agnostic in the future. ## In Progress diff --git a/config.json b/config.json deleted file mode 100755 index 99123e3..0000000 --- a/config.json +++ /dev/null @@ -1 +0,0 @@ -{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/Books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": ""} diff --git a/docker/Dockerfile b/docker/Dockerfile index 3f39ac5..7b4a6c6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,14 @@ + +# This file is used to build the Dockerhub image. To host pyShelf yourself for +# production, please use the official pyShelf image on +# https://hub.docker.com/r/pyshelf/pyshelf + +# Use the following commands to build and push the docker image to Dockerhub: +# +# docker build -t pyshelf/pyshelf -f .\docker\Dockerfile . +# docker login +# docker push pyshelf/pyshelf + FROM ubuntu EXPOSE 8000 @@ -5,22 +16,27 @@ EXPOSE 8000 RUN apt-get update -y RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential python3 python3-dev python3-pip python3-venv nginx-full -COPY . /pyshelf - -WORKDIR /pyshelf/ -RUN python3 -m pip install -r requirements.txt +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y cron +RUN echo "* * * * * cd /pyshelf/ && python3 importBooks >> /var/log/cron.log 2>&1" > import_books_scheduler.cron && crontab import_books_scheduler.cron COPY ./docker/pyshelf_nginx.conf /etc/nginx/sites-available/pyshelf_nginx.conf RUN ln -s /etc/nginx/sites-available/pyshelf_nginx.conf /etc/nginx/sites-enabled/ +COPY . /pyshelf +COPY ./docker/config.json /pyshelf/config.json + WORKDIR /pyshelf/ -ENTRYPOINT cd src/ \ +RUN python3 -m pip install -r requirements.txt + +WORKDIR /pyshelf/ +ENTRYPOINT cron start \ + && python3 configure \ + && cd src/ \ && python3 manage.py makemigrations \ && python3 manage.py makemigrations interface \ && python3 manage.py migrate \ && python3 manage.py migrate interface \ && cd .. \ - && python3 configure \ && python3 importBooks \ && nginx -g "daemon on;" \ && uwsgi --ini uwsgi.ini diff --git a/docker/config.json b/docker/config.json new file mode 100644 index 0000000..a2a9a84 --- /dev/null +++ b/docker/config.json @@ -0,0 +1 @@ +{"TITLE": "pyShelf E-Book Server", "VERSION": "Docker", "BOOKPATH": "/books", "DB_HOST": "db", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": ""} diff --git a/docker/development.docker-compose.yml b/docker/development.docker-compose.yml index 8ece1da..995a7be 100644 --- a/docker/development.docker-compose.yml +++ b/docker/development.docker-compose.yml @@ -1,11 +1,12 @@ version: "3.7" -# This file is used to test the docker image. To host pyShelf yourself for +# This file is used to test the Dockerhub image. To host pyShelf yourself for # production, please use the official pyShelf image on # https://hub.docker.com/r/pyshelf/pyshelf # For development, use the following command in the root folder: -# `docker-compose -f .\docker\development.docker-compose.yml up --build` +# +# docker-compose -f .\docker\development.docker-compose.yml up --build services: db: From edee4c9c4670d5fdc4d88f0a7d146ee75e6113ce Mon Sep 17 00:00:00 2001 From: th3r00t Date: Sun, 9 Aug 2020 10:42:27 -0400 Subject: [PATCH 2/7] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0cca9b6..cdc6669 100755 --- a/.gitignore +++ b/.gitignore @@ -136,4 +136,3 @@ pyshelf_nginx.conf .env tags TAGS -config.json From a6baddf611430558e02b75dfa4d2f20fb1c4773d Mon Sep 17 00:00:00 2001 From: MartenBE Date: Sun, 9 Aug 2020 17:17:14 +0200 Subject: [PATCH 3/7] Restored config.json --- .gitignore | 2 -- config.json | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 config.json diff --git a/.gitignore b/.gitignore index cdc6669..1ef8d84 100755 --- a/.gitignore +++ b/.gitignore @@ -127,8 +127,6 @@ dmypy.json # End of https://www.gitignore.io/api/python 0 config.backup.json -config.json -!docker/config.json uwsgi.ini installer.log pyshelf_nginx.conf diff --git a/config.json b/config.json new file mode 100644 index 0000000..a43c162 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": ""} From 88d0295ae130242fb20266baa5b95106ce79e2c3 Mon Sep 17 00:00:00 2001 From: MartenBE Date: Sun, 9 Aug 2020 23:52:32 +0200 Subject: [PATCH 4/7] Moved DEBUG variable to config --- config.json | 2 +- docker/Dockerfile | 2 +- docker/development.docker-compose.yml | 2 +- src/backend/lib/config.py | 1 + src/frontend/settings.py | 3 ++- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index a43c162..ebb7635 100644 --- a/config.json +++ b/config.json @@ -1 +1 @@ -{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": ""} +{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": "zz6e7o_65a7&u44mbcjpz=lh*rh+^g33dkaace5#9a2kr(5+k=", "BUILD_MODE": "DEBUG"} \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b4a6c6..684d71e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,7 +5,7 @@ # Use the following commands to build and push the docker image to Dockerhub: # -# docker build -t pyshelf/pyshelf -f .\docker\Dockerfile . +# docker build -t pyshelf/pyshelf -f ./docker/Dockerfile . # docker login # docker push pyshelf/pyshelf diff --git a/docker/development.docker-compose.yml b/docker/development.docker-compose.yml index 995a7be..c395f78 100644 --- a/docker/development.docker-compose.yml +++ b/docker/development.docker-compose.yml @@ -6,7 +6,7 @@ version: "3.7" # For development, use the following command in the root folder: # -# docker-compose -f .\docker\development.docker-compose.yml up --build +# docker-compose -f ./docker/development.docker-compose.yml up --build services: db: diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index dfa3636..b1f0142 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -37,6 +37,7 @@ class Config: self.db_user = _data["USER"] self.db_pass = _data["PASSWORD"] self.SECRET = _data["SECRET"] + self.debug_build_mode = (_data["SECRET"].casefold() == "debug") def open_file(self, _cp): """ diff --git a/src/frontend/settings.py b/src/frontend/settings.py index 0cb56e8..6e1a91d 100755 --- a/src/frontend/settings.py +++ b/src/frontend/settings.py @@ -32,8 +32,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = CONFIG.SECRET # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = TEMPLATE_DEBUG = False +DEBUG = TEMPLATE_DEBUG = CONFIG.debug_build_mode if DEBUG is True: + print("DEBUG build mode is ON") from pudb.remote import set_trace ALLOWED_HOSTS = CONFIG.allowed_hosts From 205a65cde28c0a2eb5c07ec9a078237d8edd53c1 Mon Sep 17 00:00:00 2001 From: MartenBE Date: Sun, 9 Aug 2020 23:56:14 +0200 Subject: [PATCH 5/7] Removed secret from config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index ebb7635..956e6f8 100644 --- a/config.json +++ b/config.json @@ -1 +1 @@ -{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": "zz6e7o_65a7&u44mbcjpz=lh*rh+^g33dkaace5#9a2kr(5+k=", "BUILD_MODE": "DEBUG"} \ No newline at end of file +{"TITLE": "pyShelf E-Book Server", "VERSION": "0.6.0", "BOOKPATH": "~/books", "DB_HOST": "localhost", "DB_PORT": "5432", "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", "BOOKSHELF": "data/shelf.json", "ALLOWED_HOSTS": "*", "SECRET": "", "BUILD_MODE": "DEBUG"} \ No newline at end of file From a2cd08efe7e92595ee570aea565b702d78ab2009 Mon Sep 17 00:00:00 2001 From: MartenBE Date: Sun, 9 Aug 2020 23:57:44 +0200 Subject: [PATCH 6/7] Fixed small error in Config --- src/backend/lib/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index b1f0142..d5aa5cc 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -37,7 +37,7 @@ class Config: self.db_user = _data["USER"] self.db_pass = _data["PASSWORD"] self.SECRET = _data["SECRET"] - self.debug_build_mode = (_data["SECRET"].casefold() == "debug") + self.debug_build_mode = (_data["BUILD_MODE"].casefold() == "debug") def open_file(self, _cp): """ From d0fb22dccd578e84ccfd37244eca20f8620f7643 Mon Sep 17 00:00:00 2001 From: MartenBE Date: Mon, 10 Aug 2020 00:00:44 +0200 Subject: [PATCH 7/7] Added pudb to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index c14ff50..962868d 100755 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,4 @@ mobi-python uwsgi jsonpickle django-widget-tweaks +pudb