1

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.

Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
Grundlefleck
  • 124,925
  • 25
  • 94
  • 111

1 Answers1

1

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

Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
  • I'm happy with the idea of packaging different config for each environment within the JAR, and environment detection as long as it's limited to e.g. ENV=PROD. It does mean there's an added level of security needed for the JAR file, since it contains e.g. production database credentials, but fair enough. How then can I specify an env variable when running the image? – Grundlefleck May 05 '15 at 12:10
  • 1
    Using the envvars switch. Example: boxfuse run myapp -env=prod -envvars.PASSWORD=t0ps3cr3t More info: https://boxfuse.com/docs/commandline/run.html#envvars – Axel Fontaine May 05 '15 at 12:34
  • 1
    Note that you can always encrypt certain properties and pass in the decryption key as en environment variable as well. – Axel Fontaine May 05 '15 at 12:35