Customize Spring Boot launch script

Viewed 213

I have a typical Spring Boot 2.x application. I'm currently deploying the application using Docker. I'm also using the built-in shell script that a "distribution" provides — when done via Gradle, read: assembleBootDist, installBootDist, etc.

The issue is that I have to execute (a) some other shell script before starting the application, (b) insert this shell script somehow the built-in one, (c) or something else that achieves the same.

So I wonder if there is a way to accomplish this in a clean way, without introducing any security concerns, etc. I've been trying to plug into the bootStartScripts (Gradle) task, but no luck there. I'm aware there is a launchScript property within bootJar, but as far as I can tell it replaces altogether the actual built-in script provided by Spring Boot — and I'm avoiding that.

Any other shell-fu would also work, provided nothing around security is compromised.

2 Answers

This is kind of hack but with spring boot default script customization provided - may be you can use "inlinedConfScript" ( explained here) which basically points to a script meant to provide configuration but since it is a script file technically you can write scripting code as usual.

inlinedConfScript

Reference to a file script that should be inlined in the default launch script. This can be used to set environmental variables such as JAVA_OPTS before any external config files are loaded.

Another solution could be to (still) use the shell script that provides the custom logic and then execute (in the end) the built-in shell script generated by the Spring Boot "distribution" (Gradle) task:

#!/usr/bin/env sh

printf "%s\n" "Running some initialization steps..."
# ...

# This is the shell script generated by the Spring Boot "distribution" (Gradle) task
exec /path/to/application "$@"

Save this as, for instance: docker-entrypoint, and use it as usual in the Dockerfile's ENTRYPOINT instruction.

Related