Tutorial: Deploy a Rails app
Last updated 1 min read
Report issueOverview#
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#
- Create a scope for your application:
BASH gritivactl scope create rails-app --cpu 2 --mem 4G
Step 2: Configure the Application#
- Create a
docker-compose.ymlfile 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#
-
Bring up the application:
BASH gritivactl scope exec rails-app -- docker compose up -d -
Run migrations:
BASH gritivactl scope exec rails-app -- docker compose exec web rails db:migrate -
Attach your domain:
BASH gritivactl domain add app.example.com --scope rails-app --port 3000 -
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.
- Ensure
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 NotesEnsure you follow the steps exactly as outlined to avoid common pitfalls.