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
Jake Howard 2020-05-13 00:14:55 +01:00 committed by GitHub
parent 14a41a89b6
commit f700ed88e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 14 deletions

View File

@ -1 +1,2 @@
.git/ .git/
venv/

View File

@ -76,7 +76,7 @@ Whoogle Search console runner
optional arguments: optional arguments:
-h, --help show this help message and exit -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) --host <ip address> Specifies the host address to use (default 127.0.0.1)
--debug Activates debug mode for the Flask server (default False) --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 git clone https://github.com/benbusby/whoogle-search.git
cd whoogle-search cd whoogle-search
docker build --tag whooglesearch:1.0 . 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` And kill with: `docker rm --force whooglesearch`

3
app/__main__.py Normal file
View File

@ -0,0 +1,3 @@
from .routes import run_app
run_app()

View File

@ -9,6 +9,7 @@ import io
import json import json
import os import os
import urllib.parse as urlparse import urllib.parse as urlparse
import waitress
app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__))) 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')) 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(): def run_app():
parser = argparse.ArgumentParser(description='Whoogle Search console runner') parser = argparse.ArgumentParser(description='Whoogle Search console runner')
parser.add_argument('--port', default=8888, metavar='<port number>', parser.add_argument('--port', default=5000, metavar='<port number>',
help='Specifies a port to run on (default 8888)') help='Specifies a port to run on (default 5000)')
parser.add_argument('--host', default='127.0.0.1', metavar='<ip address>', parser.add_argument('--host', default='127.0.0.1', metavar='<ip address>',
help='Specifies the host address to use (default 127.0.0.1)') help='Specifies the host address to use (default 127.0.0.1)')
parser.add_argument('--debug', default=False, action='store_true', 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() args = parser.parse_args()
if args.debug:
app.run(host=args.host, port=args.port, debug=args.debug) app.run(host=args.host, port=args.port, debug=args.debug)
else:
waitress.serve(app, listen="{}:{}".format(args.host, args.port))

View File

@ -5,5 +5,5 @@ services:
image: benbusby/whoogle-search image: benbusby/whoogle-search
container_name: whoogle-search container_name: whoogle-search
ports: ports:
- 8888:5000 - 5000:5000
restart: unless-stopped restart: unless-stopped

View File

@ -15,3 +15,4 @@ python-dateutil==2.8.1
six==1.14.0 six==1.14.0
soupsieve==1.9.5 soupsieve==1.9.5
Werkzeug==0.16.0 Werkzeug==0.16.0
waitress==1.4.3

View File

@ -17,11 +17,9 @@ export STATIC_FOLDER=$APP_ROOT/static
mkdir -p $STATIC_FOLDER mkdir -p $STATIC_FOLDER
pkill flask
# Check for regular vs test run # Check for regular vs test run
if [[ $SUBDIR == "test" ]]; then if [[ $SUBDIR == "test" ]]; then
pytest -sv pytest -sv
else else
flask run --host="0.0.0.0" --port=$PORT python3 -m app --port $PORT
fi fi