7.3.10.2. Distributed Uber JAR Deployment

To set up the distributed application configuration, open your CUBA project in Studio, navigate to Deployment settings, go to Uber JAR tab and then configure options as described below:

  1. Open the Uber JAR tab.

  2. Untick Single Uber JAR property.

Add the following changes to the appProperties:

appProperties = ['cuba.automaticDatabaseUpdate': true,
                 'cuba.webHostName':'sales-core',
                 'cuba.connectionUrlList': 'http://sales-core:8079/app-core',
                 'cuba.webAppUrl': 'http://sales-web:8080/app',
                 'cuba.useLocalServiceInvocation': false,
                 'cuba.trustedClientPermittedIpList': '*.*.*.*']
  • cuba.webHostName property defines the host name of the machine, on which this application block is running. The name has to correspond to the core service name described in Dockerfile.

  • cuba.connectionUrlList property sets Middleware server connection URL for client blocks. The host has to be named the same as the core service described in Dockerfile and the contextName has to correspond to the core *.jar file name.

  • cuba.webAppUrl property defines URL of the Web Client application. The host has to be named the same as the web service described in Dockerfile.

  • cuba.useLocalServiceInvocation property should be set to false in our case, because we deploy core and web servers in the different containers.

  • cuba.trustedClientPermittedIpList property defines the list of IP addresses, from which the login to the application is allowed.

Tip

If you have more than one Middleware server you have to list all of them in the cuba.connectionUrlList property and configure a cluster of Web Client servers, as you can see in the Application Scaling section.

Run the buildUberJar task to regenerate the JARs:

gradle buildUberJar

Create two subfolders in the docker-image folder for the web and core JARs. You should create separate containers for each JAR, so you need to configure two Dockerfiles.

Dockerfile for the core:

### Dockerfile

FROM openjdk:8

COPY . /usr/src/cuba-sales

CMD java -Dapp.home=/usr/src/cuba-sales/home -jar /usr/src/cuba-sales/app-core.jar

Dockerfile for the web:

### Dockerfile

FROM openjdk:8

COPY . /usr/src/cuba-sales

CMD java -Dapp.home=/usr/src/cuba-sales/home -jar /usr/src/cuba-sales/app.jar

A docker-compose.yml file contains separated core and web containers and looks like this:

version: '2'

services:
  postgres:
    image: postgres:9.6.6
    environment:
      - POSTGRES_PASSWORD=cuba
      - POSTGRES_USER=cuba
      - POSTGRES_DB=sales
    ports:
     - "5433:5432"
    networks:
     - sales-network
  sales-core:
    image: cuba-sample-sales-core
    networks:
     - sales-network
  sales-web:
    image: cuba-sample-sales-web
    ports:
     - "8080:8080"
    networks:
     - sales-network

networks:
  sales-network:

Build the images with the following commands:

docker build -t cuba-sample-sales-web ./web
docker build -t cuba-sample-sales-core ./core

To start the application, go to the directory of the docker-compose.yml file and run:

docker-compose up

After the task is completed you will be able to open the application at http://localhost:8080/app

Tip

For deploying containers on several physical machines, you may be required to install and configure Docker Swarm or Kubernetes.