Use variable substitution in .env.production

Hi all,

I have a question about .env variables. I have the main .env.production and then I have different .env* files to supply to Docker. I have one for each deployment. Consequently I now need to change or keep different .env.production files for different deployments.

Is it possible to use variable substitution in the .env.production? I guess it could be done, at least it’s mentioned on the dotenv gem page, but when I do this:


the variables are not substituted. Can I achieve this?

Best, seba

Yes, this is how I observe it working. Are you using an old version of dotenv?

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/inline'

gemfile do
  source ''
  gem 'dotenv'
  gem 'hanami', '~> 1.3'

require 'hanami/env''env-test', 'w') do |f|
  f.write "FOO=bar\n"
  f.write "BAR=foo-${FOO}"

env = {})

puts env.inspect
$ ./dotenv.rb
#<Hanami::Env:0x00007faedf902c08 @env={"FOO"=>"bar", "BAR"=>"foo-bar"}>