-
Notifications
You must be signed in to change notification settings - Fork 86
Using ENV variables in config
Lloyd Philbrook edited this page Mar 30, 2015
·
2 revisions
Some people love to use ENV to pass dynamic variables to the eye config, but this is not a good approach.
For example:
Eye.app :some do
working_dir "/project1"
(ENV['WORKERS'] || 5).to_i.times do |i|
process "worker-#{i}" do
# ...
end
end
end
When you call eye for the first time. Let's say you start eye with: WORKERS=10 eye load config.eye
, and than call it again with: WORKERS=15 eye load config.eye
. The workers count will not change because the eye server started with local ENV variables during the first eye load
. Any subsequent load command
just reevaluates the config on the server and does not reload the ENV variables.
How to solve this:
Use configs (yml for example), which updated for example by capistrano or something.
Eye.app :some do
working_dir "/project1"
config = YAML.load_file(File.join(self.working_dir, %w{config config.yml}))
workers_count = config[:workers_count] || 5
workers_count.times do |i|
process "worker-#{i}" do
# ...
end
end
end
- Write all env variables by hand in the eye config.
Eye.app :some do
env 'A' => 'B', 'C' => 'D'
end
- Use a dotenv file:
Eye.app :some do
working_dir "/project1/"
load_env ".env"
end
This will load env variables from file /project1/.env (on every load)
/project1/.env
A=1
B=2
C=SOMETHING
to load the dotenv file in bash
export $(cat /project1/.env | xargs)
- you can place env variables in some other place, like a .yml file and load it by hand
Eye.app :some do
YAML.load_file("some_file").each do |k, v|
env k => v
end
end