Tutorial: Deploy a Rails app

Last updated 3 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.
  • For the scripted checks below, an API key created in the panel under SET. → API keys, exported as GRITIVA_API_KEY.

Deployment Steps#

Step 1: Prepare the Environment#

  1. Create a scope for your application. In the panel at gritiva.com, open INFRA → Scopes → New scope and fill in:

    • Name: rails-app
    • VM: the machine you enrolled
    • CPU / memory: 2 vCPU, 4 GB
    • Isolation: medium (choices are minimal, medium, high, maximum)
    • Network mode: bridge (choices are bridge, host, isolated, shared, mesh)

    The scope moves through creating → starting → running. Confirm it landed and note its id:

    BASH
    curl -s -H "X-API-Key: $GRITIVA_API_KEY" \
      https://api.gritiva.com/api/v1/scopes

    The same operation is scriptable as POST /api/v1/scopes; the panel form is the reference for the fields it expects.

Step 2: Configure the Application#

  1. Open a shell on the VM — click the VM in the panel and choose Open Terminal, or SSH in — put a checkout of your app in /srv/rails-app, and create /srv/rails-app/docker-compose.yml:
    YAML
    version: '3.8'
    services:
      web:
        build: .
        ports:
          - '3000:3000'
      db:
        image: postgres:16
        environment:
          POSTGRES_PASSWORD: example
      redis:
        image: redis

Step 3: Deploy the Application#

  1. Bring up the application from that same shell:

    BASH
    cd /srv/rails-app
    docker compose up -d
  2. Run migrations:

    BASH
    docker compose exec web bin/rails db:migrate
  3. Attach your domain in the panel: DOMAINS → Add domain, enter app.example.com, then bind it to the rails-app scope on port 3000 under Service domains. Gritiva provisions the Cloudflare DNS record, the tunnel route and the certificate. Verify:

    BASH
    curl -s -H "X-API-Key: $GRITIVA_API_KEY" \
      https://api.gritiva.com/api/v1/domains/me
    curl -s -H "X-API-Key: $GRITIVA_API_KEY" \
      https://api.gritiva.com/api/v1/service-domains
  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.
    • If the scope shows health unhealthy or degraded in the panel, the problem is below your app — check the agent before the container.

Post-Deployment Verification#

  • Check logs and shell access from a shell on the VM:
    BASH
    cd /srv/rails-app
    docker compose logs -f web
    docker compose exec web bin/rails console
  • If the scope itself looks wrong rather than the app:
    BASH
    sudo /opt/gritiva/gritiva-agent scope-status
    journalctl -u gritiva-agent -f

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.