Skip to main content
This guide deploys a Rails application served by Puma, with a PostgreSQL database and migrations that run before each release. Qovery builds the image from your Dockerfile and runs it on a Kubernetes cluster in your own cloud account.
No configuration file in your repository. Qovery does not read a qovery.yml, .qovery.yml or .qovery.toml, and there is no qovery init. Projects, environments and services are created in the Console, with qovery api, or with Terraform. For the full path from a repository to a running app with commands only, see Deploy with the CLI and API.

Prerequisites

Add a production Dockerfile

rails new generates a production Dockerfile since Rails 7.1. You can keep it (see the port note), or use this shorter one at the root of the repository:
Dockerfile
  • ruby:3.4-slim is the official Ruby image without build tools. Match the version to your .ruby-version. It installs libpq5, the PostgreSQL client library that the pg gem loads at runtime.
  • The build stage has the compilers and headers that native gems such as pg need. The final stage copies only the installed gems and the application, so the image stays small.
  • BUNDLE_WITHOUT=development:test leaves out the gems you do not need in production.
  • SECRET_KEY_BASE_DUMMY=1 lets assets:precompile run at build time without the real secret.
  • The container runs as a non-root user that owns db, log, storage and tmp, the folders Rails writes to.
  • Puma binds to 0.0.0.0, not localhost, so Kubernetes can reach it.

Port and health check

The application listens on port 3000. Rails 7.1 and later add a GET /up route that answers 200 when the application boots, so use it as the health check path. The Dockerfile that Rails 8 generates starts Puma behind Thruster on port 80. If you keep it, set the port to 80 in Qovery instead of 3000. If you set config.hosts in config/environments/production.rb, exclude the health check from host authorization, because Kubernetes probes call the pod by its IP address:
config/environments/production.rb

Connect PostgreSQL

The application and the migration job read the connection string from DATABASE_URL. Create PostgreSQL, then expose its connection string under that name at the environment scope, so every service of the environment gets it.
  1. In the environment, click New Service and pick PostgreSQL. Keep the visibility private, then create and deploy it. See Create a Database.
  2. Open the Variables section of the environment, find the built-in variable QOVERY_POSTGRESQL_Z<ID>_DATABASE_URL_INTERNAL, select Create alias, and name it DATABASE_URL.
From the CLI, once the application exists:
This database runs as a container on your cluster, with no automated backups. Use it for development and testing.
See Aliases and Variable Interpolation for the rules. Rails reads DATABASE_URL and merges it into the production entry of config/database.yml. If that entry also declares cache, queue and cable databases (the Rails 8 default for Solid Cache, Solid Queue and Solid Cable), give each one a database it can reach on the same server, or remove the ones you do not use.

Set the variables

Run the migrations

Run db:migrate in a lifecycle job built from the same repository and Dockerfile, triggered on the Deploy event, with these CMD arguments:
The job runs once per deployment. In the default deployment pipeline, jobs run after the databases and before the applications, so the schema is up to date when the new code starts. The job needs DATABASE_URL and RAILS_MASTER_KEY too: create them at the environment scope. The Dockerfile that Rails generates also runs db:prepare in bin/docker-entrypoint when the server starts. This works for a single instance. With several instances, each one runs it at boot, so prefer the job.

Deploy

1

Create a project and an environment

Follow steps 1 and 2 of Deploy Your First Application. Pick the cluster the environment runs on.
2

Add PostgreSQL

Create the database and the DATABASE_URL variable as described in Connect PostgreSQL.
3

Create the application

In the environment, click New Service › Create application, select Git Repository, then your repository and branch. Leave Root Application Path empty unless the Dockerfile is in a subfolder.
4

Set the port

Add port 3000 with the protocol HTTP, and turn on Publicly Accessible. Qovery serves it over HTTPS on port 443.
5

Set the health checks

Set the readiness and liveness probes to type HTTP, path /up, port 3000. See Service Health Checks.
6

Add the variables

Click Create, without deploying yet. Then open the Variables section of the environment and add the other variables listed in Set the variables at the environment scope, so the migration job gets them too. DATABASE_URL already exists from the previous step. Mark keys and passwords as secrets.
7

Create the migration job

Click New Service › Create lifecycle job, select the same repository, branch and Dockerfile, and trigger it on the Deploy event (START) with the CMD arguments ["./bin/rails", "db:migrate"]. Set the number of restarts to 0. See Run the migrations.
8

Deploy

Deploy the environment. Qovery deploys the database, then the job, then the application, builds the image from your Dockerfile and gives the application a URL on qovery.io. Follow the progress in the Deployment logs tab.

Troubleshooting

The CLI commands below use the organization and project selected with qovery context set. Run it first, or add --organization and --project to each command.
The port in Qovery does not match the server: 3000 for Puma, 80 with Thruster in the Rails 8 Dockerfile. Check that Puma binds to 0.0.0.0. Read the error lines with qovery environment deployment logs --environment "<env>" --service "<app>" --errors-only.
config.hosts does not include the domain. Set APP_HOST to the qovery.io domain shown in the Console, add your custom domains, and keep /up excluded from host authorization.
RAILS_MASTER_KEY is missing or does not match config/credentials.yml.enc. Set it as a secret at the environment scope, so the application and the migration job both get it.
The migrations did not run against this database. Check that the job and the application read the same DATABASE_URL, and read the job output with qovery log --job "<job name>".
assets:precompile did not run at build time, or config.public_file_server.enabled is false in production. Rails 7.1 and later serve public/ by default; an application generated with an older version may still read RAILS_SERVE_STATIC_FILES in config/environments/production.rb, so set that variable to 1 or remove the condition. Check the build logs for the precompile step.
For other errors, see Diagnose a Failed Build or Deployment.

Next steps

Preview environments

Get a full copy of the environment for each pull request

Cron jobs

Run rake tasks on a schedule

Auto deploy

Deploy on every push to the branch

Other frameworks

All framework guides