LoginSignup
40
48

More than 5 years have passed since last update.

herokuにFlaskアプリをデプロイする

Last updated at Posted at 2017-04-23

heroku: すごく簡単に使えるPaaS

以前にAWSのEC2にデプロイしたDeep Learning アプリを herokuにデプロイしてみる。

EC2はIaaSのため、ミドルウェアのインストールや設定など色々と必要だったが、PaaSのHerokuなら同じことがterminalに数行でできちゃう。

準備:herokuの登録とツールのインストール

1.公式ページで登録する

2.CLIツールをインストール

mac
$ brew install heroku
ubuntu
$ sudo apt-get install software-properties-common # debian only
$ sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
$ curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install heroku

3.ログインする

$ heroku login

Enter your Heroku credentials:
Email: <your-email>
Password: ********
Logged in as <your-email>

pythonアプリをデプロイ

ローカルレポジトリを作成

$ mkdir heroku-app
$ cd heroku-app
$ pyenv virtualenv 3.6.0 heroku_keras_3.6.0
$ pyenv local heroku_keras_3.6.0
$ echo .python-version >> .gitignore
$ git init

requirements.txtに 依存ライブラリを記述

$ pip install tensorflow keras flask h5py
$ pip install gunicorn # web app. server
$ pip freeze > requirements.txt

runtime.txtに pythonのバージョンを指定

$ echo python-3.6.0 > runtime.txt

Procfileに webアプリの起動方法を指定

$ echo web: gunicorn app:app --log-file=- > Procfile

heroku にデプロイ

#$ heroku local web

$ heroku create <app-name>
$ heroku buildpacks:set heroku/python

$ git add -A
$ git commit -m "deploy heroku"
$ git push heroku master
$ heroku ps:scale web=1
$ heroku open

アプリ:https://msrks-numpred.herokuapp.com

40
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
40
48