Stack:
FastAPI Uvicorn Gunicorn
.Before: investigate
.env.example
and fill .env.[prod/dev/test]
.Note: for
prod
you have to generate local SSL cert and tweak hosts to local run (will describe it's later).Test
[tests (pytest), linting (flake8, isort), type-checking (mypy)]:$ make test
Prod
[Nginx + Gunicorn]:$ make prod
Dev
[Uvicorn]:$ make dev
Clean docker stuff:
$ make test-down
$ make prod-down
$ make dev-down
$ make clean
Serve postgres DB for app.
[I'm sure You understand that you have to put DB URL to that DB in .env files.]
Put
APP_ENV
in .env/environment.Test
:$ make local-test
# or
$ make lint
$ pytest
Prod
:$ python app/__main__.py
Dev
:$ python app/__main__.py
Prod
and Dev
runners depend on APP_ENV
variable.Install mkcert.
$ mkcert api.myvocab.io localhost 127.0.0.1 ::1
Put this cert under ./nginx/certs. [Use other domains? Substitute all occurrences]
Link cert to nginx conf.d (to local run):
$ cd /etc/nginx/conf.d
$ ln -s <path-to-cert> .
$ ln -s <path-to-cert-key> .
Tweak /etc/hosts file:
...
# custom domains
127.0.0.1 gunicorn_host
127.0.0.1 api.myvocab.io
You're ready to run both as locally as in Docker.
Serve nginx to local run.
noli esse irrumatus - pone stellam.