peterschutt / starlite-pg-redis-docker

Example backend stack using Starlite and postgres db

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Starlite logo

starlite-pg-redis-docker

A WIP Starlite API Implementation.

TODO

Starlite

Starlite is a light and flexible ASGI API framework.

Starlite documentation 📚

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

About

Example backend stack using Starlite and postgres db

License:MIT License


Languages

Language:Python 95.3%Language:Shell 2.2%Language:Dockerfile 1.7%Language:Mako 0.7%