Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaojiach/docker-flask
Docker NGINX Flask JWT
https://github.com/yaojiach/docker-flask
docker flask gunicorn jwt nginx psql python
Last synced: 12 days ago
JSON representation
Docker NGINX Flask JWT
- Host: GitHub
- URL: https://github.com/yaojiach/docker-flask
- Owner: yaojiach
- License: mit
- Archived: true
- Created: 2017-01-25T01:31:21.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-05-25T05:19:06.000Z (over 2 years ago)
- Last Synced: 2024-09-28T18:05:51.609Z (4 months ago)
- Topics: docker, flask, gunicorn, jwt, nginx, psql, python
- Language: Python
- Homepage:
- Size: 473 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker Flask Boilerplate
**Tested on Mac, Linux, Windows**
`Docker` + `Flask` + `JWT` boilerplate with `gunicorn`, `nginx`, and external (dockerized for dev) `Postgres` database. Good for quickly set up an authentication backend (for example for a frontend development). Implemented user registration, user login, access token, refresh token, and token revocation.
* Use `Pipfile` for dependency management.
* Use `Flask-Restful` as the REST API framework.
* Use `Flask-JWT-Extended` as the (opinionated) JWT framework. Including features like `refresh token` and `token revoking`.## Features
* Docker
* nginx
* gunicorn
* flask
* jwt
* Postgres
* redis (Used to store jwt token information)## Non-Features
* external `Postgres`
* Dockerized `Postgres` for dev## Usage
Dev with dockerized `Postgres`
```sh
docker-compose --file docker-compose-dev.yml up --build
```Stand up external `Postgres` database
```sh
bash db/init.sh
```Build containers
```sh
docker-compose up --build
```Full clean up (remove `Postgres` volume)
```sh
docker stop $(docker ps -a -q)
docker-compose rm -fs
docker system prune
rm -rf postgres_data
```User Registration example
```json
{
"email": "[email protected]",
"password": "12345"
}
```Example in `Postman`:
![Registration Example](https://github.com/yaojiach/docker-flask-boilerplate/blob/master/postman-example.png)
## Gotchas
Set `PROPAGATE_EXCEPTIONS` to propagate exceptions from `flask-jwt-extended`
```python
class Config:
...
PROPAGATE_EXCEPTIONS = True
```Must include `Pipfile.lock` for `pipenv` to install system-wide in docker
```dockerfile
...
COPY Pipfile.lock /home/project/web
...
```Use `host.docker.internal` inside container to access host machine's localhost
```sh
DATABASE_URL=postgresql://dev:[email protected]:5432/jwt
```## Caveats
* Should use external `redis` for production
## References
* https://github.com/oleg-agapov/flask-jwt-auth
* https://github.com/sladkovm/docker-flask-gunicorn-nginx