jakarta-eethorntail

How to set profiles as default in thorntail 2.4


Problem:
I created an application in JavaEE with Thorntail 2.4.0-Final. I have 2 yaml Files, 'project-default.yml' and 'project-local.yml'. My Postgres information are inside the default.yml, my H2 information inside the local.yml.

If I start my application with the command line 'java -jar myapplication.jar' it will use the default.yml. If I add -Slocal to the command line it uses the local.yml, but I want it to use as default the local.yml.

I know I can rename the 2 yaml files, so that the default will be the H2, but this doesn't solve my problem, because I want to deploy my application into a Cloud and in the Cloud it should use the Postgres and not the H2 and there is no option to say something like 'cf push myapplication -S....'.

Question:
How can I tell my application that he use the 'project-local.yml' file when I start my application local, without adding '-Slocal'?

Or

How can I push my application with adding a command to say which yaml file it should use?


Solution

  • Thorntail can't know in which environment it's running. The very purpose of configuration profiles is that you are in control of what configuration is applied. If you have an idea how a "local" environment could be reliably (!) detected, I think that would be a great feature request.

    That said, it seems weird that Cloud Foundry wouldn't let you configure the command that's used to start the app. Per http://cli.cloudfoundry.org/en-US/cf/push.html, you can use the -c argument to configure the command.

    This seems pretty low-level, though, so here's another option. In addition to the -s and -S arguments, you can use the thorntail.project.stage.file and thorntail.project.stage system properties. Here, you can set thorntail.project.stage, which is roughly equivalent to -S. Per https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-java_opts.md, you can set arbitrary system properties by creating the JAVA_OPTS environment variable.

    So if you switched project-defaults.yml to the local settings (using H2), and created e.g. project-cloud.yml with the production settings (using PostgreSQL), it would be enough to create an environment variable JAVA_OPTS="-Dthorntail.project.stage=cloud" in Cloud Foundry.