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"
image: lukeelse/wmgzon:latest
environment:
- APPSECRET=test
- ENVIRON=prod
- FILESTORE=static/assets/img/products/
tty: true
ports:

2
app.py
View File

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

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

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

View File

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

View File

@ -23,4 +23,5 @@ ujson==5.8.0
virtualenv==20.24.6
waitress==2.1.2
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
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

View File

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