Spring-Boot, OpenShift2-DIY and Java8 without installing a custom JDK
In a previous blog post I wrote about how to setup a DIY cartridge on OpenShift2 when you need Java 8 for a Spring-Boot application. What I actually didn’t like in that solution was the fact that the installed JDK uses several hundred megabytes of disk space. When running in the free plan on a small gear this is too much when you add a cartridge like mongo which itself uses over 400MB. I ended up with just a plain application and a mongo db with no data getting the message that the space on my gear is exhausted.
Mongo preallocated pretty much space before doing anything, there is nothing to do about that. So I looked for a different way to set up the JDK. I did some more research on the web and found that with normal cartridges you can add a file .openshift/markers/java8 but that does not work for a DIY cartridge.
But when logging into my app and searching round, I found that there actually is a JDK 8 installed in the directory /etc/alternatives/java_sdk_1.8.0.
So I changed my build script (.openshift/action_hooks/build) to:
#!/bin/bash # export environment variables export JAVA_HOME="/etc/alternatives/java_sdk_1.8.0" export PATH=$JAVA_HOME/bin:$PATH # call our own mvn script with the right settings cd $OPENSHIFT_REPO_DIR ./.openshift/mvn package -s .openshift/settings.xml -DskipTests=true mv target/*.jar . ./.openshift/mvn clean -s .openshift/settings.xml
Notice that I still use my custom mvn script which I described in the previous post.
My start script (.openshift/action_hooks/start) now is as follows:
#!/bin/bash # The logic to start up your application should be put in this # script. The application will work only if it binds to # $OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT # export environment variables export JAVA_HOME="/etc/alternatives/java_sdk_1.8.0" export PATH=$JAVA_HOME/bin:$PATH cd $OPENSHIFT_REPO_DIR nohup java -jar *.jar &
This frees my application from the space needed for the custom JDK.