学生向けプログラミング入門 | 無料

学生向けにプログラミングを無料で解説。Java、C++、Ruby、PHP、データベース、Ruby on Rails, Python, Django

Rails7.1 | 仕事売買アプリ作成 | 52 | Herokuの接続とPush

↓↓クリックして頂けると励みになります。



51 | コンパイルテスト】 << 【ホーム】 >> 【53 | Heroku postgresの設定



いよいよ作成したアプリケーションをherokuへデプロイする時が来ました。
Herokuへの接続の確立、HerokuとGithubの接続、デプロイの方法等、順に解説していきます。


Herokuに接続してGithubのファイルをPushしますが、方法は2通りあります。
一つはCLIを利用してコマンドラインで接続する方法、もう一つはHerokuのWebページで行う方法です。
まずはCLIを利用する方法から解説します。


「heroku CLI」をインストールします。
コマンド
brew tap heroku/brew && brew install heroku


xcodeのバージョンが古い場合、以下のようなエラーが出ます。

==> Installing heroku from heroku/brew
Error: Your Command Line Tools are too outdated.
Update them from Software Update in System Settings.

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 14.3.



このエラーの通り、まずsudo rm -rf /Library/Developer/CommandLineToolsとコマンドを打ち、古いライブラリを削除します。
次にsudo xcode-select --installとタイプし、xcodeのインストールをやり直します。
そうすることでherokuCLIをインストールできるようになります。


バージョン確認します。
コマンド
xcode-select --version

~/Desktop/QRMenu/qrmenu_react $ xcode-select --version 
xcode-select version 2403.



herokuのバージョン確認します。
コマンド
heroku --version

~/Desktop/Rails7_1/GigHub7 $ heroku --version

heroku/8.7.1 darwin-x64 node-v16.19.0



herokuにターミナルでログインします。
コマンド
heroku login

herokuログイン
herokuログイン



なんでもいいからタイプしろと言われるのでエンターキーを押します。

herokuログイン
herokuログイン



ブラウザでログイン画面が起動しますので、herokuにログインして下さい。

ブラウザでherokuにログイン
ブラウザでherokuにログイン



ターミナルで「Logged in」と出ればログイン成功です。

ログイン成功
ログイン成功



heroku git:remote​コマンドを使用して、ローカルリポジトリにアプリケーションを追加します。
コマンドの最後にHerokuで作成したアプリの名前を入れてください。
コマンド
heroku git:remote -a アプリケーション名


git remote -vコマンドで追加したアプリケーション名が表示されるのを確認してください。
コマンド
git remote -v

~/Desktop/Rails7_1/GigHub7 $ git remote -v

heroku  https://git.heroku.com/gighub7.git (fetch)
heroku  https://git.heroku.com/gighub7.git (push)
main    https://github.com/nishichin/GigHub7.git (fetch)
main    https://github.com/nishichin/GigHub7.git (push)



Herokuにpushします。
コマンド
git push heroku main

heroku CLI
heroku CLI



2023年11月18日現在、このRails7.1プロジェクトの環境でエラーはでませんでした。


無事HerokuにPushできると、4つほど警告がでますが以下のようになります。

remote: -----> Detecting rails configuration
remote: 
remote: ###### WARNING:
remote: 
remote:        Installing a default version (20.9.0) of Node.js.
remote:        This version is not pinned and can change over time, causing unexpected failures.
remote:        
remote:        Heroku recommends placing the `heroku/nodejs` buildpack in front of
remote:        `heroku/ruby` to install a specific version of node:
remote:        
remote:        https://devcenter.heroku.com/articles/ruby-support#node-js-support
remote: 
remote: ###### WARNING:
remote: 
remote:        You set your `config.assets.compile = true` in production.
remote:        This can negatively impact the performance of your application.
remote:        
remote:        For more information can be found in this article:
remote:          https://devcenter.heroku.com/articles/rails-asset-pipeline#compile-set-to-true-in-production
remote:        
remote: 
remote: ###### WARNING:
remote: 
remote:        There is a more recent Ruby version available for you to use:
remote:        
remote:        3.1.4
remote:        
remote:        The latest version will include security and bug fixes. We always recommend
remote:        running the latest version of your minor release.
remote:        
remote:        Please upgrade your Ruby version.
remote:        
remote:        For all available Ruby versions see:
remote:          https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote: 
remote: ###### WARNING:
remote: 
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote: 
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web
remote: 
remote: -----> Compressing...
remote:        Done: 127.2M
remote: -----> Launching...
remote:        Released v4
remote:        https://gighub7-cf4bb18b88c3.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/gighub7.git
 * [new branch]      main -> main



もう一つの方法を書いておきます。
herokuのページにログインし、「Deploy」の「GitHub」をクリックします。

Deploy
Deploy



「ConnectTo GitHub」をクリックします。

Connect To GitHub
Connect To GitHub



「Authorize Heroku」をクリックします。

Authorize Heroku
Authorize Heroku



パスワードを入力し、レポジトリ名を入力後検索します。
レポジトリが出てきたらConnectをクリックします。

レポジトリ名を検索
レポジトリ名を検索



一番下の「Deploy branch」をクリックし、デプロイします。

Deploy a GitHub branch
Deploy a GitHub branch



成功メッセージが出ればOKです。

デプロイ成功
デプロイ成功




51 | コンパイルテスト】 << 【ホーム】 >> 【53 | Heroku postgresの設定





↓↓クリックして頂けると励みになります。