CHORE: Created .env file to store environment vars

This commit is contained in:
Luke Else 2024-02-18 19:22:35 +00:00
parent 01cf5d641b
commit dba4cf01a3
8 changed files with 48 additions and 33 deletions

View File

@ -54,8 +54,6 @@ services:
container_name: "wmgzon" container_name: "wmgzon"
image: lukeelse/wmgzon:latest image: lukeelse/wmgzon:latest
environment: environment:
- APPSECRET=test
- ENVIRON=prod
- FILESTORE=static/assets/img/products/ - FILESTORE=static/assets/img/products/
tty: true tty: true
ports: ports:

2
app.py
View File

@ -1,5 +1,6 @@
from flask import Flask from flask import Flask
from os import environ from os import environ
from dotenv import load_dotenv
from controllers.web.endpoints import blueprint from controllers.web.endpoints import blueprint
''' '''
@ -11,6 +12,7 @@ from controllers.web.endpoints import blueprint
app: Flask = Flask(__name__) app: Flask = Flask(__name__)
# Set app secret key to sign session cookies # Set app secret key to sign session cookies
load_dotenv()
secret_key = environ.get("APPSECRET") secret_key = environ.get("APPSECRET")
if secret_key is None: if secret_key is None:
# NO Secret Key set! # NO Secret Key set!

View File

@ -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

View File

@ -5,14 +5,12 @@ services:
container_name: "wmgzon" container_name: "wmgzon"
build: . build: .
environment: environment:
- APPSECRET=test
- ENVIRON=test - ENVIRON=test
#- ENVIRON=prod
- FILESTORE=static/assets/img/products/
tty: true tty: true
ports: ports:
- "8080:8080" - "8080:8080"
# Dev container -> Copies complete root directory with latest
# code into the container
volumes: volumes:
- .:/app - .:/app
restart: unless-stopped restart: unless-stopped

View File

@ -24,3 +24,4 @@ virtualenv==20.24.6
waitress==2.1.2 waitress==2.1.2
Werkzeug==3.0.1 Werkzeug==3.0.1
pycodestyle==2.11.1 pycodestyle==2.11.1
python-dotenv==1.0.1

View File

@ -2,23 +2,25 @@
pytest --disable-warnings pytest --disable-warnings
python ./scripts/create_database.py python ./scripts/create_database.py
EXPECTED_VALUE="test" EXPECTED_VALUE="test"
if [ -z "$ENVIRON" ]; then if [ -z "$ENVIRON" ]; then
echo "ENVIRON is not set." echo "ENVIRON is not set."
else echo "Using DEFAULT Environ Value: prod"
echo "ENVIRON is set to: $ENVIRON"
# Trim leading and trailing whitespaces export ENVIRON=prod
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 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

View File

@ -1,6 +1,8 @@
import os import os
from dotenv import load_dotenv
# Setup test environment variables # Setup test environment variables
load_dotenv()
# Capture environment variables at start of testing so we can # Capture environment variables at start of testing so we can
# Monitor current setting during tests # Monitor current setting during tests