From 3eea1d946a2ff6c929324a88207ffb92da70f79a Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sun, 28 Jan 2024 01:19:37 +0000 Subject: [PATCH] Updated scripts to enable deploying prod server --- app.py | 30 +++++++++++++----------------- docker-compose.yml | 4 ++-- scripts/run.bash | 24 +++++++++++++++++++++++- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/app.py b/app.py index 49c897c..831c964 100644 --- a/app.py +++ b/app.py @@ -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) + diff --git a/docker-compose.yml b/docker-compose.yml index 88c18a2..18c247c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/scripts/run.bash b/scripts/run.bash index 7d52bd5..726badf 100644 --- a/scripts/run.bash +++ b/scripts/run.bash @@ -1,2 +1,24 @@ #! /bin/bash -pytest --disable-warnings && python ./scripts/create_database.py && python ./app.py \ No newline at end of file +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 + +