事前準備
事前準備として、上記リンクの内容が必要です。
heroku デプロイ方法(Spring)
- コマンドプロンプトを開く
- herokuにログインを行う
heroku login - 資材をフォルダに配置する
※ サンプルプロジェクトはGitHubに公開されています。git clone https://github.com/heroku/java-getting-started cd java-getting-started - Gitリポジトリを新規作成する
git init -
.git/configを開き、以下を追加[remote "heroku"] url = https://git.heroku.com/[app名].git fetch = +refs/heads/*:refs/remotes/heroku/* - 資材をインデックスに追加する(コミットの対象にする)
git add . - インデックスに追加した変更をリポジトリに記録する
git commit -m "コメント" - Herokuアプリを作成する
heroku create - ローカルリポジトリの変更内容をリモートリポジトリに送信する(デプロイ)
※エラー時は エラー対処 へgit push heroku master - アプリにアクセスする
※エラー時は エラー対処 へheroku open - ログの監視を行う
heroku logs --tail
エラー対処
failed to push some refs to 'https://git.heroku.com/[app名].git'
error: failed to push some refs to 'https://git.heroku.com/[app名].git'
上記エラーが出た場合、最新でない可能性があるため、以下コマンドを実行
git pull origin
Multiple apps in git remotes
» Warning: heroku update available from 7.53.0 to 7.59.0.
» Error: Multiple apps in git remotes
» Usage: --remote origin
» or: --app [app名]
» Your local git repository has more than 1 app referenced in git remotes.
» Because of this, we can't determine which app you want to run this command against.
» Specify the app you want with --app or --remote.
» Heroku remotes in repo:
» [app名] (heroku)
» [app名] (origin)
»
» https://devcenter.heroku.com/articles/multiple-environments
上記エラーが出た場合、以下コマンドでorigin以外は削除
git remote -v
git remote rm <名前>
その他コマンド
- postgresql追加
heroku addons:create heroku-postgresql
- 環境変数を確認
heroku config
- 環境変数を設定
heroku config:set 環境変数名=値
heroku config:set 環境変数名1=値1 環境変数名2=値2
- 詳細情報を確認
heroku pg
参考文献