Swap out Flask's default web server for Waitress (#32)
* Ignore venv when building docker file * Remove reference to 8888 port It wasn't really used anywhere, and setting it to 5000 everywhere removes ambiguity, and makes things easier to track and reason about * Use waitress rather than Flask's built in web server It's not production grade * Actually add waitress to requirements Woops!main
parent
14a41a89b6
commit
f700ed88e7
|
@ -1 +1,2 @@
|
|||
.git/
|
||||
venv/
|
||||
|
|
10
README.md
10
README.md
|
@ -57,11 +57,11 @@ Provides:
|
|||
- Downtime after periods of inactivity \([solution](https://github.com/benbusby/whoogle-search#prevent-downtime-heroku-only)\)
|
||||
|
||||
### B) [pipx](https://github.com/pipxproject/pipx#install-pipx)
|
||||
Persistent install:
|
||||
Persistent install:
|
||||
|
||||
`pipx install git+https://github.com/benbusby/whoogle-search.git`
|
||||
|
||||
Sandboxed temporary instance:
|
||||
Sandboxed temporary instance:
|
||||
|
||||
`pipx run git+https://github.com/benbusby/whoogle-search.git whoogle-search`
|
||||
|
||||
|
@ -76,7 +76,7 @@ Whoogle Search console runner
|
|||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--port <port number> Specifies a port to run on (default 8888)
|
||||
--port <port number> Specifies a port to run on (default 5000)
|
||||
--host <ip address> Specifies the host address to use (default 127.0.0.1)
|
||||
--debug Activates debug mode for the Flask server (default False)
|
||||
```
|
||||
|
@ -104,7 +104,7 @@ pip install -r requirements.txt
|
|||
git clone https://github.com/benbusby/whoogle-search.git
|
||||
cd whoogle-search
|
||||
docker build --tag whooglesearch:1.0 .
|
||||
docker run --publish 8888:5000 --detach --name whooglesearch whooglesearch:1.0
|
||||
docker run --publish 5000:5000 --detach --name whooglesearch whooglesearch:1.0
|
||||
```
|
||||
|
||||
And kill with: `docker rm --force whooglesearch`
|
||||
|
@ -172,7 +172,7 @@ A good solution for this is to set up a simple cronjob on any device at your hom
|
|||
|
||||
For instance, adding `*/20 7-23 * * * curl https://<your heroku app name>.herokuapp.com > /home/<username>/whoogle-refresh` will fetch the home page of the app every 20 minutes between 7am and midnight, allowing for downtime from midnight to 7am. And again, this wouldn't be a hard limit - you'd still have plenty of remaining hours of uptime each month in case you were searching after this window has closed.
|
||||
|
||||
Since the instance is destroyed and rebuilt after inactivity, config settings will be reset once the app enters downtime. If you have configuration settings active that you'd like to keep between periods of downtime (like dark mode for example), you could instead add `*/20 7-23 * * * curl -d "dark=1" -X POST https://<your heroku app name>.herokuapp.com/config > /home/<username>/whoogle-refresh` to keep these settings more or less permanent, and still keep the app from entering downtime when you're using it.
|
||||
Since the instance is destroyed and rebuilt after inactivity, config settings will be reset once the app enters downtime. If you have configuration settings active that you'd like to keep between periods of downtime (like dark mode for example), you could instead add `*/20 7-23 * * * curl -d "dark=1" -X POST https://<your heroku app name>.herokuapp.com/config > /home/<username>/whoogle-refresh` to keep these settings more or less permanent, and still keep the app from entering downtime when you're using it.
|
||||
|
||||
Available config values are `near`, `nojs`, `dark` and `url`.
|
||||
## FAQ
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from .routes import run_app
|
||||
|
||||
run_app()
|
|
@ -9,6 +9,7 @@ import io
|
|||
import json
|
||||
import os
|
||||
import urllib.parse as urlparse
|
||||
import waitress
|
||||
|
||||
app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__)))
|
||||
app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config['APP_ROOT'], 'static'))
|
||||
|
@ -146,12 +147,14 @@ def window():
|
|||
|
||||
def run_app():
|
||||
parser = argparse.ArgumentParser(description='Whoogle Search console runner')
|
||||
parser.add_argument('--port', default=8888, metavar='<port number>',
|
||||
help='Specifies a port to run on (default 8888)')
|
||||
parser.add_argument('--port', default=5000, metavar='<port number>',
|
||||
help='Specifies a port to run on (default 5000)')
|
||||
parser.add_argument('--host', default='127.0.0.1', metavar='<ip address>',
|
||||
help='Specifies the host address to use (default 127.0.0.1)')
|
||||
parser.add_argument('--debug', default=False, action='store_true',
|
||||
help='Activates debug mode for the Flask server (default False)')
|
||||
help='Activates debug mode for the server (default False)')
|
||||
args = parser.parse_args()
|
||||
|
||||
app.run(host=args.host, port=args.port, debug=args.debug)
|
||||
if args.debug:
|
||||
app.run(host=args.host, port=args.port, debug=args.debug)
|
||||
else:
|
||||
waitress.serve(app, listen="{}:{}".format(args.host, args.port))
|
||||
|
|
|
@ -5,5 +5,5 @@ services:
|
|||
image: benbusby/whoogle-search
|
||||
container_name: whoogle-search
|
||||
ports:
|
||||
- 8888:5000
|
||||
- 5000:5000
|
||||
restart: unless-stopped
|
||||
|
|
|
@ -15,3 +15,4 @@ python-dateutil==2.8.1
|
|||
six==1.14.0
|
||||
soupsieve==1.9.5
|
||||
Werkzeug==0.16.0
|
||||
waitress==1.4.3
|
||||
|
|
|
@ -17,11 +17,9 @@ export STATIC_FOLDER=$APP_ROOT/static
|
|||
|
||||
mkdir -p $STATIC_FOLDER
|
||||
|
||||
pkill flask
|
||||
|
||||
# Check for regular vs test run
|
||||
if [[ $SUBDIR == "test" ]]; then
|
||||
pytest -sv
|
||||
else
|
||||
flask run --host="0.0.0.0" --port=$PORT
|
||||
python3 -m app --port $PORT
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue