diff --git a/Dockerfile b/Dockerfile index b284ad4..a764bc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ WORKDIR /taiko-web #python virtualenv RUN bash -c 'virtualenv -p /usr/bin/python2 .venv2 && \ source .venv2/bin/activate && \ - pip install Flask Flask-Caching ffmpy gunicorn && \ + pip install Flask Flask-Caching ffmpy gunicorn redis && \ deactivate' RUN bash -c 'virtualenv -p /usr/bin/python3 .venv3 && \ diff --git a/app.py b/app.py index a1caf7b..66d9218 100644 --- a/app.py +++ b/app.py @@ -10,13 +10,6 @@ from flask import Flask, g, jsonify, render_template, request, abort, redirect from flask_caching import Cache from ffmpy import FFmpeg -app = Flask(__name__) -try: - app.cache = Cache(app, config={'CACHE_TYPE': 'redis'}) -except RuntimeError: - import tempfile - app.cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': tempfile.gettempdir()}) - DATABASE = 'taiko.db' DEFAULT_URL = 'https://github.com/purerosefallen/taiko-web-another/' @@ -70,6 +63,21 @@ def get_version(): return version +app = Flask(__name__) +try: + config = get_config() + app.cache = Cache(app, config={ + 'CACHE_TYPE': 'redis', + 'CACHE_REDIS_HOST': config['redis_host'], + 'CACHE_REDIS_PORT': config['redis_port'], + 'CACHE_REDIS_PASSWORD': config['redis_password'], + 'CACHE_REDIS_DB': config['redis_db'] + }) + print("redis enabled") +except RuntimeError: + print("redis disabled") + import tempfile + app.cache = Cache(app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': tempfile.gettempdir()}) @app.teardown_appcontext def close_connection(exception): diff --git a/config.example.json b/config.example.json index 9bfd207..27da0de 100644 --- a/config.example.json +++ b/config.example.json @@ -1,4 +1,8 @@ { "songs_baseurl": "", - "assets_baseurl": "" + "assets_baseurl": "", + "redis_host": "127.0.0.1", + "redis_port": 6379, + "redis_password": "", + "redis_db": 0 }