Depoly your flask app into Heroku Fix shit IE code manually ISBN to Book Category by Scraping DangDang A Generic Makefile for C/C++ Program Configure Raspberry pi Remove watermark with PyPDF2 tips for docker Anaconda+TensorFlow+CUDA Snippets Configure Remote Mathematica Kernel Build your own ngrok server Access Array SSL VPN 使用Rstudio制作html5幻灯片 tips for Mac OS X system Tips for ipython notebook 配置Ubuntu server + Openbox (Obuntu) tips for Vimperator tips for Vim 安装CUDA My First Jekyll Blog rsync常见选项 在Linux中读取Ipod touch的文件 tip for texmacs 在VPS上建站的一些tip Gnuplot绘图札记 Samba系统和autofs自动挂载 Linux中alsamixer声卡无法录音 搭建自己的RSS订阅器——Tiny Tiny RSS Grub2引导安装Ubuntu awk tips 将Ubuntu系统装入U盘 The Great Rtorrent 编译GCC 再这样剁手!!!该死的libgd 使用ulimit进行资源限制 使用SSH代理上IPV6 使用RCurl抓取网页数据 修复Ubuntu Grub记 openbox中的文件关联 在Ubuntu 12.04下编译qtiplot 处理BCM4312网卡驱动纪实 配置我的Ubuntu Server记 Cygwin杂记 Linux 使普通用户具有以超级权限执行脚本 让firefox自定义地处理文件类型 WordPress优秀主题及插件 在phpcloud上搭建wordpress UBUNTU下用pptpd做VPN server ubuntu升级内核过后的一些问题 安装telnet服务 kubuntu札记 64位kubuntu札记 统计软件R virtualbox stardict星际译王 Ubuntu重装windows系统后的grub引导修复 SSH服务及花生壳域名解析 采用cbp2make工具由code::blocks工程创建makefile文件 UBUNTU 札记

Depoly your flask app into Heroku

2018年09月29日

Heroku is a wonderful platform to host your web application which have every few traffic. You only need to set up an git repository and push it to Heroku, then your web should be running!

Write your flask app and set every thing up!

# set up the heroku buildpack
cat > app.json << EOF
{
  "name": "Lambda API",
  "description": "API like Amazon Lambda calculation",
  "image": "heroku/python",
  "keywords": ["python", "flask" ]
}
EOF

# may need to specify the python runtime version
cat > runtime.txt <<EOF
python-3.6.6
EOF

# point out the needed python packages
cat > requirements.txt <<EOF
Flask==1.0.2
gunicorn==19.9.0
EOF

# configure the gunicorn as web server
cat > Procfile <<EOF
web: gunicorn app:app
EOF

# the flask web app
mkdir app
cat > app/__init__.py <<EOF
from flask import Flask, Response, jsonify

class JSONResponse(Response):
    @classmethod
    def force_type(cls, response, environ=None):
        if isinstance(response, (list, dict, bool)):
            response = jsonify(response)
        return super(Response, cls).force_type(response, environ)


app = Flask(__name__)
app.response_class = JSONResponse
app.config['JSON_AS_ASCII'] = False


@app.route('/')
def hello_world():
    return ['hello', 'world']
EOF

# flask app for local test
cat > run.py <<EOF
#!/usr/bin/env python3
from app import app

if __name__ == '__main__':
    app.run()
EOF

The Heroku seems only support gunicorn as web server, that is what Procfile is for.

Set up the git repository

Assuming the app your created on Heroku is named $APP.

# set up the git repository
git init
git remote add heroku https://git.heroku.com/$APP.git

echo __*cache__ > .gitignore
git add .
git commit -m "initial"

# push to heroku
git push heroku master

Every thing is done!

Try curl https://$APP.herokuapp.com/.