1

I am trying to pass in VCAP_SERVICES (All Caps with an underscore) to my docker container that has a Spring Boot application in it. The application comes up and simply ignores any values in the variable. I am using a config server and the very first line of the logs is usually logging where that config server is. It is always attempting to hit localhost:8888, which is the default.

The Docker image is based off of the openjdk:8 base image and the expanded jar file is simply copied into it.

I have tried many different ways of passing it the json:

1- as an ENV named VCAP_SERVICES and the value is just the JSON object 2- as an ENV named SPRING_APPLICATION_JSON with a JSON object with a property called VCAP_SERVICES 3- attempted to pass in different ENV variables from my google-fu"

ENV SPRING_CLOUD_DEPLOYER_CLOUDFOUNDRY_STREAM_USE_SPRING_APPLICATION_JSON=false 
ENV SPRING_CLOUD_DEPLOYER_CLOUDFOUNDRY_TASK_USE_SPRING_APPLICATION_JSON=false
ENV JBP_CONFIG_SPRING_AUTO_RECONFIGURATION="{enabled: false}"
FROM openjdk:8
EXPOSE 80
EXPOSE 443
WORKDIR / app

ENV SPRING_APPLICATION_NAME="application name"  
ENV VCAP_SERVICES="{  \"p-config-server \": [ { \"credentials \": {  \"access_token_uri \":  \"https://configserverURL/oauth/token \",  \"client_id \":  \"AUNIQUECLIENTID \",  \"client_secret \":  \"ASECRET\",  \"uri \":  \"https://CONFIGSERVERURL \" },  \"gateway_name \":  \" \",  \"label \":  \"p-config-server \",  \"name \":  \"config-server \",  \"instance_name \":  \"config-server \", \"tags \": [  \"configuration \",  \"spring-cloud \" ],  \"volume_mounts \": [] }  }"

COPY / .
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-cp",".","org.springframework.boot.loader.JarLauncher"]

I Expect the logging to indicate the proper config server:

main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : https://CONFIGSERVERURL

but instead i get

main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888

the start command looks like this in PCF:

 JAVA_OPTS="-agentpath:$PWD/.java-buildpack/open_jdk_jre/bin/jvmkill-1.16.0_RELEASE=printHeapHistogram=1 -Djava.io.tmpdir=$TMPDIR -Djava.ext.dirs=$PWD/.java-buildpack/container_security_provider:$PWD/.java-buildpack/open_jdk_jre/lib/ext -Djava.security.properties=$PWD/.java-buildpack/java_security/java.security $JAVA_OPTS" && CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-3.13.0_RELEASE -totMemory=$MEMORY_LIMIT -loadedClasses=32446 -poolType=metaspace -stackThreads=250 -vmOptions="$JAVA_OPTS") && echo JVM Memory Configuration: $CALCULATED_MEMORY && JAVA_OPTS="$JAVA_OPTS $CALCULATED_MEMORY" && MALLOC_ARENA_MAX=2 SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher
ewassef
  • 286
  • 2
  • 13
  • Please provide code example of how you are trying to read environmental variable from your code. Is VCAP_SERVICES the only environmental variable the only variable not being read? There are some conversation around that here https://stackoverflow.com/questions/35531661/using-env-variable-in-spring-boots-application-properties – moficodes Aug 05 '19 at 01:42
  • I am in Ops and converting an existing (functioning) application from PCF into a Docker container. I am assuming they are reading it using the Spring actuators – ewassef Aug 05 '19 at 15:49
  • You don't need `JBP_CONFIG_SPRING_AUTO_RECONFIGURATION` because that's for the Java buildpack and that's not going to be running in your container. A couple suggestions. 1.) Copy the start command from the app when it runs on Cloud Foundry. 2.) Run `env` in the container and confirm that your VCAP_SERVICES is visible and populated correctly. If you can, comare it to the value of VCAP_SERVICES for your app on Cloud Foundry. Hope that helps! – Daniel Mikusa Aug 05 '19 at 17:45
  • @DanielMikusa, thanks for the tip. I did verify that the `env` variable is populated correctly and the JSON is valid. The start command from PCF looks like this : (see above edit) – ewassef Aug 05 '19 at 22:25

1 Answers1

1

Turns out you need an environment variable naked VCAP_APPLICATION as well to trigger the reading of the other variable. It can even be empty apparently

ewassef
  • 286
  • 2
  • 13