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:

DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/my_db"

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 'https://rubygems.org'
  gem 'dotenv'
  gem 'hanami', '~> 1.3'
end

require 'hanami/env'

File.open('env-test', 'w') do |f|
  f.write "FOO=bar\n"
  f.write "BAR=foo-${FOO}"
end

env = Hanami::Env.new(env: {})
env.load!('env-test')

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