Rails 6.0 VSCodeでherokuへのプッシュまで
bitbucketへの公開鍵の登録とHerokuへのプッシュまでを設定したので今後何かの新しい開発環境を使う際にチェックできるようにメモ(Railstutorialより抜粋)
※開発環境が同じで単に新しいアプリケーションを作るだけの際の流れはこちら
1)git configで設定
$ git config --global user.name "Your Name" $ git config --global user.email your.email@example.com
※これはVSCode導入時にすでにやっていた
2)git initでセットアップ(アプリケーションのディレクトリで)
$ git init
$ git add -A
$ git commit -m "Initialize repository"
3)公開鍵の確認とBitbucketに公開鍵を追加
①公開鍵をクリップボードにコピー
※公開鍵がない場合 (Git - SSH 公開鍵の作成 参照)
$ ssh-keygen
で作成
$ cat ~/.ssh/id_rsa.pub
で出力しコピー
※公開鍵がある場合
$ cat ~/.ssh/id_rsa.pub
で出力しコピー
②Bitbucketのアカウント内で[Bitbucket 設定]、[SSH 鍵]の順に進み貼り付け
4)アプリケーション用のリポジトリの作成
①Bitbucketのアカウント内で[+]からリポジトリを作成
②Bitbucketへのリポジトリ追加とリポジトリへのプッシュ
アプリケーションのディレクトリに行き、Bitbucketで表示されるコード入力
$ git remote add origin git@bitbucket.org:ユーザー名/hello_app.git $ git push -u origin --all
※上記はRails tutorialより抜粋した例
5)編集(例えばブランチ管理でREADMEの編集)
$ git checkout -b modify-README
編集後
$ git commit -a -m "Improve the README file"
$ git checkout master
$ git merge modify-README
$ git push
6)production環境(heroku用)にpg gemの追加
group :production do
gem 'pg', '~> 0.18.4'
end
※HerokuはpostgreSQLなのでproduction環境にgem設定
$ bundle install --without production
$ git commit -a -m "Update Gemfile for Heroku"
$ heroku --version
※heroku入ってるか確認(入ってなければ入れる)
7)Herokuのセットアップ(SSHキーの追加)
$ heroku login --interactive $ heroku keys:add
※SSHキーの追加
8)Herokuにアプリケーションの実行場所を追加
$ heroku create
9)Herokuにデプロイ
$ git push heroku master