How to Externalize Database Connections for JasperReports Server Docker containers - TIBCOSoftware/js-docker GitHub Wiki

When deploying JasperReports Server in Docker, you can externalize repository database connections by passing environment variables to containers. Environment variables can be used to parameterize database connections for services:

  • jasperserver-buildomatic
  • jasperserver-webapp

Project Preparation

  1. Clone the project:

    cd /opt
    git clone https://github.com/TIBCOSoftware/js-docker.git
  2. Obtain and copy the JasperReports Server package into the Docker project:

    cp js-jrs_9.0.0_bin.zip /opt/js-docker
  3. Unpack js-jrs_9.0.0_bin.zip:

    cd /opt/js-docker/jaspersoft-containers/Docker/jrs/scripts
    unpackWARInstaller.sh
  4. Generate context.xml which will be used to parameterize connections:

    cd /opt/js-docker/jasperreports-server-pro-9.0.0-bin/buildomatic
    cp sample_conf/postgresql_master.properties ./default_master.properties
  5. Edit default_master.properties and set appServerType = skipAppServerCheck.

  6. Generate context.xml template file and copy it into temp:

    ./js-ant gen-config
    cp /opt/js-docker/jasperreports-server-pro-9.0.0-bin/buildomatic/build_conf/default/webapp/META-INF/context.xml /tmp

    Note: This command will generate a template file with JNDI connections mapping for sample datasources, which should be removed manually from context.xml when deploying on production.

  7. Clean Buildomatic cache to avoid temporary config being used in Docker image:

    ./js-ant clean-config
    rm default_master.properties

Config Files Parameterization

  1. Copy the template context.xml into jasperserver-customization:

    mkdir -p /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/jasperserver-customization/webapps/jasperserver-pro/META-INF
    cp /tmp/context.xml /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/jasperserver-customization/webapps/jasperserver-pro/META-INF
  2. Edit /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/jasperserver-customization/webapps/jasperserver-pro/META-INF/context.xml file and:

    • Replace username="postgres" with username="${DB_USER_NAME}".
    • Replace password="postgres" with password="${DB_PASSWORD}".
    • Replace localhost:5432/jasperserver with ${DB_HOST}:${DB_PORT}/${DB_NAME}.
    • Replace for other databases localhost:5432 with ${DB_HOST}:${DB_PORT}.
    • Additionally, parameterize other database names with new variables.
    • If deploying for production, remove sample database configurations.
  3. Edit /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/default-properties/default_master.properties and pass environment variables for the repository database connection that will be used by the jasperserver-buildomatic container:

    dbHost=${env.DB_HOST}
    js.dbName=${env.DB_NAME}
    dbUsername=${env.DB_USER_NAME}
    dbPassword=${env.DB_PASSWORD}

    Note: This results in two parameterized files:

    • context.xml that will be used by jasperserver-webapp container.
    • default_master.properties that will be used by jasperserver-buildomatic container.
  4. Edit Docker Compose env /opt/js-docker/jaspersoft-containers/Docker/jrs/.env and add new variables:

    DB_HOST=<your-db-hostname>
    DB_PORT=<your-db-port>
    DB_NAME=<jasperserver-repository-db-name>
    DB_USER_NAME=<db-user>
    DB_PASSWORD=<db-password>

    Note: Ensure that <your-db-hostname> will be accessible from Docker containers.

Building Images and Starting the Cluster

Important

  • If you plan to connect containers to an already pre-created and loaded jasperserver-pro repository database, ensure you obtain the keystore files (.jrsks and .jrsksp) that were used during the database load.
  1. Copy keystore files into /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/keystore:

    cp .jrsks /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/keystore/
    cp .jrsksp /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/keystore/
    chmod -R 644 /opt/js-docker/jaspersoft-containers/Docker/jrs/resources/keystore/.jrs*
  2. Copy the license file into /opt/js-docker/js-docker/jaspersoft-containers/Docker/jrs/resources/license:

    cp jasperserver.license /opt/js-docker/js-docker/jaspersoft-containers/Docker/jrs/resources/license
  3. Edit /opt/js-docker/jaspersoft-containers/Docker/jrs/docker-compose.yml to remove dependency on the postgresdb container.

    • Under jasperserver-webapp service, remove depends_on: - repository, just keep - activemq.
    • Under jasperserver-webapp service, find JAVA_OPTS and add -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
    • Under jasperserver-buildomatic service, remove the value from command: ${JS_INSTALL_TARGETS} property, just keep command:.
    • Under jasperserver-buildomatic service, remove the whole depends_on: - repository part.
    • Find the repository service and remove or comment out the whole service.
    • Remove or comment out volumes.

Note: JAVA_OPTS example:

JAVA_OPTS: "-XX:+UseContainerSupport -XX:MinRAMPercentage=33.0 -XX:MaxRAMPercentage=75.0 -Djs.license.directory=/usr/local/share/jasperserver-pro/license -Djasperserver.cache.jms.provider=tcp://activemq:61616 -Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource"
  1. Build images:

    cd /opt/js-docker/jaspersoft-containers/Docker/jrs
    docker-compose build --no-cache
  2. Optional Step: Create and load a parameterized repository database:

    docker-compose run jasperserver-buildomatic set-minimal-mode gen-config prepare-js-pro-db-minimal

    Note: If you plan to load sample databases and sample data, ensure you configure them properly in context.xml and then execute:

    docker-compose run jasperserver-buildomatic gen-config pre-install-test-pro prepare-all-pro-dbs-normal

    If such a database already exists, you will be prompted to accept the database to be dropped and recreated, in this mode (TTY) you can enter "y", but if you plan to execute commands silently, then add additional target before db creation, like this:

    docker-compose run jasperserver-buildomatic gen-config drop-js-db pre-install-test-pro prepare-all-pro-dbs-normal
  3. Start the JasperReports Server cluster:

    docker-compose up -d

Summary: As a result, you get two images jasperserver-webapp and jasperserver-buildomatic with parameterized connections to the repository and other databases.

Updating Database Connection

In case if you need to reconnect containers to another repository database:

  1. Edit /opt/js-docker/js-docker/jaspersoft-containers/Docker/jrs/.env and change the required variables.

  2. Restart the cluster:

    docker-compose up -d jasperserver-webapp
⚠️ **GitHub.com Fallback** ⚠️