The following instructions are for the MacOS environment, they might be slightly different on Windows/Linux.
$ docker pull postgres
$ docker run -d \
--name my-postgres \
-p 5432:5432 \
-e POSTGRES_PASSWORD=postgres \
-v [host_src_path]:/var/lib/postgresql/data \
postgres
$ docker exec -it my-postgres bash
# psql -U postgres
you will be presented with a psql terminal like this
psql (16.0 (Debian 16.0-1.pgdg120+1))
Type "help" for help.
postgres=#
postgres=# CREATE DATABASE testdb;
postgres=# CREATE ROLE test WITH LOGIN PASSWORD ‘test’;
postgres=# \c testdb;
You are now connected to database "testdb" as user "postgres".
testdb=# grant all on schema public to test;
GRANT
testdb=# grant all privileges on database testdb to test;
GRANT
testdb=# \q
2.1 Install python3 (don't install Python 3.12.x, psycopg2 isnt working in python 3.12.0 recently, not sure if it has been fixed or not)
$ python3 --version
Python 3.11.6
$ cd [the project root folder]
$ python3 -m venv .venv
$ source ./.venv/bin/activate
### under the project folder ###
(.venv) $ pip install -r ./requirements.txt
(.venv) $ nano flaskreact/.env
set the corresponding settings
DATABASE_URI='postgresql+psycopg2://test:test@localhost:5432/testdb'
DEVELOPMENT_SECRET_KEY='flask app secret key' <- modify this
DEVELOPMENT_JWT_SECRET='flask-jwt-extended jwt secret key' <- modify this
### under the project root folder ###
(.venv) $ flask db init
(.venv) $ flask db migrate
(.venv) $ flask db upgrade
### unser the project root folder ###
(.venv) $ flask run
or
(.venv) $ flask --app "flaskreact:create_app(mode='development')" run
if using gunicorn
(.venv) $ gunicorn -w 4 "flaskreact:create_app(mode='development')"
or create a wsgi.py
inside wsgi.py
from my_project import create_app
app = create_app()
(.venv) $ gunicorn -w 4 my_project.wsgi:app
you should see this after flask run
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit