Closed belgoros closed 6 years ago
When reading Docker For Rails developers, I got an issue when the database secrets were defined in env files:
#.env/development/database POSTGRES_USER=postgres POSTGRES_PASSWORD= POSTGRES_DB=myapp_development
In a docker-compose.yml this file is referenced:
docker-compose.yml
... env_file: - .env/development/database - .env/development/web ...
and its values are fetched in a Rails app database.yml file as follows:
database.yml
default: &default adapter: postgresql encoding: unicode host: <%= ENV.fetch['DATABASE_HOST'] %> username: <%= ENV.fetch['POSTGRES_USER'] %> database: <%= ENV.fetch['POSTGRES_DB'] %> pool: 5 variables: statement_timeout: 5000 development: <<: *default ...
It seems like it comes in conflict with the Figaro way to use ENV variable. If I drop fetch:
ENV
fetch
default: &default adapter: postgresql encoding: unicode host: <%= ENV['DATABASE_HOST'] %> username: <%= ENV['POSTGRES_USER'] %> database: <%= ENV['POSTGRES_DB'] %> pool: 5 variables: statement_timeout: 5000 development: <<: *default ...
it works on macOS but fails on a Linux machine:
rails aborted! ArgumentError: Cannot load `Rails.application.database_configuration`: wrong number of arguments (given 0, expected 1..2) (erb):4:in `fetch' (erb):4:in `<main>' ...
NOTE: I have no values defined in my application.yml file for DATABASE_HOST, POSTGRES_USER, POSTGRES_DB keys.
application.yml
DATABASE_HOST
POSTGRES_USER
POSTGRES_DB
So the question is what is right way to do that ? Thank you.
Figaro version: 1.1.1.
1.1.1.
My bad, I figured out what was the error, - wrong syntax:
ENV.fetch['DATABASE_HOST']
should be
ENV.fetch('DATABASE_HOST', 'some_defaut_value_if_not_found')
When reading Docker For Rails developers, I got an issue when the database secrets were defined in env files:
In a
docker-compose.yml
this file is referenced:and its values are fetched in a Rails app
database.yml
file as follows:It seems like it comes in conflict with the Figaro way to use
ENV
variable. If I dropfetch
:it works on macOS but fails on a Linux machine:
NOTE: I have no values defined in my
application.yml
file forDATABASE_HOST
,POSTGRES_USER
,POSTGRES_DB
keys.So the question is what is right way to do that ? Thank you.
Figaro version:
1.1.1.