1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Rails】render.comを使ってデプロイする

Posted at
1 / 2

概要

  • render.comを使用して、アプリケーションをデプロイする
  • 無料プランを利用&クレジットカードの登録は行ない

開発環境

  • OS:MacOS(m1チップ)
  • 言語:ruby 3.1.2
  • フレームワーク:Ruby on Rails7.0.2
  • DB:PostgreSQL(←要注意:詳細後述)
  • Docker等のコンテナは使わず、PCのローカル環境に構築

本番環境(production環境)を用意する

Gemfile
group :production do
  gem "pg"
end

ここで注意が必要
gem "pg"はPostgreSQLを使用するために導入(筆者はsqliteを使用していた)
render.comはデータベースをPostgreSQLしかサポートしていないため、
MySQLやSQLite等を使用している場合は、本番環境のデータベースのみPostgreSQLnに変更する必要がある

gemをインストールする

bundle install

render.yamlの作成

以下を参考に作成してみてください

render.yaml
databases:
  - name: lunch_bot_production
    databaseName: lunch_bot_production
    user: lunch_bot
    region: singapore
    plan: free

services:
  - type: web
    name: lunch_bot_production
    env: ruby
    region: singapore
    plan: free
    buildCommand: "./bin/render-build.sh"
    startCommand: "bundle exec puma -C config/puma.rb"
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: lunch_bot_production
          property: connectionString
      - key: RAILS_MASTER_KEY
        sync: false

regionはsingaporeを指定します(日本から一番近い拠点)

databaseとserviceどちらにもplan:freeを必ず指定してください。

render.comの設定を進める

render.comのアカウントを作成する

  • render.comの公式ページからアカウントの作成を行なってください。

公式のドキュメントに沿って進めていく

  • 公式ドキュメントの通りに進めれば問題ありません。
    ※今回はRuby on Railsで作ったアプリのデプロイです。様々なフレームワークに対応した公式ドキュメントが用意されているようですので、開発環境に合わせて読み替えてください。

デプロイを確認する

  • デプロイボタン押下に生成されたURLをクリックしてデプロイされているか確認してください。
  • freeプランの場合、デプロイおよびURLをクリックした後の表示に少々時間がかかります(約3分)

まとめ

  • 公式のドキュメントに沿って進めていけば簡単にデプロイができた
  • 無料&クレジットカードの登録を行いたくない場合は、render.ymlにplanを明示する
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?