Skip to content

Add support for environment variables with custom prefix #24202

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

Closed
rsenden opened this issue Nov 18, 2020 · 1 comment
Closed

Add support for environment variables with custom prefix #24202

rsenden opened this issue Nov 18, 2020 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@rsenden
Copy link

rsenden commented Nov 18, 2020

Use case:

  • Publish a Docker image for a Spring Boot application, for example using com.google.cloud.tools.jib
  • Use this Docker image in a GitHub Actions workflow
  • Supply Spring Boot configuration properties using the with: clause in the GitHub Actions workflow

GitHub will pass the contents of the with: clause as environment variables to the Docker image using an INPUT_ prefix, i.e. INPUT_MY_CONFIG_PROPERTY. It would be nice if Spring Boot would support scenarios like these out of the box.

For now, I'm using a somewhat hacky work-around, passing the following custom Environment implementation to SpringApplicationBuilder:

public class MyCustomEnvironment extends StandardEnvironment {
	@Override
	public Map<String, Object> getSystemEnvironment() {
		Map<String, Object> systemEnv = super.getSystemEnvironment();
		Map<String, Object> result = systemEnv;
		if ( systemEnv.containsKey("GITHUB_ACTIONS") ) {
			result = new HashMap<>(systemEnv); 
			result.putAll(systemEnv.entrySet().stream()
				.filter(e->e.getKey().startsWith("INPUT_"))
				.collect(Collectors.toMap(e->e.getKey().replaceFirst("^INPUT_",""), e->e.getValue())));
		}
		return result;
	}
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 18, 2020
@wilkinsona
Copy link
Member

Thanks for the suggestion. This is a duplicate of #3450. Could you please add your comment to that issue as the GitHub Actions use case is one that I don't think we've heard before.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants