Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working PostgreSQL configuration #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ ENV CATALINA_OPTS="-Djava.awt.headless=true -Xms4096m -Xmx6144m -XX:MaxPermSize=
RUN apk add --update wget unzip bash postgresql-client ttf-dejavu

# Setup pentaho user
RUN mkdir -p ${PENTAHO_HOME}/server; mkdir ${PENTAHO_HOME}/.pentaho; adduser -D -s /bin/sh -h ${PENTAHO_HOME} pentaho; chown -R pentaho:pentaho ${PENTAHO_HOME}
RUN mkdir -p ${PENTAHO_HOME}/server && \
mkdir ${PENTAHO_HOME}/.pentaho && \
adduser -D -s /bin/sh -h ${PENTAHO_HOME} pentaho && \
chown -R pentaho:pentaho ${PENTAHO_HOME}
USER pentaho
WORKDIR ${PENTAHO_HOME}/server

# Get Pentaho Server
RUN echo http://downloads.sourceforge.net/project/pentaho/Business%20Intelligence%20Server/${MAJOR_VERSION}/pentaho-server-ce-${MINOR_VERSION}.zip | xargs wget -qO- -O tmp.zip && \
RUN echo https://downloads.sourceforge.net/project/pentaho/Business%20Intelligence%20Server/${MAJOR_VERSION}/pentaho-server-ce-${MINOR_VERSION}.zip | xargs wget -qO- -O tmp.zip && \
unzip -q tmp.zip -d ${PENTAHO_HOME}/server && \
rm -f tmp.zip

Expand All @@ -40,11 +43,22 @@ RUN rm ${PENTAHO_SERVER}/promptuser.sh
# Disable daemon mode for Tomcat
RUN sed -i -e 's/\(exec ".*"\) start/\1 run/' ${PENTAHO_SERVER}/tomcat/bin/startup.sh

# Update broken QRTZ SQL
RUN sed -i "s/connect quartz pentaho_user/connect quartz/g" ${PENTAHO_SERVER}/data/postgresql/create_quartz_postgresql.sql

# Copy scripts and fix permissions
USER root
COPY scripts ${PENTAHO_HOME}/scripts
COPY config ${PENTAHO_HOME}/config
RUN chown -R pentaho:pentaho ${PENTAHO_HOME}/scripts && chmod -R +x ${PENTAHO_HOME}/scripts
RUN chown -R pentaho:pentaho ${PENTAHO_HOME}/scripts && \
chmod -R +x ${PENTAHO_HOME}/scripts && \
chown -R pentaho:pentaho ${PENTAHO_HOME}/config && \
mkdir -p ${PENTAHO_SERVER}data/hsqldb && \
chmod -R 775 ${PENTAHO_SERVER}/data/hsqldb && \
chown -R pentaho:pentaho ${PENTAHO_SERVER}/data/hsqldb && \
mkdir -p ${PENTAHO_SERVER}/pentaho-solutions/system/jackrabbit/repository && \
chmod -R 775 ${PENTAHO_SERVER}/pentaho-solutions/system/jackrabbit/repository && \
chown -R pentaho:pentaho ${PENTAHO_SERVER}/pentaho-solutions/system/jackrabbit/repository
USER pentaho

