Ady
Ady

Reputation: 702

Externalize application configuration for Google Cloud Run

I was looking to externalize application configuration for containerized applications on Google Cloud Run. I know there are environment variables available for cloud run application and I want to have something as Config Server for Cloud Run.

Is there any out of the box support available on GCP?

Upvotes: 5

Views: 2838

Answers (2)

Abhay Phougat
Abhay Phougat

Reputation: 410

There are two solutions to it :

  1. If your docker file is "ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/****.jar"]" then use "-Dspring.profiles.active=dev" in the container arguments on the cloud run.

  2. In case your docker file has "CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/***.jar"]" You can do it by setting Environment Variable as SPRING_PROFILES_ACTIVE and value as dev in "Variables & Secrets" tab on cloud run Container Configurationenter image description here

Upvotes: 1

Michal
Michal

Reputation: 15669

When setting up your Cloud Run deployment, you can simply inject environment variables into your service:

enter image description here

Because Spring Boot comes with application.properties mechanism, you can easily override those values exactly from the environment variables. Do keep in mind, that the syntax is slightly different:

application.properties

  • spring.profiles.active=dev

environment variables

  • SPRING_PROFILES_ACTIVE=dev

Injected env variables will take precedence over the ones defined in your application.properties file.

Upvotes: 3

Related Questions