Skip Navigation
Show nav
Dev Center
  • Get Started
  • ドキュメント
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • ドキュメント
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku のアーキテクチャ
    • Dyno (アプリコンテナ)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • スタック (オペレーティングシステムイメージ)
    • ネットワーキングと DNS
    • プラットフォームポリシー
    • プラットフォームの原則
  • Developer Tools
    • コマンドライン
    • Heroku VS Code Extension
  • デプロイ
    • Git を使用したデプロイ
    • Docker によるデプロイ
    • デプロイ統合
  • 継続的デリバリーとインテグレーション
    • 継続的統合
  • 言語サポート
    • Node.js
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails のサポート
      • Bundler の使用
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Python でのバックグランドジョブ
      • Python Behavior in Heroku
      • Django の使用
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Maven の使用
      • Spring Boot の使用
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go の依存関係管理
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • データベースとデータ管理
    • Heroku Postgres
      • Postgres の基礎
      • Postgres スターターガイド
      • Postgres のパフォーマンス
      • Postgres のデータ転送と保持
      • Postgres の可用性
      • Postgres の特別なトピック
      • Migrating to Heroku Postgres
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • その他のデータストア
  • AI
    • Working with AI
    • Heroku Inference
      • Inference API
      • Quick Start Guides
      • AI Models
      • Inference Essentials
    • Vector Database
    • Model Context Protocol
  • モニタリングとメトリクス
    • ログ記録
  • アプリのパフォーマンス
  • アドオン
    • すべてのアドオン
  • 共同作業
  • セキュリティ
    • アプリのセキュリティ
    • ID と認証
      • シングルサインオン (SSO)
    • Private Space
      • インフラストラクチャネットワーキング
    • コンプライアンス
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Team
    • Heroku Connect (Salesforce 同期)
      • Heroku Connect の管理
      • Heroku Connect のリファレンス
      • Heroku Connect のトラブルシューティング
  • パターンとベストプラクティス
  • Heroku の拡張
    • Platform API
    • アプリの Webhook
    • Heroku Labs
    • アドオンのビルド
      • アドオン開発のタスク
      • アドオン API
      • アドオンのガイドラインと要件
    • CLI プラグインのビルド
    • 開発ビルドパック
    • Dev Center
  • アカウントと請求
  • トラブルシューティングとサポート
  • Salesforce とのインテグレーション
  • 言語サポート
  • Ruby
  • Rails のサポート
  • Heroku スターターガイド (Rails 7.x)

Heroku スターターガイド (Rails 7.x)

日本語 — Switch to English

この記事の英語版に更新があります。ご覧の翻訳には含まれていない変更点があるかもしれません。

最終更新日 2024年05月16日(木)

Table of Contents

  • ローカルの設定
  • 新しい Rails アプリの作成または既存の Rails アプリのアップグレード
  • pg gem の追加
  • ウェルカムページの作成
  • Ruby バージョンの指定
  • Procfile の作成
  • Git でのアプリの保存
  • Heroku アプリの作成
  • データベースのプロビジョニング
  • Heroku へのアプリのデプロイ
  • データベースの移行
  • アプリケーションのスケーリングとアクセス
  • アプリケーションログの表示
  • オプションのステップ
  • トラブルシューティング
  • 次のステップ
  • アプリとアドオンを削除する

Ruby on Rails は、Ruby​ で記述され、広く使われている Web フレームワークです。このガイドでは、Heroku での Rails 7 の使用について説明します。Heroku での Rails 旧バージョンの実行についての詳細は、Rails 6.x​ または Rails 5.x​ に関するチュートリアルを参照してください。

このチュートリアルでは、以下が用意されていることを前提としています。

  • Ruby、Ruby on Rails、および Git に関する基本的な知識
  • Ruby 3.0.0+、Rubygems、Bundler、Rails 7 のローカルにインストールされたバージョン+
  • Heroku CLI​ のローカルにインストールされたバージョン
  • 確認済みの Heroku アカウント
  • Eco dyno プラン​のサブスクリプション (推奨)

dyno とデータベースを使用してこのチュートリアルを完了した場合、使用量のカウントに入ります。低料金プラン​を使用してこのチュートリアルを完了することをお勧めします。資格のある学生の皆様は、新しい Heroku for GitHub Students プログラム​を通じてプラットフォームクレジットを申請できます。

ローカルの設定

Heroku CLI​ のインストール後、ターミナルからログインします。

$ heroku login
heroku: Press any key to open up the browser to login or q to exit
 ›   Warning: If browser does not open, visit
 ›   https://cli-auth.heroku.com/auth/browser/***
heroku: Waiting for login...
Logging in... done
Logged in as developer@example.com

このコマンドにより、Web ブラウザで Heroku ログインページが開きます。ブラウザですでに Heroku にログインしている場合は、ページの Log in​ (ログイン) ボタンをクリックします。

この認証は、heroku​ と git​ コマンドが正常に動作するために必要な操作です。

外部の HTTP/HTTPS サービスへの接続にプロキシを使用するファイアウォールを利用している場合は、heroku​ コマンドを実行する前に、ローカルの開発環境で HTTP_PROXY​ または HTTPS_PROXY​ 環境変数を設定​してください。

新しい Rails アプリの作成または既存の Rails アプリのアップグレード

アプリを作成する前に、rails -v​ を実行して、Rails 7 がインストールされていることを確認します。必要に応じて、gem install​ を使用して Rails 7 をインストールします。

$ gem install rails --no-document
Successfully installed rails-7.1.3.2
1 gem installed

Rails アプリを作成します。

$ rails new myapp --database=postgresql

アプリケーションディレクトリに移動し、Gemfile.lock​ に x86_64-linux​ および ruby​ プラットフォームを追加します。

$ cd myapp
$ bundle lock --add-platform x86_64-linux --add-platform ruby
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Writing lockfile to ./myapp/Gemfile.lock

ローカルデータベースを作成します。

$ bin/rails db:create
Database 'myapp_development' already exists
Database 'myapp_test' already exists

pg gem の追加

--database=postgresql​ が定義されていない新規または既存のアプリの場合は、Gemfile​ 内に sqlite3​ gem が存在しないことを確認します。pg​gem を所定の位置に追加します。

Gemfile​ 内で、次の行を削除します。

gem 'sqlite3'

これを次の行に置き換えます。

gem 'pg'

開発中は PostgreSQL をローカルで使用することを強くお勧めします。開発環境とデプロイ環境の間の同等性​を維持することにより、環境の違いによる微妙なバグが取り込まれることを防ぎます。

Postgres をローカルにインストールします​。Sqlite3 の代わりに Postgres が推奨される理由についての詳細は、Sqlite3 が Heroku と互換性がない理由​を参照してください。

Gemfile​ が更新されたら、依存関係を再インストールします。

$ bundle install

インストールによって、Gemfile.lock​ も変更を含めて更新されます。

pg​ gem に加えて、config/database.yml​ で postgresql​ アダプタが定義されていることを確認します。config/database.yml​ファイルの開発セクションは次のようになります。

$ cat config/database.yml
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On macOS with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem "pg"
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

  # The specified database role being used to connect to PostgreSQL.
  # To create additional roles in PostgreSQL see `$ createuser --help`.
  # When left blank, PostgreSQL will use the default role. This is
  # the same name as the operating system user running Rails.
  #username: myapp

  # The password associated with the PostgreSQL role (username).
  #password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myapp_test

# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
#   production:
#     url: <%= ENV["MY_APP_DATABASE_URL"] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
  <<: *default
  database: myapp_production
  username: myapp
  password: <%= ENV["MYAPP_DATABASE_PASSWORD"] %>

ここで注意点があります。adapter​の値が postgres​ で、postgresql​ でない場合、アプリケーションは機能しません。

ウェルカムページの作成

Rails 7 の本番環境には、デフォルトで静的なインデックスページがありません。Rails 7 にアップグレードされたアプリでは既存のページ設定が保持されますが、新しい Rails 7 アプリでは、自動的にウェルカムページが生成されません。ホームページを保持するための welcome​ コントローラーを作成します。

$ rails generate controller welcome

app/views/welcome/index.html.erb​ を作成し、次のコードを追加します。

<h2>Hello World</h2>
<p>
  The time is now: <%= Time.now %>
</p>

ウェルカムページが作成されたら、このアクションにマッピングするためのルートを作成します。

ファイル config/routes.rb​ の 2 行目に以下を追加します。

  root 'welcome#index'

Rails Web サーバーを起動して、ページが表示されることを確認します。

$ rails server

ブラウザで http://localhost:3000​ にアクセスします。ページが表示されない場合は、ログを参照​して、エラーをデバッグします。Rails によって、rails server​ を起動したのと同じターミナルにログが出力されます。

Ruby バージョンの指定

Rails 7 では、Ruby 2.7.0 以上が必要です。Heroku は、デフォルトでは最新バージョンの Ruby をインストールします。Gemfile​で ruby​ DSL を使用して、特定のバージョンを指定します。たとえば、次のようになります。

ruby "3.2.4"

常にローカルでも同じバージョンの Ruby を使用します。ruby -v​を使用して ruby のローカルバージョンを確認します。特定の Ruby バージョンの定義についての詳細は、「Ruby のバージョン​」の記事を参照してください。

Procfile の作成

Procfile​ は、アプリケーションのルートディレクトリにあるテキストファイルです。このファイルを使って、アプリの起動時に実行するコマンドを明示的に宣言します。

この Procfile では、単一のプロセスタイプの web​ と、その実行に必要なコマンドを宣言しています。 ここでは、web​ という名前が重要です。 これは、このプロセスタイプを Heroku の HTTP ルーティング​スタックにアタッチし、デプロイ後に Web トラフィックを受信することを宣言しています。

デフォルトでは、Rails アプリの Web プロセスは、Rails 7 で Puma を使用する rails server​ を実行します。Procfile​ を使用せずに Rails 7 アプリケーションをデプロイすると、このコマンドが実行されます。ただし、Procfile​ を介してサーバープロセスを起動する方法を明示的に宣言することをお勧めします。たとえば、次のようになります。

web: bundle exec puma -C config/puma.rb

Procfile​ ファイル名は大文字と小文字が区別されます。ファイル拡張子はありません。

config/puma.rb​ が存在しない場合は、最大のパフォーマンスを得るために、Heroku の Puma ドキュメント​を使用して作成してください。

Procfile には追加のプロセスタイプを含めることができます。 たとえば、キューからアイテムを取り出して処理するバックグラウンドワーカープロセス​を宣言できます。

Git でのアプリの保存

Heroku では、アプリケーションのデプロイを分散型ソース管理ツールである Git​ に依存しています。アプリケーションがまだ Git に存在しない場合は、まず git --help​ を使用して git​ がシステムに存在することを確認してください。

$ git --help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--config-env=<name>=<envvar>] <command> [<args>]

コマンドで出力が生成されないか、または command not found​ の場合、Git をインストール​します。

Rails アプリのルートディレクトリに移動します。ls​コマンドを使用して、その内容を確認します。

$ ls
Dockerfile
Gemfile
Gemfile-e
Gemfile.lock
Procfile
README.md
Rakefile
app
bin
config
config.ru
db
lib
log
public
storage
test
tmp
vendor

Rails アプリ内で直接、ローカルの空の Git リポジトリを初期化し、そのアプリのコードをコミットします。

$ git init
$ git add .
$ git commit -m "init"

git status​ を使用して、すべてが正しくコミットされたことを確認します。

$ git status
On branch main
nothing to commit, working tree clean

アプリケーションが Git にコミットされたら、Heroku にデプロイする準備ができています。

Heroku アプリの作成

