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

Add support for templating environment variables. #20

Merged
merged 6 commits into from
May 20, 2021

Conversation

fitzy101
Copy link
Contributor

This adds support for enabling environment variable templating into pups. The PR is for initial thoughts, let me know what you think.

@config["env_template"]&.each do |k,v|
ENV.each do |key, val|
if val =~ /\{\{#{k}\}\}/
transformed_env_vars[key] = val.gsub("{{#{k}}}", v)
Copy link
Member

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.

transformed_env_vars = {}
@config["env_template"]&.each do |k,v|
ENV.each do |key, val|
if val =~ /\{\{#{k}\}\}/
Copy link
Member

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.

transformed_env_vars[key] = val.gsub("{{#{k}}}", v)
end
end
ENV.replace(ENV.to_hash.merge(transformed_env_vars))
Copy link
Member

@SamSaffron SamSaffron Apr 12, 2021

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 ?

@fitzy101
Copy link
Contributor Author

@SamSaffron I've pushed up a change to fix based on your comments

@fitzy101 fitzy101 marked this pull request as ready for review May 19, 2021 04:17
@fitzy101 fitzy101 changed the title DRAFT: add support for templating environment variables. Add support for templating environment variables. May 19, 2021
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.
@fitzy101 fitzy101 force-pushed the revert-revert-app-env-support branch from 3b7f09f to 91d27ed Compare May 19, 2021 22:47
@@ -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
Copy link
Member

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.

@SamSaffron
Copy link
Member

Change looks great, just clean up the indenting and we are good to go.

@fitzy101 fitzy101 merged commit 17f04ec into master May 20, 2021
@fitzy101 fitzy101 deleted the revert-revert-app-env-support branch May 20, 2021 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants