From dba4cf01a33b53c1a467c029f8289da7e1195329 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sun, 18 Feb 2024 19:22:35 +0000 Subject: [PATCH] CHORE: Created .env file to store environment vars --- README.md | 2 -- app.py | 2 ++ cicd/Deployment/docker-compose.yml | 12 ++++++++++++ cicd/{ => Testing}/docker-compose.yml | 28 +++++++++++++-------------- docker-compose.yml | 6 ++---- requirements.txt | 3 ++- scripts/run.bash | 26 +++++++++++++------------ tests/__init__.py | 2 ++ 8 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 cicd/Deployment/docker-compose.yml rename cicd/{ => Testing}/docker-compose.yml (97%) diff --git a/README.md b/README.md index ec0243c..7ba9ea2 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,6 @@ services: container_name: "wmgzon" image: lukeelse/wmgzon:latest environment: - - APPSECRET=test - - ENVIRON=prod - FILESTORE=static/assets/img/products/ tty: true ports: diff --git a/app.py b/app.py index 200d228..157edf1 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from flask import Flask from os import environ +from dotenv import load_dotenv from controllers.web.endpoints import blueprint ''' @@ -11,6 +12,7 @@ from controllers.web.endpoints import blueprint app: Flask = Flask(__name__) # Set app secret key to sign session cookies +load_dotenv() secret_key = environ.get("APPSECRET") if secret_key is None: # NO Secret Key set! diff --git a/cicd/Deployment/docker-compose.yml b/cicd/Deployment/docker-compose.yml new file mode 100644 index 0000000..70f5ef4 --- /dev/null +++ b/cicd/Deployment/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' + +services: + wmgzon: + container_name: "wmgzon" + image: lukeelse/wmgzon:latest + tty: true + ports: + - "8080:8080" + volumes: + - ./files:/app/static/assets/img/products/ + restart: unless-stopped \ No newline at end of file diff --git a/cicd/docker-compose.yml b/cicd/Testing/docker-compose.yml similarity index 97% rename from cicd/docker-compose.yml rename to cicd/Testing/docker-compose.yml index c16f0ed..84e0212 100644 --- a/cicd/docker-compose.yml +++ b/cicd/Testing/docker-compose.yml @@ -1,15 +1,15 @@ -version: '3.8' -services: - gitlab-runner-python: - image: gitlab/gitlab-runner:latest - volumes: - - ./runner-data-python:/etc/gitlab-runner - - /var/run/docker.sock:/var/run/docker.sock - restart: unless-stopped - - gitlab-runner-docker: - image: gitlab/gitlab-runner:latest - volumes: - - ./runner-data-docker:/etc/gitlab-runner - - /var/run/docker.sock:/var/run/docker.sock +version: '3.8' +services: + gitlab-runner-python: + image: gitlab/gitlab-runner:latest + volumes: + - ./runner-data-python:/etc/gitlab-runner + - /var/run/docker.sock:/var/run/docker.sock + restart: unless-stopped + + gitlab-runner-docker: + image: gitlab/gitlab-runner:latest + volumes: + - ./runner-data-docker:/etc/gitlab-runner + - /var/run/docker.sock:/var/run/docker.sock restart: unless-stopped \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e62f6b6..8154343 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,14 +5,12 @@ services: container_name: "wmgzon" build: . environment: - - APPSECRET=test - ENVIRON=test - #- ENVIRON=prod - - FILESTORE=static/assets/img/products/ tty: true ports: - "8080:8080" + # Dev container -> Copies complete root directory with latest + # code into the container volumes: - .:/app restart: unless-stopped - \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7b8a215..361fe5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,4 +23,5 @@ ujson==5.8.0 virtualenv==20.24.6 waitress==2.1.2 Werkzeug==3.0.1 -pycodestyle==2.11.1 \ No newline at end of file +pycodestyle==2.11.1 +python-dotenv==1.0.1 \ No newline at end of file diff --git a/scripts/run.bash b/scripts/run.bash index 726badf..b29485c 100644 --- a/scripts/run.bash +++ b/scripts/run.bash @@ -2,23 +2,25 @@ 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" + echo "Using DEFAULT Environ Value: prod" - # 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 + export ENVIRON=prod fi +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 diff --git a/tests/__init__.py b/tests/__init__.py index 79b9107..a6b29a5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,8 @@ import os +from dotenv import load_dotenv # Setup test environment variables +load_dotenv() # Capture environment variables at start of testing so we can # Monitor current setting during tests