Skip to content

Jeremiaszmacura/flask-base

Repository files navigation


Development setup


Create python virutal enviroment

Create and active virtual enviroment using venv library:

python3 -m venv .venv
source .venv/bin/activate (Linux)
.venv\Scripts\activate (Windows)

In some Windows cases before activating venv:

Set-ExecutionPolicy Unrestricted -Scope Process

Setup flask app

Linux/MacOS

export FLASK_APP=flaskr/run.py
export FLASK_DEBUG="True"

Windows cmd

set FLASK_APP=flaskr/run.py
set FLASK_DEBUG="True"

Windows powershell

$env:FLASK_APP="flaskr/run.py"
$env:FLASK_DEBUG="True"

Install app as library in development mode using setuptool

python -m pip install -e .[dev]

Build package (run command each time after changes anmd before building image from Dockerfile)

python setup.py bdist_wheel

Run PosgreSQL database as container

docker run --name postgres_workshops -e POSTGRES_DB=dev_database -e POSTGRES_USER=dev_user -e POSTGRES_PASSWORD=dev_pass -p 5432:5432 -d postgres:14

Run flask app

flask run

Run unit tests

pytest tests

Run linter

Pytlint

python -m pylint flaskr tests

Black check

python -m black --check .

Black fix

python -m black .

Docker-compose

Start all containers

docker-compose up

Stop all containers

docker-compose down

Kubernetes

Apply k8 resources

kubectl apply -f .\postgres-config.yaml
kubectl apply -f .\postgres-secret.yaml
kubectl apply -f .\postgres.yaml
kubectl apply -f .\flask-app.yaml

Delete k8 resources

kubectl delete -f .\postgres-config.yaml
kubectl delete -f .\postgres-secret.yaml
kubectl delete -f .\postgres.yaml
kubectl delete -f .\flask-app.yaml

Build flask-app image

docker build -t flask-app:v1 .

URLs

App

http://localhost:5000/