HerokuでRailsアプリケーションを公開した

はじめに
ポートフォリオとして作成中のRailsアプリ「Money App」をとりあえず公開する。

gemfileを改修

この記事の通りに改修を行ったら、「bundle install –without production」をターミナルに打ち込んだところでエラーが出た。

出ていたエラーメッセージ。
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue.
In Gemfile:
sqlite3
Gemfileの変更を元に戻した。
herokuでnew appを作成した

以下のように、新しいアプリを作成した。地域はアメリカかヨーロッパしか選べなかった。

支払い方法を追加する必要があるみたいなので、Add Payment Methodをクリックした。
We won’t charge you at this time. とのこと。
今回は課金されませんという意味である。
最初のアプリでは課金されないということだろう。
クレジットカードを登録する時に、1.00USDが課金されているのが気になった。

ただ、アプリを見てみると、0になっていたので安心した。

もう一度アプリの作成の手続きを行うと完了することができた。
この画面になった。

GitHubと接続する
GitHubと繋げるという作業を行っていく。

GitHubのアイコンを選択した後に下のほうに出てきたボタンを押すと、GitHubにログインする画面が出てきた。
そこで、Herokuを認証していいですか?という確認画面が出てきて、「はい」を押すと、以下の画面になった。

ここで、公開したいリポジトリのリポジトリ名を入力するのがいいだろう。

money-appというレポジトリー名なので、こちらを入力していく。

見つかったのでコネクトする。
無事、コネクトされたようだ。

GitHubから公開する
いよいよ最終段階に入っていく。

下のほうにスクロールすると、Deploy Branchというボタンがあるので、公開したいブランチ名が選択されていることを確認してボタンをクリックする。
ビルドが上手く行かなかった
いろんな処理が走ってビルドが完成したようだ。いや、うまくいかなかったようだ。

ログメッセージはこちら。
-----> Building on the Heroku-22 stack
-----> Determining which buildpack to use for this app
-----> Ruby app detected
-----> Installing bundler 2.3.25
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.1.2
-----> Installing dependencies using bundler 2.3.25
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Your bundle only supports platforms ["x86_64-darwin-20", "x86_64-darwin-23"] but
your local platform is x86_64-linux. Add the current platform to the lockfile
with
`bundle lock --add-platform x86_64-linux` and try again.
Bundler Output: Your bundle only supports platforms ["x86_64-darwin-20", "x86_64-darwin-23"] but
your local platform is x86_64-linux. Add the current platform to the lockfile
with
`bundle lock --add-platform x86_64-linux` and try again.
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
上記の赤字部分、以下の部分が重要そうだった。重要なことだからなのか、2回繰り返していた。
Your bundle only supports platforms ["x86_64-darwin-20", "x86_64-darwin-23"] but your local platform is x86_64-linux.
Add the current platform to the lockfile with `bundle lock --add-platform x86_64-linux` and try again.
日本語にすると、以下のようになる。
あなたのバンドルは、["x86_64-darwin-20", "x86_64-darwin-23"]というプラットフォームのみをサポートしている。しかし、あなたのローカルプラットフォームは、x86_64-linuxである。
bundle lock --add-platform x86_64-linuxで、現在のプラットフォームに追加して、もう一度やり直してください。
言われた通りのコマンドを打ってみる
Gemfile.lockに「x86_64-linux」の記述が追加された。


この変化点を反映させるために、GitHubにプッシュする一連の流れを行う。

もう一度トライ
先程のエラーが解決されてうまくいったようだ。

Viewボタンをクリックすると、公開されたページに飛ぶことができた。

コメントを残す