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;
}
}
Comment From: wilkinsona
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.