Tutorial: Deploy a Rails app

Last updated 1 min read
Report issue

Overview#

This tutorial provides a step-by-step guide for deploying a Ruby on Rails 7.1 application with a PostgreSQL database on GritivaCore. The target audience is Rails developers who are familiar with their applications but new to GritivaCore.

Goal#

The goal is to get a Rails 7.1 app up and running at app.example.com in 15 minutes.

Prerequisites#

  • A virtual machine with the Gritiva agent installed. Refer to the Quick Start Guide.
  • A domain configured at Cloudflare.

Deployment Steps#

Step 1: Prepare the Environment#

  1. Create a scope for your application:
    BASH
    gritivactl scope create rails-app --cpu 2 --mem 4G

Step 2: Configure the Application#

  1. Create a docker-compose.yml file in the scope with the following content:
    YAML
    version: '3.8'
    services:
      web:
        image: ridiculus/rails:7.1
        ports:
          - '3000:3000'
      db:
        image: postgres:16
        environment:
          POSTGRES_PASSWORD: example
      redis:
        image: redis

Step 3: Deploy the Application#

  1. Bring up the application:

    BASH
    gritivactl scope exec rails-app -- docker compose up -d
  2. Run migrations:

    BASH
    gritivactl scope exec rails-app -- docker compose exec web rails db:migrate
  3. Attach your domain:

    BASH
    gritivactl domain add app.example.com --scope rails-app --port 3000
  4. Verify the deployment:

    BASH
    curl https://app.example.com/up

    A response of 200 indicates success.

Troubleshooting#

  • Common pitfalls include:
    • Ensure RAILS_ENV is set to production.
    • Asset compilation should be handled at build time, not in the entrypoint.
    • Verify the secret_key_base is correctly configured.

Post-Deployment Verification#

  • Check logs and shell access:
    BASH
    gritivactl scope exec rails-app -- docker compose logs -f web
    gritivactl scope exec rails-app -- docker compose exec web rails console

Conclusion#

Following these steps will help you successfully deploy your Ruby on Rails application on GritivaCore.

Important Notes

Important Notes
Ensure you follow the steps exactly as outlined to avoid common pitfalls.