From e8a33e876c32b821f946af6c22cda44a008010c9 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 2 Dec 2023 15:00:31 -0700 Subject: [PATCH] make docker path consistent, and enhance instructions --- README.md | 17 ++++++++++++----- app.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7f6b286..cf8685d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ``` export PUSH_SERVER_VERSION=0.1 -# also in build.sh +# This command is also in build.sh docker build --tag py-push-server:amd-$PUSH_SERVER_VERSION --platform linux/amd64 . docker save -o ~/dl/py-push-server-amd-$PUSH_SERVER_VERSION.tar py-push-server:amd-$PUSH_SERVER_VERSION @@ -22,7 +22,7 @@ bzip2 -d py-push-server-amd-$PUSH_SERVER_VERSION.tar.bz2 sudo docker load -i py-push-server-amd-$PUSH_SERVER_VERSION.tar -sudo docker run -d -p 8900:3000 -v ~/py-push-server-db:/app/instance/data --name py-push-server-$PUSH_SERVER_VERSION py-push-server:amd-$PUSH_SERVER_VERSION +sudo docker run -d -p 8900:3000 -v ~/py-push-server-db:/srv/py-push-server/data --name py-push-server-$PUSH_SERVER_VERSION py-push-server:amd-$PUSH_SERVER_VERSION ``` @@ -227,9 +227,13 @@ Run the app: ```commandline sh <(curl https://pkgx.sh) +python.org +virtualenv.pypa.io sh +pip install gunicorn + source venv/bin/activate -python app.py +gunicorn -b 0.0.0.0:3000 --log-level=debug --workers=3 app:app + +# ... and see the results in a browser: http://localhost:3000/web-push/vapid # See Troubleshooting below if that doesn't work out of the box. ``` @@ -256,6 +260,9 @@ Run haproxy (on a Mac): Troubleshooting -* If you get "unable to open database file", you can edit the app.py line with - SQLALCHEMY_DATABASE_URI and add `sqlite:////...` with the full path to the data/webpush.db file. +* If you get "no such table: vapid_key" then your file pointers are probably wrong. + Check that the "docker run" mounted volume matches the SQLALCHEMY_DATABASE_URI in the app.py file. + +* If you get "unable to open database file", you can provide the app.py with + SQLALCHEMY_DATABASE_URI with `sqlite:////...` with the full path to the data/webpush.db file. (Why does the relative path of `sqlite:///...` not work for a relative path?) diff --git a/app.py b/app.py index 873bb97..ac28982 100644 --- a/app.py +++ b/app.py @@ -37,7 +37,7 @@ class WebPushService(): self.app = app # Setting the database URI for the application - db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:////app/instance/data/webpush.db') + db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:////srv/py-push-server/data/webpush.db') # This relative path works in docker-compose #db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///data/webpush.db') self.app.config['SQLALCHEMY_DATABASE_URI'] = db_uri