Pass application.conf file at deploy time in Docker setup built using jar

Viewed 395

My requirement is to pass the application.conf file for Play framework based Scala application at deploy time in a Docker setup on Kubernetes, in order to support values passed using secrets. However, the constraint I have is I use the application's fat-jar as entrypoint in the Dockerfile:

...
EXPOSE 9000
ENTRYPOINT java -jar myapp.jar

I want to build the fat-jar with reference to that application.conf which will be passed at deploy time (using secrets), with SBT command, something like:

sbt -Dconfig.file="/opt/myorg/myapp/application.conf" clean publish

But this would fail as the file would only be available at deploy time. How can I achieve this?

1 Answers

You should change your deploy so that container takes this file from somewhere or change the approach of getting the needed properties. For example:

  • you can execute ssh/scp command that will copy the file into the container and support this by k8s because by default it will shuffle/recreate containers in the cluster (this is an awful solution, but you can get the idea from it)
  • you can attach the external volume with this file to the container and then pass the path to the java process. Something like that should work ENTRYPOINT java -jar myapp.jar -Dconfig.file="/opt/myorg/myapp/application.conf".
  • add config as a file to the jar at build time (but as I understood build time is not the case)
  • change how your app gets the properties so that it can get them from the env variables, and define env during the deploy process

I'm not a k8s user, so I can't tell you the exact way of doing this. But I hope some of that can help you.

Related