Ruby

Learn how to use Doppler with Ruby applications

We don't have a Ruby SDK available yet, but if you'd like to be notified when it's available, please reach out to us at [email protected].

In the meantime, information about how to work with Doppler in Ruby applications can be found below!

doppler-env Gem

The doppler-env gem automates the injection of Doppler secrets as environment variables into any Ruby application.

🚧

This is not meant to be used in production deployments. For production deployments, we recommend using our Integrations or our standard run methods for Docker and CLI.

Setup

Ensure you have installed the Doppler CLI locally and have created a Doppler Project. Then authorize the Doppler CLI to retrieve secrets from your workplace by running:

doppler login

Then add doppler-env to your Bundler Gemfile:

gem "doppler-env"

Configuration

Rails

For Rails applications, all you need to do is require doppler-env in your config/environments/development.rb file:

require "doppler-env/load"

Make sure it's the first require in that file.

General

First, require doppler-env in your project. Make sure it's required and loaded before any other libraries. To do this you can require the library and manually call Doppler.load:

# will cause your Doppler secrets to get injected into ENV for your application,
# but will not override any pre-existing ENV variables.
require "doppler-env"
DopplerEnv.load

or

require "doppler-env/load"

You can also force it to override pre-existing ENV variables with:

require "doppler-env"
DopplerEnv.load!

After you have the library loading in your application, you need to configure which secrets to fetch for your application by either using the CLI in the root directory of your application:

doppler setup

or by setting the DOPPLER_PROJECT and DOPPLER_CONFIG environment variables in the context you're executing in.

Now your secrets will get injected into your application at runtime:

ruby app.rb

[doppler-env]: DOPPLER_ENV environment variable set. Fetching secrets using Doppler CLI.
[doppler-env]: Secrets loaded successfully:
[doppler-env]:   {"DOPPLER_CONFIG"=>"dev", "DOPPLER_ENVIRONMENT"=>"dev", "DOPPLER_PROJECT"=>"example"}

In restrictive environments where the use of the Doppler CLI isn't possible, set a DOPPLER_TOKEN environment variable with a Service Token to fetch secrets directly from the Doppler API:

ruby app.rb

[doppler-env]: DOPPLER_TOKEN environment variable set. Fetching secrets from Doppler API.
[doppler-env]: Secrets loaded successfully:
[doppler-env]:   {"DOPPLER_CONFIG"=>"dev", "DOPPLER_ENVIRONMENT"=>"dev", "DOPPLER_PROJECT"=>"example"}