- Install the Google Cloud SDK. You can do so with the following command:
curl https://sdk.cloud.google.com | bash
- Create, enable billing on a project on the Google Cloud Console.
- Enable the Runtime Config API
- Set the
GOOGLE_CLOUD_PROJECT
orGCLOUD_PROJECT
environment variable.
export GOOGLE_CLOUD_PROJECT=my-project-id
- (Local testing only)
Using the
Runtime Configurator
in your application requires thatGOOGLE_APPLICATION_CREDENTIALS
environment variable be set to point to an authorized service account credentials file. More instructions on creating the credentials file here.
cd rcloadenv
mvn clean install
-
Create a configuration using the Google Cloud SDK. The configuration name should be in the format
application.id
_profile
, for example :myapp_prod
gcloud beta runtime-config configs create myapp_prod
Then set the variables you wish to load. Variable names will be transformed from lowercase to uppercase, separated by underscores.
gcloud beta runtime-config configs variables set \
queue_size 25 \
--config-name myapp_prod
gcloud beta runtime-config configs variables set \
feature_x_enabled true \
--config-name myapp_prod
- In your Spring Boot application directory (see the sample application here),
add the following line to
src/main/resources/META-INF/spring.factories
:
org.springframework.cloud.bootstrap.BootstrapConfiguration=com.google.cloud.rcloadenv.RuntimeConfigPropertySourceLocator
- Add the following dependency to your
pom.xml
:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>rcloadenv</artifactId>
<version>0.0.1-alpha-SNAPSHOT</version>
</dependency>
- Set an
application.id
and profile(default =default
) in yoursrc/main/resources/application.properties
:
application.id=myapp
spring.profiles.active=prod
- Add Spring style configuration variables, see SampleConfig.java
@Value("${queue_size}")
private int queueSize;
@Value("${feature_x_enabled}")
private boolean isFeatureXEnabled;
- (Optional Step) Spring Boot Actuator provides support to have configuration parameters be reloadable with the POST
/refresh
endpoint. Add the following dependency to yourpom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then, add @RefreshScope
to your configuration class to have parameters be reloadable at runtime.
Update a property with gcloud and then call the /refresh
endpoint:
gcloud beta runtime-config configs variables set \
queue_size 200 \
--config-name myapp_prod
curl -XPOST http://myapp.host.com/refresh