dyno とデータベースを使用してこのチュートリアルを完了した場合、使用量のカウントに入ります。コストを抑制するために、完了したらすぐにアプリを削除​し、データベースも削除​してください。

Heroku でアプリを作成するには、Rails アプリのルートディレクトリ内で Heroku CLI を使用します。

$ heroku apps:create
Creating app... done, murmuring-taiga-66903
https://murmuring-taiga-66903-369309d7b6b1.herokuapp.com/ | https://git.heroku.com/murmuring-taiga-66903.git

アプリを作成すると、heroku​ という名前の Git リモートリポジトリも作成され、ローカルの Git リポジトリと関連付けられます。Git リモートは、他のサーバー上で稼働するリポジトリのバージョンです。アプリに関連付けられた、Heroku でホストされる特別なリモートにコードをプッシュすることにより、アプリをデプロイします。git config​でリモートが 設定されていることを確認します。

$ git config --list --local | grep heroku
remote.heroku.url=https://git.heroku.com/murmuring-taiga-66903.git
remote.heroku.fetch=+refs/heads/*:refs/remotes/heroku/*

現在のディレクトリが正しくないか、または Git が初期化​されていない場合、Git は fatal: not in a git directory​ を返します。Git がリモートの一覧を返した場合は、デプロイする準備ができています。

業界での変更に従い、Heroku ではデフォルトのブランチ名​を main​ に更新しました。プロジェクトでデフォルトのブランチ名として master​ を使用している場合は、git push heroku master​ を使用してください。

データベースのプロビジョニング

Elements Marketplace​ から入手可能なアドオンの 1 つである Heroku Postgres​ データベースをプロビジョニングします。アドオンは、ログ記録、モニタリング、データベースなど、アプリケーションですぐに使える追加サービスを提供するクラウドサービスです。

essential-0​ Postgres のサイズのコストは月額 5 ドルで、分単位で課金されます​。このチュートリアルの最後で、データベースを削除​して、コストを最小限に抑えるように求められます。

$ heroku addons:create heroku-postgresql:essential-0
Creating heroku-postgresql:essential-0 on ⬢ murmuring-taiga-66903... ~$0.007/hour (max $5/month)
Database should be available soon
postgresql-corrugated-66300 is being created in the background. The app will restart when complete...
Use heroku addons:info postgresql-corrugated-66300 to check creation progress
Use heroku addons:docs heroku-postgresql to view documentation

Heroku アプリでこの Postgres データベースにアクセスできるようになりました。DATABASE_URL​環境変数は、規約によって Rails が接続する資格情報を格納します。

Heroku へのアプリのデプロイ

dyno を使用してこのチュートリアルを完了した場合、使用量のカウントに入ります。コストを抑制するために、完了したらすぐにアプリを削除​してください。

コードをデプロイします。このコマンドは、サンプルリポジトリの main​ ブランチを heroku​ リモートにプッシュし、次に Heroku にデプロイします。

$ git push heroku main
remote: Updated 87 paths from 5068e81
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-22 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.5.6
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.2.4
remote: -----> Installing dependencies using bundler 2.5.6
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching rake 13.2.1
remote:        Installing rake 13.2.1
remote:        Fetching base64 0.2.0
remote:        Fetching bigdecimal 3.1.7
remote:        Fetching concurrent-ruby 1.2.3
remote:        Fetching connection_pool 2.4.1
remote:        Installing base64 0.2.0
remote:        Fetching drb 2.2.1
remote:        Installing bigdecimal 3.1.7 with native extensions
remote:        Installing connection_pool 2.4.1
remote:        Fetching minitest 5.22.3
remote:        Installing concurrent-ruby 1.2.3
remote:        Installing drb 2.2.1
remote:        Fetching mutex_m 0.2.0
remote:        Installing mutex_m 0.2.0
remote:        Fetching builder 3.2.4
remote:        Installing minitest 5.22.3
remote:        Installing builder 3.2.4
remote:        Fetching erubi 1.12.0
remote:        Installing erubi 1.12.0
remote:        Fetching racc 1.7.3
remote:        Fetching crass 1.0.6
remote:        Fetching rack 3.0.10
remote:        Installing racc 1.7.3 with native extensions
remote:        Installing crass 1.0.6
remote:        Fetching nio4r 2.7.1
remote:        Installing rack 3.0.10
remote:        Installing nio4r 2.7.1 with native extensions
remote:        Fetching websocket-extensions 0.1.5
remote:        Installing websocket-extensions 0.1.5
remote:        Fetching zeitwerk 2.6.13
remote:        Installing zeitwerk 2.6.13
remote:        Fetching timeout 0.4.1
remote:        Installing timeout 0.4.1
remote:        Fetching marcel 1.0.4
remote:        Installing marcel 1.0.4
remote:        Fetching mini_mime 1.1.5
remote:        Installing mini_mime 1.1.5
remote:        Fetching date 3.3.4
remote:        Installing date 3.3.4 with native extensions
remote:        Fetching msgpack 1.7.2
remote:        Installing msgpack 1.7.2 with native extensions
remote:        Fetching stringio 3.1.0
remote:        Installing stringio 3.1.0 with native extensions
remote:        Fetching io-console 0.7.2
remote:        Installing io-console 0.7.2 with native extensions
remote:        Fetching webrick 1.8.1
remote:        Installing webrick 1.8.1
remote:        Fetching thor 1.3.1
remote:        Installing thor 1.3.1
remote:        Fetching pg 1.5.6
remote:        Installing pg 1.5.6 with native extensions
remote:        Fetching redis-client 0.22.1
remote:        Installing redis-client 0.22.1
remote:        Fetching i18n 1.14.4
remote:        Installing i18n 1.14.4
remote:        Fetching tzinfo 2.0.6
remote:        Installing tzinfo 2.0.6
remote:        Fetching rack-session 2.0.0
remote:        Installing rack-session 2.0.0
remote:        Fetching rack-test 2.1.0
remote:        Installing rack-test 2.1.0
remote:        Fetching sprockets 4.2.1
remote:        Installing sprockets 4.2.1
remote:        Fetching websocket-driver 0.7.6
remote:        Installing websocket-driver 0.7.6 with native extensions
remote:        Fetching net-protocol 0.2.2
remote:        Installing net-protocol 0.2.2
remote:        Fetching nokogiri 1.16.4 (x86_64-linux)
remote:        Installing nokogiri 1.16.4 (x86_64-linux)
remote:        Fetching puma 6.4.2
remote:        Installing puma 6.4.2 with native extensions
remote:        Fetching psych 5.1.2
remote:        Installing psych 5.1.2 with native extensions
remote:        Fetching bootsnap 1.18.3
remote:        Installing bootsnap 1.18.3 with native extensions
remote:        Fetching rackup 2.1.0
remote:        Installing rackup 2.1.0
remote:        Fetching reline 0.5.5
remote:        Installing reline 0.5.5
remote:        Fetching redis 5.2.0
remote:        Installing redis 5.2.0
remote:        Fetching net-pop 0.1.2
remote:        Installing net-pop 0.1.2
remote:        Fetching net-smtp 0.5.0
remote:        Installing net-smtp 0.5.0
remote:        Fetching net-imap 0.4.10
remote:        Installing net-imap 0.4.10
remote:        Fetching loofah 2.22.0
remote:        Installing loofah 2.22.0
remote:        Fetching activesupport 7.1.3.2
remote:        Installing activesupport 7.1.3.2
remote:        Fetching rdoc 6.6.3.1
remote:        Installing rdoc 6.6.3.1
remote:        Fetching mail 2.8.1
remote:        Installing mail 2.8.1
remote:        Fetching rails-html-sanitizer 1.6.0
remote:        Installing rails-html-sanitizer 1.6.0
remote:        Fetching rails-dom-testing 2.2.0
remote:        Installing rails-dom-testing 2.2.0
remote:        Fetching globalid 1.2.1
remote:        Installing globalid 1.2.1
remote:        Fetching activemodel 7.1.3.2
remote:        Installing activemodel 7.1.3.2
remote:        Fetching irb 1.13.0
remote:        Installing irb 1.13.0
remote:        Fetching actionview 7.1.3.2
remote:        Installing actionview 7.1.3.2
remote:        Fetching activejob 7.1.3.2
remote:        Installing activejob 7.1.3.2
remote:        Fetching activerecord 7.1.3.2
remote:        Installing activerecord 7.1.3.2
remote:        Fetching actionpack 7.1.3.2
remote:        Installing actionpack 7.1.3.2
remote:        Fetching jbuilder 2.12.0
remote:        Installing jbuilder 2.12.0
remote:        Fetching actioncable 7.1.3.2
remote:        Installing actioncable 7.1.3.2
remote:        Fetching activestorage 7.1.3.2
remote:        Installing activestorage 7.1.3.2
remote:        Fetching actionmailer 7.1.3.2
remote:        Installing actionmailer 7.1.3.2
remote:        Fetching railties 7.1.3.2
remote:        Installing railties 7.1.3.2
remote:        Fetching sprockets-rails 3.4.2
remote:        Installing sprockets-rails 3.4.2
remote:        Fetching actionmailbox 7.1.3.2
remote:        Installing actionmailbox 7.1.3.2
remote:        Fetching actiontext 7.1.3.2
remote:        Installing actiontext 7.1.3.2
remote:        Fetching importmap-rails 2.0.1
remote:        Installing importmap-rails 2.0.1
remote:        Fetching stimulus-rails 1.3.3
remote:        Installing stimulus-rails 1.3.3
remote:        Fetching turbo-rails 2.0.5
remote:        Installing turbo-rails 2.0.5
remote:        Fetching rails 7.1.3.2
remote:        Installing rails 7.1.3.2
remote:        Bundle complete! 15 Gemfile dependencies, 70 gems now installed.
remote:        Gems in the groups 'development' and 'test' were not installed.
remote:        Bundled gems are installed into `./vendor/bundle`
remote:        Bundle completed (35.78s)
remote:        Cleaning up the bundler cache.
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2024-05-03T15:57:41.661688 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/manifest-b84bfa46a33d7f0dc4d2e7b8889486c9a957a5e40713d58f54be71b66954a1ff.js
remote:        I, [2024-05-03T15:57:41.661889 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/manifest-b84bfa46a33d7f0dc4d2e7b8889486c9a957a5e40713d58f54be71b66954a1ff.js.gz
remote:        I, [2024-05-03T15:57:41.662182 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/application-e0cf9d8fcb18bf7f909d8d91a5e78499f82ac29523d475bf3a9ab265d5e2b451.css
remote:        I, [2024-05-03T15:57:41.662283 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/application-e0cf9d8fcb18bf7f909d8d91a5e78499f82ac29523d475bf3a9ab265d5e2b451.css.gz
remote:        I, [2024-05-03T15:57:41.662400 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js
remote:        I, [2024-05-03T15:57:41.662479 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js.gz
remote:        I, [2024-05-03T15:57:41.662644 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js
remote:        I, [2024-05-03T15:57:41.662719 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js.gz
remote:        I, [2024-05-03T15:57:41.662812 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js
remote:        I, [2024-05-03T15:57:41.662883 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js.gz
remote:        I, [2024-05-03T15:57:41.663073 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js
remote:        I, [2024-05-03T15:57:41.663168 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js.gz
remote:        I, [2024-05-03T15:57:41.663294 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo-6f8f1796078d2d3f7cb9b6badcd2d5e76287a3c58d97baffaa59dd12bd4135f5.js
remote:        I, [2024-05-03T15:57:41.663391 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo-6f8f1796078d2d3f7cb9b6badcd2d5e76287a3c58d97baffaa59dd12bd4135f5.js.gz
remote:        I, [2024-05-03T15:57:41.663508 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo.min-918a6cf2f2be8ed9555c9a11eee69c7dc2f01770802815576efc931876b327fb.js
remote:        I, [2024-05-03T15:57:41.663599 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo.min-918a6cf2f2be8ed9555c9a11eee69c7dc2f01770802815576efc931876b327fb.js.gz
remote:        I, [2024-05-03T15:57:41.663755 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo.min.js-16b5fa18e8e95a86fc9f56ced2c8a9c83a99b73834da35ba1b2ff5dab550d7fa.map
remote:        I, [2024-05-03T15:57:41.663834 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/turbo.min.js-16b5fa18e8e95a86fc9f56ced2c8a9c83a99b73834da35ba1b2ff5dab550d7fa.map.gz
remote:        I, [2024-05-03T15:57:41.663938 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actiontext-78de0ebeae470799f9ec25fd0e20ae2d931df88c2ff9315918d1054a2fca2596.js
remote:        I, [2024-05-03T15:57:41.664285 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actiontext-78de0ebeae470799f9ec25fd0e20ae2d931df88c2ff9315918d1054a2fca2596.js.gz
remote:        I, [2024-05-03T15:57:41.664591 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actiontext.esm-328ef022563f73c1b9b45ace742bd21330da0f6bd6c1c96d352d52fc8b8857e5.js
remote:        I, [2024-05-03T15:57:41.664895 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actiontext.esm-328ef022563f73c1b9b45ace742bd21330da0f6bd6c1c96d352d52fc8b8857e5.js.gz
remote:        I, [2024-05-03T15:57:41.665193 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/trix-e17a480fcb4e30c8571f0fed42dc81de5faeef93755ca30fe9623eb3f5c709e5.js
remote:        I, [2024-05-03T15:57:41.665449 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/trix-e17a480fcb4e30c8571f0fed42dc81de5faeef93755ca30fe9623eb3f5c709e5.js.gz
remote:        I, [2024-05-03T15:57:41.665759 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/trix-91ad87f30d9c53c7b05f534dc3c9994e4e90d50dff03a7222c1326f342f9c223.css
remote:        I, [2024-05-03T15:57:41.666178 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/trix-91ad87f30d9c53c7b05f534dc3c9994e4e90d50dff03a7222c1326f342f9c223.css.gz
remote:        I, [2024-05-03T15:57:41.666487 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-f75215805563870a61ee9dc5a207ce46d4675c7e667558a54344fd1e7baa697f.js
remote:        I, [2024-05-03T15:57:41.666736 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-f75215805563870a61ee9dc5a207ce46d4675c7e667558a54344fd1e7baa697f.js.gz
remote:        I, [2024-05-03T15:57:41.667021 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js
remote:        I, [2024-05-03T15:57:41.667289 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js.gz
remote:        I, [2024-05-03T15:57:41.667598 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js
remote:        I, [2024-05-03T15:57:41.667847 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js.gz
remote:        I, [2024-05-03T15:57:41.668146 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js
remote:        I, [2024-05-03T15:57:41.668411 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js.gz
remote:        I, [2024-05-03T15:57:41.668696 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus.min-dd364f16ec9504dfb72672295637a1c8838773b01c0b441bd41008124c407894.js
remote:        I, [2024-05-03T15:57:41.668958 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus.min-dd364f16ec9504dfb72672295637a1c8838773b01c0b441bd41008124c407894.js.gz
remote:        I, [2024-05-03T15:57:41.669307 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js
remote:        I, [2024-05-03T15:57:41.669566 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-autoloader-c584942b568ba74879da31c7c3d51366737bacaf6fbae659383c0a5653685693.js.gz
remote:        I, [2024-05-03T15:57:41.669871 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js
remote:        I, [2024-05-03T15:57:41.670159 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-importmap-autoloader-db2076c783bf2dbee1226e2add52fef290b5d31b5bcd1edd999ac8a6dd31c44a.js.gz
remote:        I, [2024-05-03T15:57:41.670453 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js
remote:        I, [2024-05-03T15:57:41.670711 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js.gz
remote:        I, [2024-05-03T15:57:41.671027 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus.min.js-2cc63625fa177963b45da974806e7aee846cbf1d4930815733d0fdf3fb232325.map
remote:        I, [2024-05-03T15:57:41.671563 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/stimulus.min.js-2cc63625fa177963b45da974806e7aee846cbf1d4930815733d0fdf3fb232325.map.gz
remote:        I, [2024-05-03T15:57:41.671980 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/activestorage-503a4fe23aabfbcb752dad255f01835904e6961d5f20d1de13987a691c27d9cd.js
remote:        I, [2024-05-03T15:57:41.674247 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/activestorage-503a4fe23aabfbcb752dad255f01835904e6961d5f20d1de13987a691c27d9cd.js.gz
remote:        I, [2024-05-03T15:57:41.682044 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/activestorage.esm-b3f7f0a5ef90530b509c5e681c4b3ef5d5046851e5b70d57fdb45e32b039c883.js
remote:        I, [2024-05-03T15:57:41.682485 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/activestorage.esm-b3f7f0a5ef90530b509c5e681c4b3ef5d5046851e5b70d57fdb45e32b039c883.js.gz
remote:        I, [2024-05-03T15:57:41.682654 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actioncable-1c7f008c6deb7b55c6878be38700ff6bf56b75444a086fa1f46e3b781365a3ea.js
remote:        I, [2024-05-03T15:57:41.682751 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actioncable-1c7f008c6deb7b55c6878be38700ff6bf56b75444a086fa1f46e3b781365a3ea.js.gz
remote:        I, [2024-05-03T15:57:41.682849 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actioncable.esm-06609b0ecaffe2ab952021b9c8df8b6c68f65fc23bee728fc678a2605e1ce132.js
remote:        I, [2024-05-03T15:57:41.682911 #1307]  INFO -- : Writing /tmp/build_95a1e009/public/assets/actioncable.esm-06609b0ecaffe2ab952021b9c8df8b6c68f65fc23bee728fc678a2605e1ce132.js.gz
remote:        Asset precompilation completed (1.62s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote: -----> Detecting rails configuration
remote:
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> web
remote:        Default types for buildpack -> console, rake
remote:
remote: -----> Compressing...
remote:        Done: 42.8M
remote: -----> Launching...
remote:        Released v6
remote:        https://murmuring-taiga-66903-369309d7b6b1.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/murmuring-taiga-66903.git
 * [new branch]      main -> main

出力に警告やエラーメッセージが表示された場合は、出力をチェックして、調整します。

デプロイが成功したら、必要に応じて以下のタスクを実行します。

  • データベースの移行
  • dyno のスケーリング
  • 問題が発生した場合はアプリのログのチェック

データベースの移行

アプリケーションでデータベースを使用している場合は、Heroku CLI を使用して、One-off dyno​ を起動し、移行をトリガーします。One-off dyno で、heroku run​ コマンドを使ってコマンド (通常はアプリの一部を構成するスクリプトやアプリケーション) を実行できます。次のコマンドでデータベース移行をトリガーできます。

$ heroku run rake db:migrate

代わりに対話型シェルを使用するには、heroku run bash​ を実行できます。

アプリケーションのスケーリングとアクセス

Heroku は、定義されたプロセスとプロセスタイプ​を使用してアプリケーションコードを実行します。新しいアプリケーションでは、デフォルトでプロセスタイプがアクティブになりません。次のコマンドはアプリを最大 1 つの dyno にスケーリングし、web​ プロセスを実行します。

$ heroku ps:scale web=1

Heroku CLI の ps​ コマンドを使用して、アプリのすべての dyno の状態をターミナルに表示します。

$ heroku ps
=== web (Basic): bundle exec puma -C config/puma.rb (1)
web.1: up 2024/05/03 10:57:54 -0500 (~ 4s ago)

この例では、1 つの web​ プロセスが実行されています。

Eco​ にサブスクライブしている場合、アプリではデフォルトで Eco dyno が使用されます。それ以外の場合は、デフォルトで Basic dyno が使用されます。Eco dyno プランは、アカウントのすべての Eco dyno 間で共有され、多数の小さなアプリを Heroku にデプロイする場合にお勧めします。Eco dyno は 30 分間トラフィックを何も受信しないとスリープします。 このスリープ動作により、スリープ解除した最初のリクエストで数秒の遅延が発生します。Eco dyno は、月ごとに割り当てられるアカウント別の Eco dyno 時間​を消費します。割り当て時間が残っている限り、アプリは稼働し続けます。

dyno がスリープしないようにするには、「dyno タイプ​」の記事で紹介されている Basic 以上の dyno タイプにアップグレードします。少なくとも Standard dyno にアップグレードすることでも、プロセスタイプあたり複数の dyno にスケールアップできます。

アプリをブラウザで開くには、heroku open​ を実行します。

$ heroku open

ブラウザに、「Hello World」というテキストが表示されます。表示されない場合、またはエラーが発生した場合は、ウェルカムページのコンテンツをレビューして確認​してください。

Heroku では、開発中のすべてのアプリケーションにデフォルトの Web URL​ が提供されます。アプリケーションを本番環境用に準備できたら、カスタムドメイン​を追加します。

アプリケーションログの表示

アプリが正しく実行されないか、またはエラーを生成する場合、アプリログは貴重なツールです。

実行中のアプリに関する情報は、Heroku CLI のログコマンド​ heroku logs​ を使用して表示します。出力例を次に示します。

$ heroku logs
2024-05-03T15:56:53.688568+00:00 app[api]: Release v1 created by user developer@example.com2024-05-03T15:56:53.688568+00:00 app[api]: Initial release by user developer@example.com2024-05-03T15:56:53.994609+00:00 app[api]: Enable Logplex by user developer@example.com2024-05-03T15:56:53.994609+00:00 app[api]: Release v2 created by user developer@example.com2024-05-03T15:56:56.210643+00:00 app[api]: Running release v3 commands by user developer@example.com2024-05-03T15:56:56.210643+00:00 app[api]: Attach DATABASE (@ref:postgresql-corrugated-66300) by user developer@example.com2024-05-03T15:56:56.222146+00:00 app[api]: @ref:postgresql-corrugated-66300 completed provisioning, setting DATABASE_URL. by user developer@example.com2024-05-03T15:56:56.222146+00:00 app[api]: Release v4 created by user developer@example.com2024-05-03T15:56:58.000000+00:00 app[api]: Build started by user developer@example.com2024-05-03T15:57:50.020078+00:00 app[api]: Set LANG, RACK_ENV, RAILS_ENV, RAILS_LOG_TO_STDOUT, RAILS_SERVE_STATIC_FILES, SECRET_KEY_BASE config vars by user developer@example.com2024-05-03T15:57:50.020078+00:00 app[api]: Release v5 created by user developer@example.com2024-05-03T15:57:50.320771+00:00 app[api]: Release v6 created by user developer@example.com2024-05-03T15:57:50.320771+00:00 app[api]: Deploy a0b1f706 by user developer@example.com2024-05-03T15:57:50.332914+00:00 app[api]: Scaled to console@0:Basic rake@0:Basic web@1:Basic by user developer@example.com2024-05-03T15:57:53.000000+00:00 app[api]: Build succeeded
2024-05-03T15:57:53.170135+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2024-05-03T15:57:54.081636+00:00 app[web.1]: [2] Puma starting in cluster mode...
2024-05-03T15:57:54.081709+00:00 app[web.1]: [2] * Puma version: 6.4.2 (ruby 3.2.4-p170) ("The Eagle of Durango")
2024-05-03T15:57:54.081710+00:00 app[web.1]: [2] *  Min threads: 5
2024-05-03T15:57:54.081710+00:00 app[web.1]: [2] *  Max threads: 5
2024-05-03T15:57:54.081710+00:00 app[web.1]: [2] *  Environment: production
2024-05-03T15:57:54.081711+00:00 app[web.1]: [2] *   Master PID: 2
2024-05-03T15:57:54.081711+00:00 app[web.1]: [2] *      Workers: 4
2024-05-03T15:57:54.081711+00:00 app[web.1]: [2] *     Restarts: (✔) hot (✔) phased
2024-05-03T15:57:54.081846+00:00 app[web.1]: [2] * Listening on http://0.0.0.0:25875
2024-05-03T15:57:54.081912+00:00 app[web.1]: [2] Use Ctrl-C to stop
2024-05-03T15:57:54.440430+00:00 heroku[web.1]: State changed from starting to up
2024-05-03T15:57:55.942470+00:00 app[web.1]: [2] - Worker 3 (PID: 11) booted in 1.86s, phase: 0
2024-05-03T15:57:55.948153+00:00 app[web.1]: [2] - Worker 1 (PID: 7) booted in 1.86s, phase: 0
2024-05-03T15:57:55.974855+00:00 app[web.1]: [2] - Worker 0 (PID: 5) booted in 1.89s, phase: 0
2024-05-03T15:57:55.978895+00:00 app[web.1]: [2] - Worker 2 (PID: 9) booted in 1.89s, phase: 0
2024-05-03T15:58:01.558246+00:00 app[web.1]: I, [2024-05-03T15:58:01.558112 #11]  INFO -- : [bdac5d62-b659-4c68-a2cb-f74bccac26ae] Started GET "/" for 13.110.54.14 at 2024-05-03 15:58:01 +0000
2024-05-03T15:58:01.560244+00:00 app[web.1]: I, [2024-05-03T15:58:01.560189 #11]  INFO -- : [bdac5d62-b659-4c68-a2cb-f74bccac26ae] Processing by WelcomeController#index as HTML
2024-05-03T15:58:01.565205+00:00 app[web.1]: I, [2024-05-03T15:58:01.565163 #11]  INFO -- : [bdac5d62-b659-4c68-a2cb-f74bccac26ae]   Rendered layout layouts/application.html.erb (Duration: 4.0ms | Allocations: 2555)
2024-05-03T15:58:01.565377+00:00 app[web.1]: I, [2024-05-03T15:58:01.565353 #11]  INFO -- : [bdac5d62-b659-4c68-a2cb-f74bccac26ae] Completed 200 OK in 5ms (Views: 4.7ms | ActiveRecord: 0.0ms | Allocations: 3396)
2024-05-03T15:58:01.566615+00:00 heroku[router]: at=info method=GET path="/" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=bdac5d62-b659-4c68-a2cb-f74bccac26ae fwd="13.110.54.14" dyno=web.1 connect=0ms service=10ms status=200 bytes=3553 protocol=https
2024-05-03T15:58:01.686259+00:00 heroku[router]: at=info method=GET path="/assets/application-e0cf9d8fcb18bf7f909d8d91a5e78499f82ac29523d475bf3a9ab265d5e2b451.css" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=a65e92f7-edd3-4eec-8280-f82c2d91ae1d fwd="13.110.54.14" dyno=web.1 connect=0ms service=1ms status=200 bytes=639 protocol=https
2024-05-03T15:58:01.800415+00:00 heroku[router]: at=info method=GET path="/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=a5315144-6eb5-4b5e-96f2-7b6a151f1313 fwd="13.110.54.14" dyno=web.1 connect=0ms service=1ms status=200 bytes=387 protocol=https
2024-05-03T15:58:01.904570+00:00 heroku[router]: at=info method=GET path="/assets/turbo.min-918a6cf2f2be8ed9555c9a11eee69c7dc2f01770802815576efc931876b327fb.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=e34b2d4f-f578-4ff4-a1ee-4a471e5a9c5c fwd="13.110.54.14" dyno=web.1 connect=0ms service=1ms status=200 bytes=27538 protocol=https
2024-05-03T15:58:01.906297+00:00 heroku[router]: at=info method=GET path="/assets/stimulus-loading-3576ce92b149ad5d6959438c6f291e2426c86df3b874c525b30faad51b0d96b3.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=3e10eae2-c334-47b2-a6c5-1e16ae77feb9 fwd="13.110.54.14" dyno=web.1 connect=1ms service=1ms status=200 bytes=1279 protocol=https
2024-05-03T15:58:01.907023+00:00 heroku[router]: at=info method=GET path="/assets/stimulus.min-dd364f16ec9504dfb72672295637a1c8838773b01c0b441bd41008124c407894.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=9469b478-adb0-41e9-ba03-6fa166223d7d fwd="13.110.54.14" dyno=web.1 connect=0ms service=1ms status=200 bytes=11321 protocol=https
2024-05-03T15:58:01.912815+00:00 heroku[router]: at=info method=GET path="/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=af6a90f3-9621-4632-ac1f-ab5dffd97fd0 fwd="13.110.54.14" dyno=web.1 connect=0ms service=1ms status=200 bytes=508 protocol=https
2024-05-03T15:58:01.913743+00:00 heroku[router]: at=info method=GET path="/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=f3caf4a6-60b3-4bce-a2d9-132e4f437808 fwd="13.110.54.14" dyno=web.1 connect=1ms service=0ms status=200 bytes=397 protocol=https
2024-05-03T15:58:01.914329+00:00 heroku[router]: at=info method=GET path="/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=797c9084-6983-4032-a9eb-42d64ee5c258 fwd="13.110.54.14" dyno=web.1 connect=1ms service=1ms status=200 bytes=413 protocol=https
2024-05-03T15:58:02.201060+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=murmuring-taiga-66903-369309d7b6b1.herokuapp.com request_id=7e05b330-ce00-4274-9fef-c43af38dc2f9 fwd="13.110.54.14" dyno=web.1 connect=0ms service=4ms status=200 bytes=207 protocol=https

アプリのログの完全なライブストリームを表示するには、コマンドに -t​/--tail​ を追加します。

$ heroku logs --tail

Heroku では、デフォルトで 1500 行のアプリケーションログが記録されますが、完全なログストリームはサービスとして提供されています。複数のアドオンプロバイダ​が、ログの永続化、検索、メールや SMS 通知などの機能を提供するログサービスを用意しています。

オプションのステップ

Rails コンソールの使用

One-off dyno​ をトリガーして、スクリプトやアプリケーションを必要な場合にのみ実行するには、Heroku CLI の run​ コマンドを使用します。このコマンドを使用して、アプリの環境で試行するためにローカルターミナルにアタッチされた Rails コンソールプロセスを起動します。

$ heroku run rails console
irb(main):001:0> puts 1+1
2

また、run bash​ Heroku CLI コマンドもデバッグに役立ちます。このコマンドは、対話型の bash セッションで新しい One-off dyno を起動します。

Rake コマンドの実行

Rails コンソールと同様に、run​ コマンドを使用して、db:migrate​ などの rake​ コマンドを実行します。

$ heroku run rake db:migrate

Procfile をローカルで使用する

Procfile​ をローカルで使用するには、heroku local​ CLI コマンドを使用します。

Procfile​ でのコマンドの実行に加えて、heroku local​ コマンドでは、環境変数を .env​ ファイル経由でローカルで管理することもできます。RACK_ENV​を、ローカル環境の場合は development​ に、Puma の場合は PORT​ に設定します。

$ echo "RACK_ENV=development" >>.env
$ echo "PORT=3000" >> .env

.env​ ファイルを使用して環境変数をローカルで使用する代わりの方法として dotenv​ gem があります。

これらの変数はローカル環境の設定専用であるため、.env​ を .gitignore​ に追加します。

$ echo ".env" >> .gitignore
$ git add .gitignore
$ git commit -m "add .env to .gitignore"

Foreman​ を使用して、Procfile をローカルでテストします。local​を使用して Web サーバーを起動します。

$ heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
10:58:05 AM web.1 |  Puma starting in single mode...
10:58:05 AM web.1 |  * Puma version: 6.4.2 (ruby 3.2.4-p170) ("The Eagle of Durango")
10:58:05 AM web.1 |  *  Min threads: 5
10:58:05 AM web.1 |  *  Max threads: 5
10:58:05 AM web.1 |  *  Environment: development
10:58:05 AM web.1 |  *          PID: 86703
10:58:05 AM web.1 |  * Listening on http://0.0.0.0:3000
10:58:05 AM web.1 |  Use Ctrl-C to stop

Ctrl+C​ または Cmd+C​ を押して終了します。

Rails アセットパイプライン

Heroku にデプロイするときに、Rails アセットパイプライン​を起動するためのオプションはいくつかあります。アセットパイプラインに関する一般的な情報については、「Heroku での Rails アセットパイプライン​」の記事を参照してください。

Rails 7 では、必要がなくなった config.assets.initialize_on_precompile​ オプションが削除されました。さらに、アセットコンパイルで何らかのエラーが発生するとプッシュが失敗するようになりました。Rails 7 アセットパイプラインのサポートについては、Ruby サポート​のページを参照してください。

トラブルシューティング

たとえば heroku ps​ に crashed​ 状態が表示されるなど、Heroku にデプロイされたアプリがクラッシュした場合は、アプリのログを確認します。次のセクションでは、アプリのクラッシュの一般的な原因について説明します。

開発またはテスト gem でのランタイムの依存関係

デプロイ中に gem が存在しない場合は、Bundler グループをチェックしてください。Heroku では、アプリが development​ または test​ グループなしでビルドされ、アプリの実行をこれらのいずれかのグループの gem に依存している場合は、それをグループから除外します。

一般的な例として、Rakefile​ での RSpec タスクの使用があります。このエラーは多くの場合、次のようになります。

$ heroku run rake -T
Running `bundle exec rake -T` attached to terminal... up, ps.3
rake aborted!
no such file to load -- rspec/core/rake_task

まず、開発またはテスト gem グループなしで bundle install​ を実行して、問題をローカルに複製します。

$ bundle install --without development:test
…
$ bundle exec rake -T
rake aborted!
no such file to load -- rspec/core/rake_task

bundler​ の --without​ オプションは永続的です。このオプションを削除するには、bundle config --delete without​ を実行します。

これらの Rake タスクを gem のロード中に条件付きにすることによってエラーを解決します。次に例を示します。

begin
  require "rspec/core/rake_task"

  desc "Run all examples"

  RSpec::Core::RakeTask.new(:spec) do |t|
    t.rspec_opts = %w[--color]
    t.pattern = 'spec/**/*_spec.rb'
  end
