javadockeropen-libertymicroprofileeclipse-microprofile-config

How to setup stage-specific microprofile config with java-ee8, microProfile 4.0, Openliberty 21 and Docker


I have a problem with my application using JavaEE8, Openliberty 21.0.0.5 and Microprofile 4.0 inside a docker container. I cannot set the mpConfig-2.0-introduced mp.config.profile from "outside" the image. My setup is as follows:

microprofile-config.properties
microprofile-config-dev.properties
microprofile-config-prod.properties

inside src/main/resources/META-INF/

Features are correctly activated inside server.xml and are installed correctly on startup.

<featureManager onError="WARN">
    <feature>microProfile-4.0</feature>
    <feature>javaee-8.0</feature>
</featureManager>

I also have one server.env per stage that is passed to my container via docker run's --env-file.

My first approach was to set mp.config.profile inside the server.env since it can be changed when running the image on different stages. f.e. mp.config.profile=dev inside server-dev.env an so forth. However the values of microprofile-config-dev.properties are never used with this setup.

The only way I was able to correctly activate the config profile was when using

<variable name="mp.config.profile" value="dev" />

inside the server.xml.

However the server.xml is not stage-specific inside the docker image, so it won't be possible to change it on different stages.

Does anyone have a suggestions what is the correct way to do this?

Thanks in advance

Regards


Solution

  • If you want to set mp.config.profile from server.env, you probably need to set MP_CONFIG_PROFILE instead.

    Since dots aren't valid in environment variable names, MP Config defines some mapping rules when looking up config from environment variables. It will check for the requested name with non-alphanumeric characters converted to underscores, and then again also with all letters converted to uppercase.