Skip to content
/ flask-api-demo Public template

Flask REST API项目示例,包含JWT认证、RABC、rq异步任务、Swagger文档、Docker部署、uwsgi、supervisor……

Notifications You must be signed in to change notification settings

luolingchun/flask-api-demo

Repository files navigation

flask-api-demo

项目初始化

执行sh init.sh PROJECT_NAME

开发说明

  1. 修改build.shdocker-compose.yml中镜像版本,执行sh build.sh构建镜像
  2. 执行docker-compose up -d启动容器
  3. 执行docker exec -it flask-api-demo bash进入容器
  4. 执行supervisorctl stop app停止服务,并执行flask runpython wsgi.py进入开发者模式
  5. CHANGELOG.md中记录版本日志,重新执行第一步发布镜像

运维调试

  1. 进入容器后使用supervisorctl status进程状态

    # supervisorctl status
    app                              RUNNING   pid 8, uptime 3 days, 5:35:50
    worker                           RUNNING   pid 10, uptime 3 days, 5:35:50
  2. 停止进程:supervisorctl stop app

  3. 启动进程:supervisorctl start app

  4. 查看日志:tail -f /data/log/webapp.log

  5. 查看日志:tail -f /data/log/worker.log

部署说明

  1. 创建flask网络:docker network create flask

    可能遇到网络冲突问题,解决方法:

    1. 删除网络:docker network rm flask

    2. 创建网络时指定掩码和网关:

      docker network create --subnet=192.168.0.0/24 --gateway=192.168.0.1 flask

  2. 准备docker-compose.yml, 注释源码挂载:- "./:/work"

  3. 启动服务:docker-compose up -d

  4. 数据库迁移:

    1. docker exec -it flask-api-demo bash
    2. flask db init -d /data/data/migrations
    3. flask db migrate -d /data/data/migrations
    4. flask db upgrade -d /data/data/migrations
  5. 初始化数据库:

    flask init_db

Docker配置文件

  1. vim /etc/docker/daemon.json

    • default-runtime:修改默认运行时为nvidia
    • data-root:修改数据存储路径
    • bip:修改网卡地址
    {
        "default-runtime": "nvidia",
        "runtimes": {
            "nvidia": {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        },
        "data-root":"/data/docker_data",
        "bip":"192.168.0.1/24"
    }

About

Flask REST API项目示例,包含JWT认证、RABC、rq异步任务、Swagger文档、Docker部署、uwsgi、supervisor……

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published