はじめに
前回作成したPythonアプリをherokuにデプロイしてみようとしたけど、Compiled slug sizeが500MBオーバーでherokuにpushできなかった備忘録
git -> heroku の方法を試してみた(github -> heroku の方法もあるらしい)
前回作成したPythonアプリ
Python × Flask × Tensorflow.Keras 猫の品種を予測するWebアプリ2
環境
macOS
Python3.7.5
試した方法
参考:公式チュートリアル
Heroku用の用意
1.gunicornをインストール
pip install gunicorn
2.ファイル用意
Flask==1.1.2
tensorflow==2.1.0
numpy==1.18.2
Pillow==7.1.1
gunicorn==20.0.4
web: gunicorn app:app --log-file -
python-3.7.5
3.gitにデプロイ
モデルは100MB以上あるためBucketeerに入れる予定・・・
参考:HerokuでTensorFlowのAPIをホストした話
folder
  |- app.py #元sever.py
  |- image_process.py
  |- templates
  |  |- index.html
  |- requirements.py
  |- runtime.py
  |- Procfile
Heroku Command Line Interface (CLI)をインストール
1.herokuコマンドを使えるようにする
$ brew install heroku/brew/heroku
2.Pythonアプリをherokuにデプロイする
$ heroku login
$ heroku create アプリ名 #herokuにリポジトリを作成する?
$ heroku git:remote -a アプリ名 #gitとherokuのリポジトリ(アプリ名)を紐付ける
3.herokuにPythonプログラムをpushする
$ git push heroku master
😥ここでerrorメッセージが出てしまいpushできませんでした
😥Compiled slug size: 518M is too large (max is 500M).を解決しないとダメのようです
😥tensorflowが400M以上を占めているらしい.困った
(略)
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:  !     Compiled slug size: 518M is too large (max is 500M).
remote:  !     See: http://devcenter.heroku.com/articles/slug-size
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to (アプリ名).
remote: 
To https://git.heroku.com/(アプリ名).git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/(アプリ名).git'