Project for studying purposes using FastAPI.
Make sure your .env file is configured with:
DB
DB_NAME
DB_USER
DB_PSWD
DB_HOST
DB_PORT
SECRET_KEY
- You can generate a new
SECRET_KEYwith
openssl rand -hex 32Make sure you have pipenv installed:
pip install pipenvInstall dependencies:
pipenv installEnter the virtual env.:
pipenv shellStart the server:
uvicorn app.main:app
Build the docker image
docker-compose build
Run the containers
docker-compose up
The server will be listening at localhost:8000.
Check both Dockerfile and docker-compose.yml for further documentation.
You can test inside the container, on the postgres database, using
docker-compose run --rm --no-deps --entrypoint=pytest app /tests
To test locally using sqlite, add the following line to .env:
TESTING_DB_URL=sqlite:///testing.db
And then everything you run locally (the app or pytest) will use the local sqlite database (./testing.db).
If you consider usefull, you can also run only the postgres database container using
docker-compose up -d postgres
Other useful commands are specified at Makefile.
- Problem: pipenv was unable to install
psycopg2orpsycopg-binary. - Solution found: install missing dependency
sudo apt-get install libpq-dev