Tutorial: Deploy a Rails app
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#
-
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 areminimal,medium,high,maximum) - Network mode:
bridge(choices arebridge,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/scopesThe same operation is scriptable as
POST /api/v1/scopes; the panel form is the reference for the fields it expects. - Name:
Step 2: Configure the Application#
- 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#
-
Bring up the application from that same shell:
BASH cd /srv/rails-app docker compose up -d -
Run migrations:
BASH docker compose exec web bin/rails db:migrate -
Attach your domain in the panel: DOMAINS → Add domain, enter
app.example.com, then bind it to therails-appscope 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 -
Verify the deployment:
BASH curl https://app.example.com/upA response of
200indicates success.
Troubleshooting#
- Common pitfalls include:
- Ensure
RAILS_ENVis set to production. - Asset compilation should be handled at build time, not in the entrypoint.
- Verify the
secret_key_baseis correctly configured. - If the scope shows health
unhealthyordegradedin the panel, the problem is below your app — check the agent before the container.
- Ensure
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 NotesEnsure you follow the steps exactly as outlined to avoid common pitfalls.