Languages

Envlet for Ruby

Envlet.inject fills ENV before Rails or Sinatra boots. One gem, nothing else.

RubyGemsenvlet

Set up

Three steps. The host keeps one secret and everything else arrives at boot.

  1. 01

    Install

    One gem. Rails, Sinatra, and plain scripts.

    Terminal
    gem install envlet
  2. 02

    Set one secret

    ENVLET_TOKEN in the process environment.

    Ruby / production / environment variables
    ENVLET_TOKENenvlet_••••••••the only secret the host keeps
    DATABASE_URL••••••••moved to Envlet
    STRIPE_KEY••••••••moved to Envlet
    SENTRY_DSN••••••••moved to Envlet
  3. 03

    Inject at boot

    Require envlet and call Envlet.inject at the top of config/boot.rb or your entrypoint.

    config/boot.rb
    require "envlet"
    
    Envlet.inject
    
    Stripe.api_key = ENV["STRIPE_KEY"]

Three calls

inject for most apps. load when you want a map. get when you want one value.

require "envlet"

Envlet.inject

Stripe.api_key = ENV["STRIPE_KEY"]

Typed

envlet types writes this file from the variables in your environment, with a load() that fills the shape below. Run it with --check in CI and a renamed variable fails the build.

Terminal
envlet types
envlet types --check
envlet_env.rb
# Generated by envlet types for the "production" environment.

require "envlet"

ENV_SCHEMA = {
    "DATABASE_URL" => { type: :url, required: true },
    "DEBUG" => { type: :boolean, required: true },
    "FLAGS" => { type: :json, required: false },
    "MODE" => { type: :enum, required: true, allowed: ["dev", "prod"] },
    "PORT" => { type: :integer, required: true },
    "STRIPE_KEY" => { type: :string, required: true },
}.freeze

Env = Struct.new(
  :database_url,
  :debug,
  :flags,
  :mode,
  :port,
  :stripe_key,
  keyword_init: true,
) do

Questions

Will my app start if Envlet is down?

No. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.

What does the host need?

One variable, ENVLET_TOKEN. Everything else arrives at boot.

Can I still set some values on the Ruby host?

Yes. A value the host already set wins. Pass override if you want Envlet to win instead.

Stop pasting .env files.

One command. The right values for whoever runs it.