LoginSignup
0
1

More than 1 year has passed since last update.

【Ruby on Rails】デプロイ手順

Last updated at Posted at 2022-11-17

Gemを追加

Gemfile
group :production do
  gem 'pg'
end
ターミナル
bundle install

デプロイ用の設定ファイルを追加

① binフォルダに、render-build.shという名称でファイルを新規作成する。
② 作成したファイルに、以下の記述を追加する。

bin/render-build.sh
#!/usr/bin/env bash
# exit on error
set -o errexit

bundle install
bundle exec rake assets:precompile
bundle exec rake assets:clean
bundle exec rake db:migrate

database.ymlの設定を変更

このように変更することで、開発環境およびテスト環境ではMySQLが、本番環境ではPostgreSQLが使用されるようになる。

config/database.yml
default: &default
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  adapter: mysql2
  username: root
  password:
  host: localhost
  database: アプリケーション名_development

test:
  <<: *default
  adapter: mysql2
  username: root
  password:
  host: localhost
  database: アプリケーション名_test

production:
  <<: *default
  adapter: postgresql
  url: <%= ENV['DATABASE_URL'] %>

Gemfile.lockの設定を変更

ターミナル
bundle lock --add-platform x86_64-linux

秘密情報管理用ファイルを作成

ターミナル
EDITOR="vi" bin/rails credentials:edit

「escキー」→「:」→「q」と入力し、「enterキー」を押下。

Renderで「Web Service」作成時に入力する項目

入力欄 入力内容
Build Command ./bin/render-build.sh
Start Command bundle exec puma -C config/puma.rb

Renderで「Add Environment Variable」に追記する項目

入力欄        入力内容
RAILS_MASTER_KEY configフォルダにある「master.key」
DATABASE_URL         自身のRenderのDashboardの「Internal Database URL」

#techcamp136期

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1