fixed Dockerfile - I only needed to expose 443, not sure what I was thinking mashing this web code with DB, anyway... also switched to using env var rather than hostname to pick up DEV/PROD, and now show that in base.html. Updated Dockerfile and requirements to prep for putting ldap/auth in, will need to copy some stuff from PA later. finally removed console debugs in book.html

This commit is contained in:
2022-06-19 16:15:51 +10:00
parent 6087bdab9e
commit 4725f006bc
6 changed files with 37 additions and 17 deletions

3
BUGs
View File

@@ -1,4 +1,4 @@
#### BUGS (next-19) #### BUGS (next-20)
### DB/back-end ### DB/back-end
@@ -11,3 +11,4 @@ BUG-6: author,series, etc. do not have explicit ordering like sub-books... sort
- add/remove authors, and after save they are ordered by author.id, not order of addition (prob. needs book_author_link to have an auth_num) - add/remove authors, and after save they are ordered by author.id, not order of addition (prob. needs book_author_link to have an auth_num)
#### SHOWSTOPPER: #### SHOWSTOPPER:
BUG-19: show unrated gets all books, looks like ORM is not joining as I expected -- I wonder if it relates to that SAWarning about book id being written in the wrong spot?

View File

@@ -1,8 +1,23 @@
FROM ubuntu:20.04 FROM ubuntu:20.04
WORKDIR /code WORKDIR /code
RUN apt-get update && apt-get -y install python3-pip python3-psycopg2 libpq-dev gunicorn USER root
ENV PJM_UID=500
ENV PJM_GID=500
RUN groupadd -g ${PJM_GID} mythtv && useradd -r -u ${PJM_UID} -g ${PJM_GID} mythtv
ENV TZ=Australia/Melbourne
RUN truncate -s0 /tmp/preseed.cfg && \
(echo "tzdata tzdata/Areas select Australia" >> /tmp/preseed.cfg) && \
(echo "tzdata tzdata/Zones/Australia select Melbourne" >> /tmp/preseed.cfg) && \
debconf-set-selections /tmp/preseed.cfg && \
rm -f /etc/timezone /etc/localtime && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
apt-get install -y tzdata
## cleanup of files from setup
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get update && apt-get -y install python3-pip python3-psycopg2 libpq-dev gunicorn python3-ldap
COPY requirements.txt requirements.txt COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
EXPOSE 443 EXPOSE 443
COPY . . COPY . .
CMD ["gunicorn", "--bind=0.0.0.0:443", "--workers=2","--threads=2", "--certfile", "/etc/letsencrypt/live/book.depaoli.id.au/fullchain.pem", "--keyfile", "/etc/letsencrypt/live/book.depaoli.id.au/privkey.pem","main:app"] CMD gunicorn --bind=0.0.0.0:443 --workers=2 --threads=2 --certfile /etc/letsencrypt/live/book.depaoli.id.au/fullchain.pem --keyfile /etc/letsencrypt/live/book.depaoli.id.au/privkey.pem main:app --env FLASK_ENV="production" --error-logfile gunicorn.error.log --access-logfile gunicorn.log --capture-output

18
main.py
View File

@@ -7,20 +7,16 @@ from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerF
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from status import st, Status from status import st, Status
import re import re
import socket import os
####################################### Flask App globals ####################################### ####################################### Flask App globals #######################################
DEV_HOST="mara"
hostname = socket.gethostname()
print( "Running on: {}".format( hostname) )
app = Flask(__name__) app = Flask(__name__)
### what is this value? I gather I should chagne it?
# local DB conn string # local DB conn string
if hostname == DEV_HOST: if os.environ['FLASK_ENV'] == "production":
DB_URL = 'postgresql+psycopg2://ddp:NWNlfa01@127.0.0.1:5432/library'
else:
DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb:5432/library' DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb:5432/library'
else:
DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@127.0.0.1:55432/library'
app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
@@ -750,7 +746,7 @@ def main_page():
return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage()) return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage())
if __name__ == "__main__": if __name__ == "__main__":
if hostname == DEV_HOST: if os.environ['FLASK_ENV'] == "production":
app.run(host="0.0.0.0", debug=True)
else:
app.run(ssl_context=('/etc/letsencrypt/live/book.depaoli.id.au/cert.pem', '/etc/letsencrypt/live/book.depaoli.id.au/privkey.pem'), host="0.0.0.0", debug=False) app.run(ssl_context=('/etc/letsencrypt/live/book.depaoli.id.au/cert.pem', '/etc/letsencrypt/live/book.depaoli.id.au/privkey.pem'), host="0.0.0.0", debug=False)
else:
app.run(host="0.0.0.0", debug=True)

View File

@@ -1,4 +1,6 @@
flask flask
flask_login
flask-ldap3-login
sqlalchemy sqlalchemy
flask-sqlalchemy flask-sqlalchemy
SQLAlchemy-serializer SQLAlchemy-serializer
@@ -6,3 +8,7 @@ marshmallow-sqlalchemy
flask-marshmallow flask-marshmallow
flask-wtf flask-wtf
flask-bootstrap flask-bootstrap
datetime
pytz
Werkzeug
flask-compress

View File

@@ -36,7 +36,11 @@
</div> </div>
<nav class="navbar navbar-expand-lg navbar-light bg-light justify-content-between"> <nav class="navbar navbar-expand-lg navbar-light bg-light justify-content-between">
{% if config.ENV == "production" %}
<a class="navbar-brand" href="/">Books DB</a> <a class="navbar-brand" href="/">Books DB</a>
{% else %}
<a class="navbar-brand bg-secondary text-white px-2 py-0" style="border-radius:4px" href="/">Books (DEV)</a>
{% endif %}
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>

View File

@@ -93,7 +93,6 @@ function SeriesButPlus(num) {
} }
function AddBookToSeries() { function AddBookToSeries() {
console.log("add Book to series")
// Read the Number from that DIV's ID (i.e: 3 from "series-div-3") -- could // Read the Number from that DIV's ID (i.e: 3 from "series-div-3") -- could
// also be the filler (series-div-0), thats ok too // also be the filler (series-div-0), thats ok too
@@ -139,7 +138,6 @@ console.log( "reset buttons on last_div is=" + last_div.prop('id') )
} }
function RemoveBookFromSeries(sid) { function RemoveBookFromSeries(sid) {
console.log("remove Book from Series: " + sid )
$('#'+sid).remove() $('#'+sid).remove()
var num = parseInt( sid.match(/\d+/g), 10 ); var num = parseInt( sid.match(/\d+/g), 10 );