diff --git a/.dockerignore b/.dockerignore index 2d2ecd6..80b070a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ .git/ +venv/ diff --git a/README.md b/README.md index 818289b..4a2afd8 100644 --- a/README.md +++ b/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 Specifies a port to run on (default 8888) + --port Specifies a port to run on (default 5000) --host 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://.herokuapp.com > /home//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://.herokuapp.com/config > /home//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://.herokuapp.com/config > /home//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 diff --git a/app/__main__.py b/app/__main__.py new file mode 100644 index 0000000..03a424c --- /dev/null +++ b/app/__main__.py @@ -0,0 +1,3 @@ +from .routes import run_app + +run_app() diff --git a/app/routes.py b/app/routes.py index 09c39a8..7886de9 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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='', - help='Specifies a port to run on (default 8888)') + parser.add_argument('--port', default=5000, metavar='', + help='Specifies a port to run on (default 5000)') parser.add_argument('--host', default='127.0.0.1', metavar='', 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)) diff --git a/docker-compose.yml b/docker-compose.yml index c6c9ced..479b7f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,5 +5,5 @@ services: image: benbusby/whoogle-search container_name: whoogle-search ports: - - 8888:5000 + - 5000:5000 restart: unless-stopped diff --git a/requirements.txt b/requirements.txt index 5a6a937..eac1d8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/whoogle-search b/whoogle-search index e8bcc7f..3393528 100755 --- a/whoogle-search +++ b/whoogle-search @@ -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