From efe21b27cdfda27f9edb5a839bb1a6b65e1dcfec Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 20 Dec 2016 10:41:45 -0800 Subject: [PATCH] Allow configuration to be defined in an ENV var If `ENV['VMPOOLER_CONFIG']` is defined, it is read in as a YAML configuration. This allows vmpooler to run in a docker daemon via `docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler` rather than embedding a YAML file within the container. --- lib/vmpooler.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 0e5707c..844aa6e 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -21,11 +21,18 @@ module Vmpooler end def self.config(filepath='vmpooler.yaml') - # Load the configuration file - config_file = File.expand_path(filepath) - parsed_config = YAML.load_file(config_file) + parsed_config = {} - # Set some defaults + if ENV['VMPOOLER_CONFIG'] + # Load configuration from ENV + parsed_config = YAML.load(ENV['VMPOOLER_CONFIG']) + else + # Load the configuration file from disk + config_file = File.expand_path(filepath) + parsed_config = YAML.load_file(config_file) + end + + # Set some configuration defaults parsed_config[:redis] ||= {} parsed_config[:redis]['server'] ||= 'localhost' parsed_config[:redis]['data_ttl'] ||= 168