One build for multiple applications

Hi,

I want to build a war from my project and then use that same war for multiple (customer) applications. There are some properties that need to match the final url and that exist in the war already:


cuba.webHostName = app.company.com
cuba.webAppUrl = https://app.company.com/customer

Here the /customer may vary as well as the ‘app.company.com’. Is there any way to override these properties when deploying in production?

I’m using docker and do a number of overrides already to the different images but I can’t seem to override properties in the war file.

One option could be to allow for Java defines (like -Dcuba.webAppUrl=https://app.company.com/customer) and have that applied for the application but again, I do not see how to do that.

Any suggestions?

Hi,

you can just define the mentioned app.properties in an external properties file. This way, you can just build your war file and place a local.app.properties file right next to it which defines the external configuration options.

In this case you would to something like:
docker run -v /path/to/external/local.app.properties:/usr/local/tomcat/conf/app-core/local.app.properties my-cuba-app-container

One other alternative is to bake the local.app.properties in the container but not into the war file. So instead of using the volume feature of Docker you can create a Dockerfile that extends from your normal docker image where you add a local.app.properties into the Container.

For something like this can be as described here.

The third option is to externalize the the properties as OS environment variables (which are the base primitives for configuration options in the docker world). This would be something like this:
docker run -e CUBA_WEB_APP_URL=https://app.company.com/customer -e CUBA_WEB_HOST_NAME=app.company.com my-cuba-app-container
This would require anything that takes the environment variables and place it into the local.app.properties or somewhere else where the tomcat can pick it up.

For this you can find an example in this article (as a side not, but anyways): Run CUBA on AWS ECS - Part 1 – Road to CUBA and beyond...

Bye
Mario

1 Like

I would add that as long as Java system properties override application properties with the same name (see Appendix C: System Properties - CUBA Platform. Developer’s Manual), you should be able to specify the JAVA_OPTS environment variable which is used by standard Tomcat launch scripts and define your properties in it like this:


JAVA_OPTS="-Dcuba.connectionUrlList=http://somehost:8080/app-core -DmyProperty=myValue"

Got it to work - thanks!

I guess the different options in your approach would work but I applied the solution by Konstantin as it fitted my setup most conveniently.

But thanks for sharing.

Hi
it’s an old topic, but it can be useful to others…
So I want to add that if you’re using UberJAR deploy method, with embedded Jetty, you can make even your embedded jetty-env.xml config dynamic by using SystemProperty tag:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="CubaDS" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg/>
        <Arg>jdbc/CubaDS</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp2.BasicDataSource">
                <Set name="driverClassName">org.postgresql.Driver</Set>
                <Set name="url"><SystemProperty name="app.jetty.mainds.url" default="jdbc:postgresql://localhost/mylocaldb"/></Set>
                <Set name="username"><SystemProperty name="app.jetty.mainds.user"/></Set>
                <Set name="password"><SystemProperty name="app.jetty.mainds.password"/></Set>
                <Set name="maxIdle">2</Set>
                <Set name="maxTotal">20</Set>
                <Set name="maxWaitMillis">5000</Set>
            </New>
        </Arg>
    </New>
</Configure>

here the three properties starting with app.jetty.mainds are custom java props, and you can define them in the usual ways.

Bye
Paolo

1 Like