Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom file location #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zeevallin
Copy link

Possibly solves or replaces #78

Say your deployment process require you to have your configuration at a certain file path or that you want to provide defaults for different platforms in development.
You can achieve this by using an environment variable to tell Figaro where to look for your yaml file.

$ docker run -e FIGARO_PATH=./config/application.docker.yml my-container rails s
$ FIGARO_PATH=/storage_device/configuration/my_app_variables.yml rails s

If you're not using rails or if you want to determine the file path by other means, set the Figaro.adapter.path to your desired value.

require "figaro"
Figaro.adapter.path = "/my/config/file.yml"
Figaro.load

Now you can get your environment variables using environment variables

Infinity
Yo dawg

…onfiguration YAML

- Only works in the context of rails
- It takes precedence over the default `config/application.yml`
- Add README and include other examples of how you can customise your file path
@zeevallin
Copy link
Author

Not sure why this caused the travis build to 🔴 fail for rails 3.2 on ruby 1.9.3 since it's not even related code. Is this a bug caused by something else?

@laserlemon
Copy link
Owner

Restarting that particular job. Recently, the suite has been experiencing some intermittent failures and I haven't had the chance to get to the bottom of it yet. 😢 🐼

@zeevallin
Copy link
Author

@laserlemon Ah, cool, looks like they all pass now! Wohoo!

@laserlemon
Copy link
Owner

I have a few suggestions and concerns. First, let's call the variable FIGARO_PATH.

Next, I think this feature would be more useful if the user could specify any path on the server, not just a path within Rails.root. But if that's the case, how would one easily specify a relative path within Rails.root? Would it even be necessary to supply a relative path, or will most (all?) deployment setups at least symlink the deployment to a predictable location such as /app/foobarapp/current so that an absolute path would suffice?

@zeevallin
Copy link
Author

@laserlemon I like the idea of FIGARO_PATH, more succinct. I'll make another commit.

As for your concern. Joining an absolute path with Rails.root will return the absolute path. There's already a test for this in the figaro/rails/application_spec.rb

As for my rationale. I ran in to issues and came up with this feature trying to support defaults for different environments on different platforms in development.

For OS X defaults I would like something like this:

# config/application.osx+brew.yml
development: &defaults
  database_url: postgres://app@localhost:5432/dev?template=template0&pool=5&encoding=unicode
  redis_url: redis://localhost:6379/0
test:
  <<: *defaults
  database_url: postgres://app@localhost:5432/test?template=template0&pool=5&encoding=unicode
  redis_url: redis://localhost:6379/0

While something like docker + fig gives me /etc/hosts records in my application container using dockers internal network to communicate with the dependent service containers. In this case it would be cool if my defaults looked something like this:

# config/application.fig+docker.yml
development: &defaults
  database_url: postgres://app@postgres:5432/dev?template=template0&pool=5&encoding=unicode
  redis_url: redis://redis:6379/0
test:
  <<: *defaults
  database_url: postgres://app@postgres:5432/test?template=template0&pool=5&encoding=unicode
  redis_url: redis://redis:6379/0

@zeevallin
Copy link
Author

@laserlemon Does this replace #78 or do you want to take another direction altogether?

@zeevallin
Copy link
Author

@laserlemon What are your thoughts?

@jbussdieker
Copy link

This patch looks familiar :trollface:

@zeevallin
Copy link
Author

@jbussdieker Haha, yeah sorry. I didn't realise until long after submitting this pull request. Kind of jumped the gun.

@dgmstuart
Copy link

@laserlemon Any thoughts on whether this (or #78) is likely to get merged?

@carltonbrown
Copy link

+1 This fix is exactly what I was looking for, could someone please merge ???

@dgmstuart
Copy link

@carltonbrown Unfortunately Figaro seems to have been unmaintained for several years. Personally I've found https://github.com/bkeepers/dotenv works well as a replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants