Updated scripts to enable deploying prod server

This commit is contained in:
Luke Else 2024-01-28 01:19:37 +00:00
parent d80b07d43d
commit 3eea1d946a
3 changed files with 38 additions and 20 deletions

30
app.py
View File

@ -8,24 +8,20 @@ from controllers.web.endpoints import blueprint
Database manager...
'''
app = Flask(__name__)
def main():
print(__package__)
app = Flask(__name__)
# Set app secret key to sign session cookies
secret_key = environ.get("APPSECRET")
if secret_key is None:
# NO Secret Key set!
print("No app secret set, please set one before deploying in production")
app.secret_key = "DEFAULTKEY"
else:
app.secret_key = secret_key
# Register a blueprint
app.register_blueprint(blueprint)
app.run(debug=True, host="0.0.0.0")
# Set app secret key to sign session cookies
secret_key = environ.get("APPSECRET")
if secret_key is None:
# NO Secret Key set!
print("No app secret set, please set one before deploying in production")
app.secret_key = "DEFAULTKEY"
else:
app.secret_key = secret_key
# Register a blueprint
app.register_blueprint(blueprint)
if __name__ == "__main__":
main()
app.run(debug=True, host="0.0.0.0", port=8080)

View File

@ -7,11 +7,11 @@ services:
environment:
- APPSECRET=test
- ENVIRON=test
# - ENVIRON=prod
#- ENVIRON=prod
- FILESTORE=static/assets/img/products/
tty: true
ports:
- "5000:5000"
- "8080:8080"
volumes:
- .:/app
restart: unless-stopped

View File

@ -1,2 +1,24 @@
#! /bin/bash
pytest --disable-warnings && python ./scripts/create_database.py && python ./app.py
pytest --disable-warnings
python ./scripts/create_database.py
EXPECTED_VALUE="test"
if [ -z "$ENVIRON" ]; then
echo "ENVIRON is not set."
else
echo "ENVIRON is set to: $ENVIRON"
# Trim leading and trailing whitespaces
ACTUAL_VALUE=$(echo "$ENVIRON" | tr -d '[:space:]')
if [ "$ACTUAL_VALUE" = "$EXPECTED_VALUE" ]; then
echo "Launching DEV Server"
python ./app.py
else
echo "Launching PROD Server"
waitress-serve --host 0.0.0.0 app:app
fi
fi