Building for production

Hi,

Is there any common approach to follow when building the app for production? I know the documentation and got it to work when performing the following steps (manually mostly):

  • Modify web-app.properties to remove username/password for the login:

# Enable for production
cuba.web.loginDialogDefaultUser=
cuba.web.loginDialogDefaultPassword=
  • Build a war file :

$ gradlew buildWar
  • Modify the local.app.properties in both war files:

cuba.connectionUrlList = https://servername/app-core // Only on app.war, not app-core.war
cuba.webHostName = servername
cuba.webAppUrl = http://servername/app
  • Modify the web.xml in the app.war:

	<context-param>
		<description>Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>true</param-value>
	</context-param>

I guess the last two steps could be done while deploying the app on a docker image as well but somehow the entire process feels inconvenient and is should be possible to do this easier.

Is there anything I’m doing wrong here or missing?

I think you can do all of this in Studio > Deployment settings > WAR. All settings will be saved as parameters of the buildWar task in your build.gradle and thus will be separated from you development settings.

Properties that you define there are written to both WARs, but it is not a problem, because there are no properties with the same name that should have different values. The only problem with separate WARs is that you cannot specify custom web.xml files, so you have to switch off Vaadin production mode beforehand.

Hi Konstantin,

I must have missed this option but glad that it is available. I guess that makes things much easier.

I saw that if I make a single war, the web.xml can be customised (as you suggested). However, I would only like to define the ‘delta’ and not the entire web.xml so it would be updated appropriately in future. Any thought on that?

And coming to think of it, is there any means for version / build numbers within Cuba or does it need to be constructed otherwise?

I would only like to define the ‘delta’ and not the entire web.xml

I’ve created an issue for this, see the attached link.

is there any means for version / build numbers within Cuba

You can see how we expose the platform version in the com.haulmont.cuba.core.app.ServerInfo bean. These release.number and release.timestamp files are created at build time with the CubaReleaseTimeStamp task which can be used in your build.gradle as follows:


configure(globalModule) {
    task enhance(type: CubaEnhancing)

    task generateReleaseTimestamp(type: CubaReleaseTimeStamp) {
        releaseTimeStampPath = "$buildDir/classes/main/com/company/sample/core/global/release.timestamp"
        releaseNumberPath = "$buildDir/classes/main/com/company/sample/core/global/release.number"
        artifactVersion = '1.0'
        isSnapshot = false
    }
}

So you can make a similar mechanism in your project.

Hi Konstantin,

Thanks - I will see whether I get this to work.

Meanwhile, I didn’t get the war properties working. I added them in the deployment settings > war but when reopening the project, there was an error saying that the values of these properties were incorrect.

I had to remove the following from build.gradle (line 290):


appProperties = ['cuba.automaticDatabaseUpdate':'true', 'cuba.web.loginDialogDefaultUser':' ', 'cuba.web.loginDialogDefaultPassword':' ', 'cuba.connectionUrlList':'https://app.myserver.com/app-core', 'cuba.webHostName':'app.myserver.com', 'cuba.webAppUrl':'https://app.myserver.com']

and replace it with:


appProperties = ['cuba.automaticDatabaseUpdate':'true']

Any ideas?

Hi Berend,

This is because of this bug in Studio. It’s already fixed, the next bug-fix release will be available this week.

Thanx - than I understand

HI,

The related YouTrack issue is fixed in the platform version 6.4.0. Now custom separate web.xml could be used for each WAR.

Hi Rostislav,

Good news and I got this to work, meaning I got a production-web.xml in my war file. However, I’m not sure how to deploy it. Tomcat normally reads web.xml but doesn’t pick up anything else. So, how am I supposed to utilise the dedicated production-web.xml?

Thanks for your help.

Hi Berend,

Let me explain how the buildWar task works if a custom WebXmlPath is specified:

During the task execution, production-web.xml is copied to temp folder and renamed to web.xml*. It replaces the default web.xml. After that, contents of the temp folder are packed to WAR. So the contents of *web.xml in WAR should be exactly what you need.

But one thing has not been done yet: the plugin could not work as described if a path to custom production-web.xml is relative. See the YouTrack issue for more details.

Hi Rostislav,

Yep - that did the trick. It needs to be an absolute path. That’s ok for now but I’m glad that it will be fixed. I did see some comment in the original YouTrack issue but as I didn’t know what to expect I was not sure what to do with it.

Anyway - thanks!

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-8364