diff --git a/.gitignore b/.gitignore index 8248183..1238215 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ .vscode # data -instance/partitioncloud.sqlite +instance partitioncloud/partitions partitioncloud/search-partitions partitioncloud/static/thumbnails diff --git a/default_config.py b/default_config.py new file mode 100644 index 0000000..e5aa4ae --- /dev/null +++ b/default_config.py @@ -0,0 +1,9 @@ +# Should be copied to ../instance folder to override some values +# WARNING: Be sure not to leave spaces around `=` because this +# Config file will be used both by Python and Bash + +# Generate with `python -c 'import secrets; print(secrets.token_hex())'` +SECRET_KEY="dev" + +# Port to run on +PORT="5000" \ No newline at end of file diff --git a/make.sh b/make.sh index b1a011f..2205c23 100755 --- a/make.sh +++ b/make.sh @@ -16,7 +16,13 @@ init () { } start () { - flask run + flask run --port=$PORT +} + +production () { + FLASK_APP=partitioncloud /usr/bin/gunicorn \ + wsgi:app \ + --bind 0.0.0.0:$PORT } @@ -27,7 +33,10 @@ usage () { } if [[ $1 && $(type "$1") = *"is a"*"function"* || $(type "$1") == *"est une fonction"* ]]; then - $1 ${*:2} # Call the function + # Import config + source "default_config.py" + [[ ! -x instance/config.py ]] && source "instance/config.py" + $1 ${*:2} # Call the function else usage echo $(type "$1") diff --git a/partitioncloud/__init__.py b/partitioncloud/__init__.py index 5cdf7ff..6a756dd 100644 --- a/partitioncloud/__init__.py +++ b/partitioncloud/__init__.py @@ -14,11 +14,13 @@ from .db import get_db app = Flask(__name__) app.config.from_mapping( - # a default secret that should be overridden by instance config - SECRET_KEY="dev", - # store the database in the instance folder DATABASE=os.path.join(app.instance_path, f"{__name__}.sqlite"), ) +app.config.from_object('default_config') +if os.path.exists("instance/config.py"): + app.config.from_object('instance.config') +else: + print("[WARNING] Using default config") app.register_blueprint(auth.bp) app.register_blueprint(albums.bp)