Feature: database choice between HSQLDB, Oracle, MySQL and PostgreSQL as environment variable

This commit is contained in:
fecaille
2016-04-08 13:58:07 +02:00
parent 3380efa377
commit 6b9b2bb964
5 changed files with 54 additions and 16 deletions

View File

@@ -5,9 +5,11 @@ ARG JETTY_MAJOR=stable-9
ARG JETTY_VERSION=9.3.8.v20160314 ARG JETTY_VERSION=9.3.8.v20160314
ENV JETTY_BASE /usr/local/jetty ENV JETTY_BASE /usr/local/jetty
ENV MYSQL_USER xwiki ENV DB_TYPE hsqldb
ENV MYSQL_PASSWORD dbpass ENV DB_USER sa
ENV MYSQL_HOST db ENV DB_PASSWORD ''
ENV DB_HOST db
ENV WIKI_CONTEXT xwiki ENV WIKI_CONTEXT xwiki
ENV ADMIN_EMAIL '' ENV ADMIN_EMAIL ''
ENV SMTP_HOST '' ENV SMTP_HOST ''
@@ -29,8 +31,11 @@ RUN curl -sL http://download.forge.ow2.org/xwiki/xwiki-enterprise-web-${XWIKI_VE
mkdir -p ${JETTY_BASE}/webapps/ROOT/ && \ mkdir -p ${JETTY_BASE}/webapps/ROOT/ && \
unzip -q ${JETTY_BASE}/xwiki${XWIKI_VERSION}.war -d ${JETTY_BASE}/webapps/ROOT/ && \ unzip -q ${JETTY_BASE}/xwiki${XWIKI_VERSION}.war -d ${JETTY_BASE}/webapps/ROOT/ && \
rm ${JETTY_BASE}/xwiki${XWIKI_VERSION}.war && \ rm ${JETTY_BASE}/xwiki${XWIKI_VERSION}.war && \
curl -sL http://central.maven.org/maven2/org/hsqldb/hsqldb/2.3.3/hsqldb-2.3.3.jar --output ${JETTY_BASE}/webapps/ROOT/WEB-INF/lib/hsqldb-2.3.3.jar && \
curl -sL http://central.maven.org/maven2/org/postgresql/postgresql/9.4.1208/postgresql-9.4.1208.jar --output ${JETTY_BASE}/webapps/ROOT/WEB-INF/lib/postgresql-9.4.jar && \
curl -sL http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar --output ${JETTY_BASE}/webapps/ROOT/WEB-INF/lib/mysql-connector-java-5.jar curl -sL http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar --output ${JETTY_BASE}/webapps/ROOT/WEB-INF/lib/mysql-connector-java-5.jar
ADD binaries/ojdbc7.jar ${JETTY_BASE}/webapps/ROOT/WEB-INF/lib/ojdbc7.jar
RUN rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /usr/share/doc/* RUN rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /usr/share/doc/*

View File

@@ -3,9 +3,10 @@
Create a xwiki instance with jetty webserver Create a xwiki instance with jetty webserver
Use the following ENV when running : Use the following ENV when running :
- MYSQL_USER : the mysql user - DB_TYPE : the type of database. Supported databases : HSQLDB / Oracle / MySQL / PostgreSQL. HSQLDB is stored in the folder defined by the XWiki environment.permanentDirectory variable.
- MYSQL_PASSWORD : the mysql password - DB_USER : the database user (not needed for HSQLDB)
- MYSQL_HOST : the hostname of the linked database container - DB_PASSWORD : the database password (not needed for HSQLDB)
- DB_HOST : the hostname of the linked database container (not needed for hsqldb)
- WIKI_CONTEXT : the context of the website (ROOT for no context) - WIKI_CONTEXT : the context of the website (ROOT for no context)
- ADMIN_EMAIL : the email of the administrator - ADMIN_EMAIL : the email of the administrator
- SMTP_HOST : smtp host to send email from - SMTP_HOST : smtp host to send email from

BIN
binaries/ojdbc7.jar Normal file

Binary file not shown.

View File

@@ -14,11 +14,12 @@
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property> <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.url">jdbc:mysql://MYSQL_HOST/xwiki</property> <property name="connection.url">DB_HOST</property>
<property name="connection.username">MYSQL_USER</property> <property name="connection.username">DB_USER</property>
<property name="connection.password">MYSQL_PASSWORD</property> <property name="connection.password">DB_PASSWORD</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.driver_class">DB_DRIVER_CLASS</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="dialect">DB_DIALECT</property>
DB_OPTIONAL
<property name="dbcp.poolPreparedStatements">true</property> <property name="dbcp.poolPreparedStatements">true</property>
<property name="dbcp.maxOpenPreparedStatements">20</property> <property name="dbcp.maxOpenPreparedStatements">20</property>
<mapping resource="xwiki.hbm.xml"/> <mapping resource="xwiki.hbm.xml"/>
@@ -28,4 +29,3 @@
<mapping resource="mailsender.hbm.xml"/> <mapping resource="mailsender.hbm.xml"/>
</session-factory> </session-factory>
</hibernate-configuration> </hibernate-configuration>

View File

@@ -3,10 +3,42 @@
if [ "$WIKI_CONTEXT" != "" ];then if [ "$WIKI_CONTEXT" != "" ];then
if [ ! -f "${JETTY_BASE}/webapps/${WIKI_CONTEXT}" ];then if [ ! -f "${JETTY_BASE}/webapps/${WIKI_CONTEXT}" ];then
mv ${JETTY_BASE}/webapps/ROOT ${JETTY_BASE}/webapps/${WIKI_CONTEXT} mv ${JETTY_BASE}/webapps/ROOT ${JETTY_BASE}/webapps/${WIKI_CONTEXT}
#curl http://download.forge.ow2.org/xwiki/xwiki-enterprise-web-8.0-milestone-2.war --output webapps/xwiki8.war
sed -i "s|MYSQL_HOST|${MYSQL_HOST}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml DB_OPTIONAL=''
sed -i "s|MYSQL_USER|${MYSQL_USER}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml DB_DRIVER_CLASS=''
sed -i "s|MYSQL_PASSWORD|${MYSQL_PASSWORD}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml DB_DIALECT=''
case ${DB_TYPE} in
'hsqldb')
DB_DIALECT='org.hibernate.dialect.HSQLDialect'
DB_DRIVER_CLASS='org.hsqldb.jdbcDriver'
DB_HOST='jdbc:hsqldb:file:${environment.permanentDirectory}/database/xwiki;shutdown=true'
;;
'mysql')
DB_DIALECT='org.hibernate.dialect.MySQLDialect'
DB_DRIVER_CLASS='com.mysql.jdbc.Driver'
DB_HOST="jdbc:mysql://${DB_HOST}/xwiki?useServerPrepStmts=false\&amp;sessionVariables=sql_mode=''"
;;
'oracle')
DB_DIALECT='org.hibernate.dialect.Oracle10gDialect'
DB_DRIVER_CLASS='oracle.jdbc.driver.OracleDriver'
DB_HOST="jdbc:oracle:thin:${DB_HOST}:1521:xwiki"
DB_OPTIONAL='<property name="hibernate.connection.SetBigStringTryClob">true</property><property name="hibernate.jdbc.batch_size">0</property>'
;;
'postgresql')
DB_DIALECT='org.hibernate.dialect.PostgreSQLDialect'
DB_DRIVER_CLASS='org.postgresql.Driver'
DB_HOST="jdbc:postgresql://${DB_HOST}/xwiki"
;;
esac
sed -i "s|DB_HOST|${DB_HOST}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
sed -i "s|DB_USER|${DB_USER}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
sed -i "s|DB_PASSWORD|${DB_PASSWORD}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
sed -i "s|DB_DRIVER_CLASS|${DB_DRIVER_CLASS}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
sed -i "s|DB_DIALECT|${DB_DIALECT}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
sed -i "s|DB_OPTIONAL|${DB_OPTIONAL}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/hibernate.cfg.xml
if [[ "${SMTP_HOST}" != "" ]]; then if [[ "${SMTP_HOST}" != "" ]]; then
sed -i "s|.*mail\.sender\.host = .*|mail.sender.host = ${SMTP_HOST}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/xwiki.properties sed -i "s|.*mail\.sender\.host = .*|mail.sender.host = ${SMTP_HOST}|" ${JETTY_BASE}/webapps/${WIKI_CONTEXT}/WEB-INF/xwiki.properties
fi fi