项目作者: yaojiach

项目描述 :
Docker NGINX Flask JWT
高级语言: Python
项目地址: git://github.com/yaojiach/docker-flask.git
创建时间: 2017-01-25T01:31:21Z
项目社区:https://github.com/yaojiach/docker-flask

开源协议:MIT License

下载


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

  1. docker-compose --file docker-compose-dev.yml up --build

Stand up external Postgres database

  1. bash db/init.sh

Build containers

  1. docker-compose up --build

Full clean up (remove Postgres volume)

  1. docker stop $(docker ps -a -q)
  2. docker-compose rm -fs
  3. docker system prune
  4. rm -rf postgres_data

User Registration example

  1. {
  2. "email": "test@test.com",
  3. "password": "12345"
  4. }

Example in Postman:

Registration Example

Gotchas

Set PROPAGATE_EXCEPTIONS to propagate exceptions from flask-jwt-extended

  1. class Config:
  2. ...
  3. PROPAGATE_EXCEPTIONS = True

Must include Pipfile.lock for pipenv to install system-wide in docker

  1. ...
  2. COPY Pipfile.lock /home/project/web
  3. ...

Use host.docker.internal inside container to access host machine’s localhost

  1. DATABASE_URL=postgresql://dev:12345@host.docker.internal:5432/jwt

Caveats

  • Should use external redis for production

References