Search code examples
cloudcaptain

How to make boxfuse create an image containing executable jar and configuration file to be specified in main arg?


I'm playing around with boxfuse attempting to "fuse" an image which contains an executable JAR. My executable JAR is given the path to a config file as an argument to it's main method, like so:

java -jar my-executable.jar -conf /some/path/to/my/conf.json

Where the file conf.json is read in by the JAR's process to be configured with e.g. port, database connection properties, etc.

I understand how to pass custom arguments using -jvm.main.args="-conf /some/path/to/my/conf.json", however, I don't know how to get the config file into the image itself. Obviously the path has to point to a valid file that exists within the image.

In dev, test and production, I would want to use the same executable JAR, but a different config file for each environment. I don't currently see a way around having different images for each environment. I see there is some support for packaging specific config with Dropwizard payloads, but no mention of something similar for executable JARs.

Is there a more general way I can package arbitrary files into the image, with predictable paths I can refer to in the jvm.main.args?


P.S. in my case the executable JAR happens to be a Vert.x application, but I think the general case applies.


Solution

  • What you can do is package the configuration for all environments (dev, test & production) within the executable JAR file. So you would have dev.json, test.json and production.json

    You can then use a technique like environment detection with for example an environment variable to detect the correct environment at runtime and pick the correct configuration, which can then be loaded from the classpath instead of the file system.

    This allows you to build both the jar file and the Boxfuse image only once and run it unchanged on all environments.

    P.S.: I've just raised an issue for you to add first class Vert.x support in the near future to make things even easier: https://github.com/cloudcaptainsh/cloudcaptain/issues/28