starlite-pg-redis-docker
A WIP Starlite API Implementation.
TODO
- Header/cookie parameter example.
- CI?
- Profile
- Profile alternate UUID implementation (https://github.com/MagicStack/py-pgproto/blob/a4178145cd7cc3a44eee20cfc9e8b94a7fed2053/uuid.pyx)
- Gunicorn logconfig ignore sqlalchemy.engine logs
- explicitly include any dirs/files into docker and remove .dockerignore
- add pre-commit (I'll just make as equivalent as possible to the original pre-commit config in this project)
- configure pyupgrade for only --py310-plus
- use the Dockerfile from https://gist.github.com/Goldziher/942f4a027a7fa1e2cafaa35e0333b6dc
- remove black and isort from alembic hooks
- map docker ports to service defaults
- add pylint into tooling
- black and isort settings as per original
- websocket example project with simple front end???
Starlite
Starlite is a light and flexible ASGI API framework.
RestartableUvicornWorker
There is a known issue when running gunicorn with uvicorn workers, see here.
For convenience an implementation of the workaround (this one) suggested in that gunicorn issue is included in the application source.
To use the included RestartableUvicornWorker
set the GUNICORN_WORKER_CLASS
env var
to app.utils.restartable_worker.RestartableUvicornWorker
.
In production, set the GUNICORN_WORKER_CLASS
env var to uvicorn.workers.UvicornWorker
as advised here.
Setup
$ cp .env.example .env
$ docker-compose run --rm app alembic upgrade head
Run
$ docker-compose up --build
ReDoc
http://localhost:8000/schema
Test
$ docker-compose run --rm app scripts/tests
Format
black
$ docker-compose run --rm app black .
isort
$ docker-compose run --rm app isort .
Add Dependencies
Production
$ docker-compose run --rm app poetry add <dependency>
Dev
$ docker-compose run --rm app poetry add <dependency> --dev
Rebuild
$ docker-compose build
Migrations
Ensure the database service is up
$ docker-compose up -d db
Revision
$ docker-compose run --rm app alembic revision --autogenerate -m "revision description"
May have issue with permissions after having docker generate the revision file, to fix:
$ sudo chown <user> ./alembic/versions/<filename>.py
Migration
$ docker-compose run --rm app alembic upgrade head