# Volumes:
Expand Down
68 changes: 46 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@ It is based on some really splendid work done by [Wellington
Marinho](https://github.com/wmarinho/docker-pentaho).

## Requirements

- [PostgreSQL](https://www.postgresql.org/) 9.4
- `postgres:9.4-alpine` worked nicely for me

## How to run

- Start a PostgreSQL server
```

```Shell
docker run -d -p 5432:5432 --name postgres postgres:9.4-alpine
```

- Run once for testing and auto-clean container
```

```Shell
docker run --rm -it --link postgres:postgres \
-e PGHOST=postgres -e PGUSER=postgres -e PGPASSWORD= -p 8080:8080 ca0abinary/docker-pentaho
```

- Start in bash, prior to any scripts having executed, auto-clean (for debugging)
```

```Shell
docker run --rm -it --link postgres:postgres \
-e PGHOST=postgres -e PGUSER=postgres -e PGPASSWORD= -p 8080:8080 \
--entrypoint bash ca0abinary/docker-pentaho
```

- Run as a service
```

```Shell
docker run -d --link postgres:postgres \
-e PGHOST=postgres -e PGUSER=postgres -e PGPASSWORD= -p 8080:8080 \
ca0abinary/docker-pentaho
Expand All @@ -61,8 +66,10 @@ keep it in a data container or volume map.
- Jackrabbit stores files locally at `/opt/pentaho/server/pentaho-server/pentaho-solutions/system/jackrabbit/repository`

Example:
```

```shell
docker run --rm -it \
-v ./config/systemListeners.xml:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/systemListeners.xml \
-v /mnt/nfs-share/pentaho/hsqldb:/opt/pentaho/server/pentaho-server/data/hsqldb \
-v /mnt/nfs-share/pentaho/repository:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/jackrabbit/repository \
-p 8080:8080 ca0abinary/docker-pentaho
Expand All @@ -89,9 +96,33 @@ Default password is `password`.

The simplest `docker-compose.yml` file would be:

```YAML
version: "3"
services:

# Pentaho BI
pentaho:
container_name: pentaho
image: ca0abinary/docker-pentaho
ports:
- "8080:8080"
volumes:
- ./config/systemListeners.xml:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/systemListeners.xml
- pentaho-hsqldb-data:/opt/pentaho/server/pentaho-server/data/hsqldb
- pentaho-jackrabbit-data:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/jackrabbit/repository

# Data volumes
volumes:
pentaho-hsqldb-data:
pentaho-jackrabbit-data:
```

When using PostgreSQL `docker-compose.yml` file would be:

```YAML
version: "3"
services:

# Pentaho BI
pentaho:
container_name: pentaho
Expand All @@ -101,10 +132,11 @@ services:
ports:
- "8080:8080"
environment:
- HOST=pentaho-pg
- USER=pentaho
- PASSWORD=password
- PGHOST=pentaho-pg
- PGUSER=pentaho
- PGPASSWORD=password
volumes:
- ./config/systemListeners.xml:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/systemListeners.xml
- pentaho-hsqldb-data:/opt/pentaho/server/pentaho-server/data/hsqldb
- pentaho-jackrabbit-data:/opt/pentaho/server/pentaho-server/pentaho-solutions/system/jackrabbit/repository

Expand All @@ -118,6 +150,11 @@ services:
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- pentaho-pg-data:/var/lib/postgresql/data/pgdata
healthcheck:
test: pg_isready -U pgadmin || exit 1
interval: 30s
timeout: 10s
retries: 3

# Data volumes
volumes:
Expand All @@ -126,21 +163,8 @@ volumes:
pentaho-pg-data:
```

## Problems

Quartz and Hibernate continue to live on the internal
[HyperSQL](http://hsqldb.org/) database as despite changing the settings to work
with PostgreSQL using the provided documentation I'm not having success.
(`java.sql.SQLException: No suitable driver`)

The databases will be created in PostgreSQL, just not used.

Please feel free to examine the `scripts/setup_postgresql.sh` and post a PR if
you can fix it!

## See Also

- [Wellington
Marinho](https://github.com/wmarinho/docker-pentaho).
- [Wellington Marinho](https://github.com/wmarinho/docker-pentaho).
- [Pentaho 7.0 Docker Image](https://github.com/ca0abinary/docker-pentaho).
- [Pentaho 7.0 Documentation](https://help.pentaho.com/Documentation/7.0).
47 changes: 47 additions & 0 deletions config/systemListeners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
This is the spring configuration file that is used to wire system listeners into the Pentaho BI Platform. System
listeners are notified when the platform starts up and shuts down. System listeners can be added, removed, and
initialized here. Each bean in the list is a system listener. You can intialize any listeners properties, as shown
in the QuartzSystemListener and VersionCheckSystemListener.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd" default-lazy-init="true">
<bean id="systemListenersList" class="java.util.ArrayList">
<constructor-arg>
<list>
<bean id="osgiListener" class="org.pentaho.platform.osgi.OSGIBoot"/>
<bean id="kettleSystemListener" class="org.pentaho.platform.plugin.action.kettle.KettleSystemListener" />
<bean id="pluginSystemListener" class="org.pentaho.platform.plugin.services.pluginmgr.PluginAdapter" />
<bean class="org.pentaho.platform.plugin.services.security.userrole.SecuritySystemListener"/>
<bean id="backingRepositoryLifecycleManagerSystemListener" class="org.pentaho.platform.repository2.unified.BackingRepositoryLifecycleManagerSystemListener"/>

<bean id="jfreeReportSystemListener" class="org.pentaho.platform.plugin.action.jfreereport.JFreeReportSystemListener" />
<bean id="mondrianSystemListener" class="org.pentaho.platform.plugin.action.mondrian.MondrianSystemListener" />
<!--<bean id="pooledDataSourceSystemListener" class="org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceSystemListener"/>-->
<!--<bean id="nonPooledDataSourceSystemListener" class="org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledDatasourceSystemListener"/>-->
<!--<bean id="dynamicallyPooledDataSourceSystemListener" class="org.pentaho.platform.engine.services.connection.datasource.dbcp.DynamicallyPooledDatasourceSystemListener"/>-->
<bean id="chartingSystemListener" class="org.pentaho.platform.plugin.action.chartbeans.ChartBeansSystemListener" />
<bean id="loadDriversListener" class="org.pentaho.commons.system.LoadDriversListener" />
<bean id = "olap4jSystemListener" class="org.pentaho.platform.plugin.action.olap.Olap4jSystemListener">
<property name="olap4jConnectionList" ref="olap4jConnectionList"/>
<property name="olap4jConnectionRemoveList" ref="olap4jConnectionRemoveList"/>
</bean>
<bean id="quartzSystemListener" class="org.pentaho.platform.scheduler2.quartz.EmbeddedQuartzSystemListener" />
<bean id="versionCheckerSystemListener" class="org.pentaho.platform.scheduler2.versionchecker.EmbeddedVersionCheckSystemListener">
<property name="repeatIntervalSeconds">
<value>86400</value>
</property>
<property name="requestedReleases" value="Minor, GA" />
<property name="disableVersionCheck">
<value>false</value>
</property>
</bean>
<bean id="defaultContentSystemListener" class="org.pentaho.platform.plugin.action.defaultcontent.DefaultContentSystemListener" />

<!-- Insert system-listeners -->
</list>
</constructor-arg>
</bean>
</beans>
136 changes: 71 additions & 65 deletions scripts/setup_postgresql.sh
Original file line number Diff line number Diff line change
@@ -1,78 +1,84 @@
#!/bin/bash

if [ "$RDS_HOSTNAME" ]; then
PGHOST="$RDS_HOSTNAME"
PGUSER="$RDS_USERNAME"
PGPASSWORD="$RDS_PASSWORD"
PGDATABASE="$RDS_DB_NAME"
PGPORT="$RDS_PORT"
PGHOST="$RDS_HOSTNAME"
PGUSER="$RDS_USERNAME"
PGPASSWORD="$RDS_PASSWORD"
PGDATABASE="$RDS_DB_NAME"
PGPORT="$RDS_PORT"
fi

if [ "$PGHOST" ]; then
if [ ! "$PGPORT" ]; then
PGPORT=5432
fi
if [ ! "$PGDATABASE" ]; then
PGDATABASE=postgres
fi
if [ ! "$PGUSER" ]; then
PGUSER=pgadmin
fi
if [ ! "$PGPASSWORD" ]; then
PGPASSWORD=pgadmin.

fi
export PGPASSWORD="$PGPASSWORD"
echo "Checking PostgreSQL connection ..."
if [ ! "$PGPORT" ]; then
PGPORT=5432
fi
if [ ! "$PGDATABASE" ]; then
PGDATABASE=postgres
fi
if [ ! "$PGUSER" ]; then
PGUSER=pgadmin
fi
if [ ! "$PGPASSWORD" ]; then
PGPASSWORD=pgadmin.

nc -zv $PGHOST $PGPORT

if [ "$?" -ne "0" ]; then
echo "PostgreSQL connection failed."
exit 0
fi
fi
export PGPASSWORD="$PGPASSWORD"
echo "Checking PostgreSQL connection ..."

CHK_QUARTZ=`echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep quartz | wc -l)"`
CHK_HIBERNATE=`echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep hibernate | wc -l)"`
CHK_JCR=`echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep jackrabbit | wc -l)"`
until psql -h "$PGHOST" -U "$PGUSER" -c '\q'; do
echo >&2 "PostgreSQL is unavailable - sleeping"
sleep 1
done
sleep 2

echo "quartz: $CHK_QUARTZ"
echo "hibernate: $CHK_HIBERNATE"
echo "jcr: $CHK_JCR"

if [ "$CHK_JCR" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_jcr_postgresql.sql
fi
if [ "$CHK_HIBERNATE" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_repository_postgresql.sql
fi
if [ "$CHK_QUARTZ" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_quartz_postgresql.sql
nc -zv $PGHOST $PGPORT

# Insert dummy table to fix "RUNSCRIPT" issue.
# http://forums.pentaho.com/showthread.php?153231-Pentaho-ce-5-Initialization-Exception
psql -U $PGUSER -h $PGHOST -d quartz -c 'CREATE TABLE "QRTZ" ( NAME VARCHAR(200) NOT NULL, PRIMARY KEY (NAME) );'
fi
if [ "$?" -ne "0" ]; then
echo "PostgreSQL connection failed."
exit 0
fi

# Use postgresql for hibernate
if grep -q postgresql $PENTAHO_SERVER/pentaho-solutions/system/hibernate/hibernate-settings.xml; then
sed -i s/hsql/postgresql/g $PENTAHO_SERVER/pentaho-solutions/system/hibernate/hibernate-settings.xml

sed -i s/localhost:5432/$PGHOST:$PGPORT/g $PENTAHO_SERVER/pentaho-solutions/system/hibernate/postgresql.hibernate.cfg.xml

cp $PENTAHO_HOME/config/jdbc.properties $PENTAHO_SERVER/pentaho-solutions/system/simple-jndi/jdbc.properties
sed -i "s|postgresql://localhost:5432|postgresql://$PGHOST:$PGPORT|g" $PENTAHO_SERVER/pentaho-solutions/system/simple-jndi/jdbc.properties
fi
CHK_QUARTZ=$(echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep quartz | wc -l)")
CHK_HIBERNATE=$(echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep hibernate | wc -l)")
CHK_JCR=$(echo "$(psql -U $PGUSER -h $PGHOST -d $PGDATABASE -l | grep jackrabbit | wc -l)")

# Use postgreql for jackrabbit
#if grep -q postgresql://localhost:5432 $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml; then
# cp $PENTAHO_HOME/config/repository.xml $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml
# sed -i "s|postgresql://localhost:5432|postgresql://$PGHOST:$PGPORT|g" $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml
#fi

# Use postgresql for tomcat (quartz / hibernate)
if grep -q hsqldb $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml; then
cp $PENTAHO_HOME/config/context.xml $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml
sed -i "s|jdbc:postgresql://localhost:5432/|jdbc:postgresql://$PGHOST:$PGPORT/|g" $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml
fi
echo "quartz: $CHK_QUARTZ"
echo "hibernate: $CHK_HIBERNATE"
echo "jcr: $CHK_JCR"

if [ "$CHK_JCR" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_jcr_postgresql.sql
fi
if [ "$CHK_HIBERNATE" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_repository_postgresql.sql
fi
if [ "$CHK_QUARTZ" -eq "0" ]; then
psql -U $PGUSER -h $PGHOST -d $PGDATABASE -f $PENTAHO_SERVER/data/postgresql/create_quartz_postgresql.sql

# Insert dummy table to fix "RUNSCRIPT" issue.
# http://forums.pentaho.com/showthread.php?153231-Pentaho-ce-5-Initialization-Exception
psql -U $PGUSER -h $PGHOST -d quartz -c 'CREATE TABLE "QRTZ" ( NAME VARCHAR(200) NOT NULL, PRIMARY KEY (NAME) );'
fi

# Use postgresql for hibernate
if grep -q postgresql $PENTAHO_SERVER/pentaho-solutions/system/hibernate/hibernate-settings.xml; then
sed -i s/hsql/postgresql/g $PENTAHO_SERVER/pentaho-solutions/system/hibernate/hibernate-settings.xml

sed -i s/localhost:5432/$PGHOST:$PGPORT/g $PENTAHO_SERVER/pentaho-solutions/system/hibernate/postgresql.hibernate.cfg.xml

cp $PENTAHO_HOME/config/jdbc.properties $PENTAHO_SERVER/pentaho-solutions/system/simple-jndi/jdbc.properties
sed -i "s|postgresql://localhost:5432|postgresql://$PGHOST:$PGPORT|g" $PENTAHO_SERVER/pentaho-solutions/system/simple-jndi/jdbc.properties
fi

# Use postgreql for jackrabbit
if grep -q postgresql://localhost:5432 $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml; then
cp $PENTAHO_HOME/config/repository.xml $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml
sed -i "s|postgresql://localhost:5432|postgresql://$PGHOST:$PGPORT|g" $PENTAHO_SERVER/pentaho-solutions/system/jackrabbit/repository.xml
fi

# Use postgresql for tomcat (quartz / hibernate)
if grep -q hsqldb $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml; then
cp $PENTAHO_HOME/config/context.xml $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml
sed -i "s|jdbc:postgresql://localhost:5432/|jdbc:postgresql://$PGHOST:$PGPORT/|g" $PENTAHO_SERVER/tomcat/webapps/pentaho/META-INF/context.xml
fi
fi