rescue LoadError
end

これがローカルで動作することを確認してから、Heroku にプッシュします。

次のステップ

Rails 7 アプリケーションをデプロイできました。調査を継続するには、次に、以下の記事を確認してください。

  • 「Ruby サポートカテゴリ​」では、Heroku での Ruby および Rails の使用に関する詳細を確認できます。
  • 「デプロイカテゴリ​」では、デプロイを効率的かつ簡単に行うことができるようにする、多くの強力な統合や機能を紹介しています。

コストを抑制するために、チュートリアルを完了したらすぐにサンプルアプリを削除​し、データベースも削除​してください。

アプリとアドオンを削除する

アカウントからアプリとデータベースを削除します。使用したリソースに対してのみ課金されます。

この操作により、アドオンとデータベースに保存されたすべてのデータが削除されます。

$ heroku addons:destroy heroku-postgresql

この操作により、アプリケーションが完全に削除されます。

$ heroku apps:destroy

以下のコマンドによって、アドオンとアプリが消去されたことを確認できます。

$ heroku addons --all
$ heroku apps --all

これで、​アプリをデプロイする​準備ができました。

関連カテゴリー

  • Rails のサポート
Unicorn を使用した Rails アプリケーションのデプロイ JRuby 上で実行するための既存の Rails アプリの移動

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices