Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Dynamically load environment variables when using BootstrapFromDocker #60

Merged
merged 7 commits into from Dec 31, 2019
Merged

Conversation

ghost
Copy link

@ghost ghost commented Dec 19, 2019

Currently, I'm doing this to allow us to more easily configure Lighthouse while it's running in a Docker container. (See, petabridge/lighthouse#115). The quick and dirty method would have been to simply carry on with hard coding the environment variable extraction as in the previous version. But I can see the need to configure more and more settings from envvars and it will begin to get tedious at some point. So I've created this small set of classes as a step towards extending the core Akka.NET configuration libraries to support loading from environment variables.

With that in mind, there are a few things that should be noted:

  • I feel this method could be better named (eg. config.FromEnvironment()), but as I've noted there is a possibility of moving this code to the core Akka.NET libraries. So, I'm keeping the name as-is to avoid potential clashes in the future.

  • Because everything happens a bit more dynamically, the logging and output of configuration values to the console has been removed. I think this isn't too bad considering one can easily turn on the Akka.NET feature that prints config on startup.

  • One unit test has been removed where seed nodes where checked against a variable of '[]'. See the respective commit message for more details.

Once this is merged, we can bump the dependency in Lighthouse and start working on the default resolver strategy.

Jonathan Nagy added 3 commits December 19, 2019 15:14
This test implies that you can send through '[]' but
no other tests validate that behavior.  Additionally,
the current bootstrap process will create a value
for this hocon key as '[[]]' which is incorrect.
@claassistantio
Copy link

claassistantio commented Dec 19, 2019

CLA assistant check
All committers have signed the CLA.

Jonathan Nagy added 3 commits December 19, 2019 16:51
Some cases may require us to specify the hostname
on startup (ie. multiple NICs).  And, the previous code
would have blocked environment variables from overriding the value.  So, moving it lower into the
fallback block.
@ghost
Copy link
Author

ghost commented Dec 31, 2019

@Aaronontheweb Can I get a review on this to help close out petabridge/lighthouse#115

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Looks great!

@@ -84,5 +83,27 @@ public void ShouldStartNormallyIfNotEnvironmentVariablesAreSupplied()
myConfig.GetString("akka.remote.dot-netty.tcp.public-hostname").Should().Be(Dns.GetHostName());
myConfig.HasPath("akka.remote.dot-netty.tcp.port").Should().BeFalse();
}

[Fact]
public void ShouldStartIfValidAkkaConfigurationSuppliedByEnvironmentVariables()
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb Aaronontheweb merged commit 64ae1e0 into petabridge:dev Dec 31, 2019
Aaronontheweb added a commit that referenced this pull request Dec 31, 2019
…#60)

* Remove faulty test.

This test implies that you can send through '[]' but
no other tests validate that behavior.  Additionally,
the current bootstrap process will create a value
for this hocon key as '[[]]' which is incorrect.

* Add environment variable configuration loader

* Use environment variable configuration loader in docker bootstrap

* Fix formatting issue when writing entries to hocon

* Add unit test to validate envvar loading

* Move default hostname into fallback

Some cases may require us to specify the hostname
on startup (ie. multiple NICs).  And, the previous code
would have blocked environment variables from overriding the value.  So, moving it lower into the
fallback block.

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
@ghost ghost deleted the feat/envvar-loader branch January 11, 2020 03:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants