Languages

Envlet for Elixir

Envlet.inject! sets the process environment from one token. Nothing outside OTP.

Hexenvlet

Set up

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

  1. 01

    Install

    One Hex package. Phoenix and plain releases.

    mix.exs
    def deps do
      [
        {:envlet, "~> 0.1.0"}
      ]
    end
  2. 02

    Set one secret

    ENVLET_TOKEN in the release environment.

    Elixir / 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

    Call Envlet.inject! in your release config provider or at the top of the application start.

    config/runtime.exs
    Envlet.inject!()
    
    stripe_key = System.fetch_env!("STRIPE_KEY")

Three calls

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

Envlet.inject!()

stripe_key = System.fetch_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.ex
# Generated by envlet types for the "production" environment.

defmodule EnvletEnv do
  defstruct [:database_url, :debug, :flags, :mode, :port, :stripe_key]

  @type t :: %__MODULE__{
          database_url: String.t(),
          debug: boolean(),
          flags: term() | nil,
          mode: String.t(),
          port: integer(),
          stripe_key: String.t(),
        }

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 Elixir 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.