12 Commits

12 changed files with 90 additions and 41 deletions

13
.env Normal file
View File

@@ -0,0 +1,13 @@
# Environment Variables used to configure WMGZON
# ENVIRON: Used to incidicate the type of environment the app is running in.
# DEFAULT = prod
ENVIRON=prod
# ENVIRON=test
# App secret used to encrpy client-side cookies
APPSECRET=test
# Filestore for product photos
FILESTORE=static/assets/img/products/

1
.gitignore vendored
View File

@@ -17,7 +17,6 @@ cicd/runner-data
instance/* instance/*
!instance/.gitignore !instance/.gitignore
.webassets-cache .webassets-cache
.env
### Flask.Python Stack ### ### Flask.Python Stack ###
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files

View File

@@ -1,7 +1,4 @@
variables: variables:
APPSECRET: "test"
ENVIRON: "test"
FILESTORE: "static/assets/img/products/"
DOCKER_HOST: tcp://docker:2375/ DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2 DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "" DOCKER_TLS_CERTDIR: ""
@@ -19,13 +16,13 @@ deploy:
stage: deploy stage: deploy
tags: tags:
- docker - docker
image: docker:20.10.16 image: docker:latest
services: services:
- name: docker:20.10.16-dind - name: docker:dind
alias: docker alias: docker
script: script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA . - docker buildx build --platform linux/amd64 -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest - docker push $CI_REGISTRY_IMAGE:latest

View File

@@ -41,3 +41,24 @@ docker-compose up -d
``` ```
to run the container in a detatched mode. to run the container in a detatched mode.
### Container
Alternatively, to deploy the app from the lastest published container:
```yml
version: '3.8'
services:
wmgzon:
container_name: "wmgzon"
image: lukeelse/wmgzon:latest
environment:
- FILESTORE=static/assets/img/products/
tty: true
ports:
- "8080:8080"
volumes:
- ./files:/app/$FILESTORE
restart: unless-stopped
```

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,13 @@
version: '3.8'
services:
wmgzon:
container_name: "wmgzon"
image: lukeelse/wmgzon:latest
tty: true
ports:
- "8080:8080"
volumes:
- ./files:/app/static/assets/img/products/
- ./data:/app/data/
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

@@ -4,4 +4,5 @@ WORKDIR /app
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
COPY . /app COPY . /app
RUN chmod +x scripts/run.bash RUN chmod +x scripts/run.bash
CMD ["bash", "scripts/run.bash"] EXPOSE 8080
ENTRYPOINT ["scripts/run.bash"]

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,11 +2,16 @@
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"
export ENVIRON=prod
fi
echo "ENVIRON is set to: $ENVIRON" echo "ENVIRON is set to: $ENVIRON"
# Trim leading and trailing whitespaces # Trim leading and trailing whitespaces
@@ -19,6 +24,3 @@ else
echo "Launching PROD Server" echo "Launching PROD Server"
waitress-serve --host 0.0.0.0 app:app waitress-serve --host 0.0.0.0 app:app
fi fi
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