fix DB path and add instructions for docker deployment #1
@@ -1,6 +1,34 @@
|
|||||||
# py-push-server
|
# py-push-server
|
||||||
|
|
||||||
## Docker Compose Setup
|
## Docker Build & Deploy
|
||||||
|
|
||||||
|
```
|
||||||
|
export PUSH_SERVER_VERSION=0.1
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
bzip2 ~/dl/py-push-server-amd-$PUSH_SERVER_VERSION.tar
|
||||||
|
```
|
||||||
|
|
||||||
|
... and then on the server after transferring that file:
|
||||||
|
|
||||||
|
```
|
||||||
|
export PUSH_SERVER_VERSION=0.1
|
||||||
|
|
||||||
|
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:/srv/py-push-server/data --name py-push-server-$PUSH_SERVER_VERSION py-push-server:amd-$PUSH_SERVER_VERSION
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Docker Compose & HAProxy Setup
|
||||||
|
|
||||||
|
|
||||||
On first run you need to:
|
On first run you need to:
|
||||||
@@ -8,7 +36,7 @@ On first run you need to:
|
|||||||
`docker network create phoenix-network`
|
`docker network create phoenix-network`
|
||||||
|
|
||||||
|
|
||||||
## HAProxy setup
|
### HAProxy setup
|
||||||
|
|
||||||
... in docker-compose.yml ...
|
... in docker-compose.yml ...
|
||||||
|
|
||||||
@@ -181,7 +209,7 @@ NOTE: `timesafari-pwa.anomalistlabs.com` PWA sits on the root
|
|||||||
timesafari-pwa.anomalistlabs.com/web-push/ web_push_backend
|
timesafari-pwa.anomalistlabs.com/web-push/ web_push_backend
|
||||||
```
|
```
|
||||||
|
|
||||||
## The rest ..
|
### The rest ..
|
||||||
|
|
||||||
`docker-compose up -d` should just work :-)
|
`docker-compose up -d` should just work :-)
|
||||||
|
|
||||||
@@ -192,11 +220,6 @@ timesafari-pwa.anomalistlabs.com/web-push/ web_push_backend
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Run the server outside Docker
|
## Run the server outside Docker
|
||||||
|
|
||||||
Run the app:
|
Run the app:
|
||||||
@@ -204,9 +227,13 @@ Run the app:
|
|||||||
```commandline
|
```commandline
|
||||||
sh <(curl https://pkgx.sh) +python.org +virtualenv.pypa.io sh
|
sh <(curl https://pkgx.sh) +python.org +virtualenv.pypa.io sh
|
||||||
|
|
||||||
|
pip install gunicorn
|
||||||
|
|
||||||
source venv/bin/activate
|
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.
|
# See Troubleshooting below if that doesn't work out of the box.
|
||||||
```
|
```
|
||||||
@@ -233,6 +260,9 @@ Run haproxy (on a Mac):
|
|||||||
|
|
||||||
Troubleshooting
|
Troubleshooting
|
||||||
|
|
||||||
* If you get "unable to open database file", you can edit the app.py line with
|
* If you get "no such table: vapid_key" then your file pointers are probably wrong.
|
||||||
SQLALCHEMY_DATABASE_URI and add `sqlite:////...` with the full path to the data/webpush.db file.
|
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?)
|
(Why does the relative path of `sqlite:///...` not work for a relative path?)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from pywebpush import webpush, WebPushException
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -36,7 +37,10 @@ class WebPushService():
|
|||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
# Setting the database URI for the application
|
# Setting the database URI for the application
|
||||||
self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///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
|
||||||
|
|
||||||
# Initializing the database with the application
|
# Initializing the database with the application
|
||||||
db.init_app(self.app)
|
db.init_app(self.app)
|
||||||
|
|||||||
Reference in New Issue
Block a user