-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add support for templating environment variables. #20
Conversation
lib/pups/config.rb
Outdated
@config["env_template"]&.each do |k,v| | ||
ENV.each do |key, val| | ||
if val =~ /\{\{#{k}\}\}/ | ||
transformed_env_vars[key] = val.gsub("{{#{k}}}", v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v.to_s ... cause it could be a number.
lib/pups/config.rb
Outdated
transformed_env_vars = {} | ||
@config["env_template"]&.each do |k,v| | ||
ENV.each do |key, val| | ||
if val =~ /\{\{#{k}\}\}/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val.include?("{{#{k}}}") ... no need for a regex here.
lib/pups/config.rb
Outdated
transformed_env_vars[key] = val.gsub("{{#{k}}}", v) | ||
end | ||
end | ||
ENV.replace(ENV.to_hash.merge(transformed_env_vars)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full replace may be a bit too much I would just fix ENV as we go ?
@SamSaffron I've pushed up a change to fix based on your comments |
This reverts commit 05db637.
Templated variables can be used to parameterise container creation. This will ensure any ENV variables are templated during config initialisation prior to any use.
There are situations where we want to provide and config template at runtime rather than ahead-of-time. This adds support for specifying such a variable via the process environment, prefixed with env_template_<name>=value.
3b7f09f
to
91d27ed
Compare
test/config_test.rb
Outdated
@@ -10,16 +10,74 @@ def test_config_from_env | |||
assert_equal("world", config.params["$ENV_HELLO"]) | |||
end | |||
|
|||
def test_env_param | |||
ENV["FOO"] = "BAR" | |||
config = <<YAML |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor... use <<~
then you don't need the odd indenting.
Change looks great, just clean up the indenting and we are good to go. |
This adds support for enabling environment variable templating into pups. The PR is for initial thoughts, let me know what you think.