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

[hab-director] per-service environment variables #1075

Merged
merged 1 commit into from
Jul 18, 2016
Merged

Conversation

bookshelfdave
Copy link
Contributor

Services can provide environment variables in the form of a TOML table which follows the following format:

[services.<origin>.<name>.<group>.<organization>.env]
ENV1="some value"
ENV2="some other value" 

Note: Environment variables MUST be specified as valid TOML strings.

For example:

# Specify custom JAVA_HOME and CLASSPATH environment variables
[services.core.java_app.somegroup.someorg]
start = "--permanent-peer"
[services.core.java_app.somegroup.someorg.env]
JAVA_HOME="/some/path/"
CLASSPATH="/some/classpath/foo.jar"

[services.core.rngd.foo.someorg]
start = "--permanent-peer --foo=bar"
JAVA_HOME="/a/different/path/"
# we don't specify CLASSPATH here, so it won't be set for core/rngd

Note: We current don't support "global" environment variables that are shared between services. This is definitely doable, but not in this PR.

for you @smith 🍰

@thesentinels
Copy link
Contributor

@metadave, thanks for your PR! By analyzing the annotation information on this pull request, we identified @adamhjk, @davidwrede, @leonhartX and @fnichol to be potential reviewers

@@ -98,23 +99,61 @@ impl Config {
fn lookup_service_param(toml: &toml::Value,
service_name: &str,
param_name: &str)
-> Option<String> {
-> Result<Option<String>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This funciton never returns an Err case so just using Option is fine here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I gave it the same return type as the new function I added for consistency.

On Jul 18, 2016, at 1:33 PM, Jamie Winsor [email protected] wrote:

In components/director/src/config.rs:

@@ -98,23 +99,61 @@ impl Config {
fn lookup_service_param(toml: &toml::Value,
service_name: &str,
param_name: &str)

  •                        -> Option<String> {
    
  •                        -> Result<Option<String>> {
    
    This funciton never returns an Err case so just using Option is fine here


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lookup_service_param() has been updated to only accept string types, which makes the Result<Option<String>> the correct return type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@reset
Copy link
Collaborator

reset commented Jul 18, 2016

@metadave one minor comment but everything else looks like a great addition. Thanks for updating the docs!

gif-keyboard-5622189816808110834

allow director service defs to specify a child "env" table

Signed-off-by: Dave Parfitt <[email protected]>
@reset reset merged commit 40f0cc6 into master Jul 18, 2016
@reset reset deleted the dp_director_env branch July 18, 2016 21:10

[services.core.rngd.foo.someorg]
start = "--permanent-peer --foo=bar"
JAVA_HOME="/a/different/path/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be under a .env key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, will push in a different PR

@smith
Copy link
Contributor

smith commented Jul 18, 2016

I think this is probably a good addition, but we still have some work to do with handling environment variables.

This solution only works for the director, at runtime, with totally static data. If I need to set, say something like SSL_CERT_DIR=$(hab pkg path core/cacerts)/ssl/certs, I can't do it in the config here without hard-coding a specific version/release of cacerts.

The situations I can think of that we should be able to handle are:

  • Specifying env vars at build time that will be loaded with hab pkg exec and hab sup start
  • Specifying env vars that can be templated at run time in a hook.

You can do both of these pretty easily right now if you specify a run hook, but it might be nicer to have something available that you can use if you're just doing pkg_svc_run.

These are just considerations for building the features out. Your PR is fine and we can flesh out the other pieces later. Thanks!

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