LoginSignup
4
7

More than 5 years have passed since last update.

【Heroku】GitHubで作成したFlaskアプリをHerokuに連携させる

Posted at

はじめに

すでに自分がgithubで作ったFlaskアプリをHerokuにデプロイするために必要なことをまとめました

1.準備

  1. Herokuの公式サイトで、アカウントを登録します。

  2. Getting Startedのset upからHerokuをダウンロードします

  3. Personal appsからnewを書かれたボタンを押してアプリを作成します。
    この時、アプリ名はなんでもいいですが、関連するのが望ましいとは思います。

2.GitHubアカウント連携

herokuA.png

作成したアプリを押すと、↑のような画面になるので、Deployタブを選択し、Deployment methodGitHubを押します。

そのあとは、自分のデプロイしたいリポジトリを選びます。

herokuB.png

↑この状態になってればOKです

3.必要ファイルを作成

自分のデプロイしたいリポジトリにファイルを三つ作成します。
terminalなどで、リポジトリのディレクトリのルートに入り以下を実行します

$ pip install gunicorn
$ pip freeze -l > requirements.txt
$ echo "web: gunicorn 起動ファイル名:app --log-file -" > Procfile
$ echo "pythonの環境" > runtime.txt

manage.pypython-3.6.3で起動するなら、

$ pip install gunicorn
$ pip freeze -l > requirements.txt
$ echo "web: gunicorn manage:app --log-file -" > Procfile
$ echo "python-3.6.3" > runtime.txt

4.デプロイ

先ほどの変更をそのままpushすれば反映されます

$ git add .
$ git commit -m 'Heroku'
$ git push origin master

5.確認

$ heroku login
$ heroku open --app 自分の作成したアプリ

これで確認できるはずです。ちなみに、若干のタイムラグがあるので即時反映はされません。

できない場合は、

herokuB 2.png

Deploy Branchを押して、下の方に出て来るViewを押して確認してください

おわりに

参考にしたサイトは、

です

4
7
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
4
7