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
-
Clone the project:
cd /opt git clone https://github.com/TIBCOSoftware/js-docker.git
-
Obtain and copy the JasperReports Server package into the Docker project:
cp js-jrs_9.0.0_bin.zip /opt/js-docker
-
Unpack
js-jrs_9.0.0_bin.zip
:cd /opt/js-docker/jaspersoft-containers/Docker/jrs/scripts unpackWARInstaller.sh
-
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
-
Edit
default_master.properties
and setappServerType = skipAppServerCheck
. -
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. -
Clean Buildomatic cache to avoid temporary config being used in Docker image:
./js-ant clean-config rm default_master.properties
-
Copy the template
context.xml
intojasperserver-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
-
Edit
/opt/js-docker/jaspersoft-containers/Docker/jrs/resources/jasperserver-customization/webapps/jasperserver-pro/META-INF/context.xml
file and:- Replace
username="postgres"
withusername="${DB_USER_NAME}"
. - Replace
password="postgres"
withpassword="${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.
- Replace
-
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 thejasperserver-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 byjasperserver-webapp
container. -
default_master.properties
that will be used byjasperserver-buildomatic
container.
-
-
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.
- 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.
-
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*
-
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
-
Edit
/opt/js-docker/jaspersoft-containers/Docker/jrs/docker-compose.yml
to remove dependency on thepostgresdb
container.- Under
jasperserver-webapp
service, removedepends_on: - repository
, just keep- activemq
. - Under
jasperserver-webapp
service, findJAVA_OPTS
and add-Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource
- Under
jasperserver-buildomatic
service, remove the value fromcommand: ${JS_INSTALL_TARGETS}
property, just keepcommand:
. - Under
jasperserver-buildomatic
service, remove the wholedepends_on: - repository
part. - Find the
repository
service and remove or comment out the whole service. - Remove or comment out
volumes
.
- Under
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"
-
Build images:
cd /opt/js-docker/jaspersoft-containers/Docker/jrs docker-compose build --no-cache
-
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
-
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.
In case if you need to reconnect containers to another repository database:
-
Edit
/opt/js-docker/js-docker/jaspersoft-containers/Docker/jrs/.env
and change the required variables. -
Restart the cluster:
docker-compose up -d jasperserver-webapp