ewassef
ewassef

Reputation: 340

Dockerized Spring Boot application not reading VCAP_SERVICES environment variable JSON

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

Upvotes: 1

Views: 906

Answers (1)

ewassef
ewassef

Reputation: 340

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

Upvotes: 1

Related Questions