naif hussain
naif hussain

Reputation: 1

Hosting XWIKI on Azure Webapps

Can we host XWIKI on Azure WebApps? Possible ways are to push docker images to the Azure container registry and host it on web apps, but this way it generates several errors. HTTP ERROR 404

I Used Docker-Image on docker hub docker image containerized it and tried hosting it on Azure since it worked well on my localhost I expect it to work fine on Azure but it won't work since the pre-built images and other configurations are made to run on local host and need extensive modifications and understanding to make it compatible to run on azure this is where I need help. I tried making some changes to files like hibernate.cfg.xml and some .env and docker-compose.yml files but all ended up with no signs of hope. I am expecting if someone had worked on this and figured out how to do this would help me a lot.

Problem: The pre-built docker image on docker hub is configured to work on localhost but there are no resource or documentation on how to get it hosted on azure web Apps. this is docker-compose.yml file as per the information it is configured to work on local host but I want to run xwiki on azure webapps and want to figure our how can I do that, Azure web Apps runs on port 80 even if I use expose 80 as host it doesn't work.

# ---------------------------------------------------------------------------
# See the NOTICE file distributed with this work for additional
# information regarding copyright ownership.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
# ---------------------------------------------------------------------------
version: '2'
networks:
  bridge:
    driver: bridge
services:
  # The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for mysql).
  web:
    image: "xwiki:${XWIKI_VERSION}-mysql-tomcat"
    container_name: xwiki-mysql-tomcat-web
    depends_on:
      - db
    ports:
      - "8080:8080"
    # Default values defined in .env file.
    # The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
    environment:
      - XWIKI_VERSION=${XWIKI_VERSION}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_DATABASE=${DB_DATABASE}
      - DB_HOST=xwiki-mysql-db
    # Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
    # configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
    volumes:
      - xwiki-data:/usr/local/xwiki
    networks:
      - bridge
  # The container that runs the database (mysql)
  db:
    image: "mysql:8.3"
    container_name: xwiki-mysql-db
    # - Provide a name instead of an auto-generated id for the mysql data, to make it simpler to identify in
    # 'docker volume ls'
    # - Provide a SQL script to be executed when the db image starts (to set permissions to create subwikis)
    volumes:
      - mysql-data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql

    # Configure the MySQL database and create a user with provided name/password.
    # See https://hub.docker.com/_/mysql/ for more details.
    # Default values defined in .env file.
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=${DB_DATABASE}

    # Pass arguments to configure the database
    command:
      - "--character-set-server=utf8mb4"
      - "--collation-server=utf8mb4_bin"
      - "--explicit-defaults-for-timestamp=1"
    networks:
      - bridge
volumes:
  mysql-data: {}
  xwiki-data: {}

and this is hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>

    <!-- Please refer to the installation guide on
         https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/ for configuring your
         database. You'll need to do 2 things:
         1) Copy your database driver JAR in WEB-INF/lib or in some shared lib directory
         2) Uncomment the properties below for your specific DB (and comment the default
            database configuration if it doesn't match your DB)
    -->

    <!-- Generic parameters common to all Databases -->

    <property name="show_sql">false</property>
    <property name="use_outer_join">true</property>

    <!-- Without it, some queries fail in MS SQL. XWiki doesn't need scrollable result sets, anyway. -->
    <property name="jdbc.use_scrollable_resultset">false</property>

    <!-- DBCP Connection Pooling configuration. Only some properties are shown. All available properties can be found
         at https://commons.apache.org/proper/commons-dbcp/configuration.html
    -->
    <property name="dbcp.defaultAutoCommit">false</property>
    <property name="dbcp.maxTotal">50</property>
    <property name="dbcp.maxIdle">5</property>
    <property name="dbcp.maxWaitMillis">30000</property>
    <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>

    <!-- Setting "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" will tell DBCP to cache
         Prepared Statements (it's off by default). Note that for backward compatibility the "dbcp.ps.maxActive" is also
         supported and when set it'll set "dbcp.poolPreparedStatements" to true and "dbcp.maxOpenPreparedStatements" to
         value of "dbcp.ps.maxActive".

         Note 1: When using HSQLDB for example, it's important to NOT cache prepared statements because HSQLDB
         Prepared Statements (PS) contain the schema on which they were initially created and thus when switching
         schema if the same PS is reused it'll execute on the wrong schema! Since HSQLDB does internally cache
         prepared statement there's no performance loss by not caching Prepared Statements at the DBCP level.
         See https://jira.xwiki.org/browse/XWIKI-1740.
         Thus we recommend not turning on this configuration for HSQLDB unless you know what you're doing :)

         Note 2: The same applies to PostGreSQL.
    -->

    <!-- BoneCP Connection Pooling configuration.
    <property name="bonecp.idleMaxAgeInMinutes">240</property>
    <property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>
    <property name="bonecp.partitionCount">3</property>
    <property name="bonecp.acquireIncrement">10</property>
    <property name="bonecp.maxConnectionsPerPartition">60</property>
    <property name="bonecp.minConnectionsPerPartition">20</property>
    <property name="bonecp.statementsCacheSize">50</property>
    <property name="bonecp.releaseHelperThreads">3</property>
    <property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
    -->

    <!-- MySQL configuration.
         Notes:
           - If you want the main wiki database to be different than "xwiki"
             you will also have to set the property xwiki.db in xwiki.cfg file
           - Use the local timezone to work around a bug in the MySQL 8.x which often does not understand the server
              timezone and crash
    -->
    <property name="connection.url">jdbc:mysql://replacecontainer/replacedatabasereplacejdbcparams</property>
    <property name="connection.username">replaceuser</property>
    <property name="connection.password">replacepassword</property>
    <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
    <property name="dbcp.poolPreparedStatements">true</property>
    <property name="dbcp.maxOpenPreparedStatements">20</property>

    <property name="hibernate.connection.charSet">UTF-8</property>
    <property name="hibernate.connection.useUnicode">true</property>
    <property name="hibernate.connection.characterEncoding">utf8</property>

    <mapping resource="xwiki.hbm.xml"/>
    <mapping resource="feeds.hbm.xml"/>
    <mapping resource="instance.hbm.xml"/>
    <mapping resource="notification-filter-preferences.hbm.xml"/>
    <mapping resource="mailsender.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

rest of the files you can check on github as well https://github.com/xwiki/xwiki-docker/tree/master/16/mysql-tomcatGithub Repository

Upvotes: 0

Views: 232

Answers (1)

Suresh Chikkam
Suresh Chikkam

Reputation: 3262

Here I have taken Azure database MySQL in the place of MySQL.

enter image description here

From the connection for JDBC we can connect with our application.

docker-compose.yml:

version: '2'
services:
  web:
    build: .
    ports:
      - "8080:8080"
    environment:
      - XWIKI_VERSION=${XWIKI_VERSION}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_DATABASE=${DB_DATABASE}
      - DB_HOST=<azure_mysql_host>
    volumes:
      - xwiki-data:/usr/local/xwiki
  db:
    image: "mysql:8.3"
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${DB_USER}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=${DB_DATABASE}
volumes:
  xwiki-data: {}
  • Use the above compose file for new Azure MySQL connection and adjust it to match the Azure Web Apps environment.

hibernate.cfg.xml:

<hibernate-configuration>
  <session-factory>

    <!-- MySQL configuration -->
    <property name="connection.url">jdbc:mysql://<azure_mysql_host>:<azure_mysql_port>/<database_name>?useSSL=false&amp;serverTimezone=UTC&amp;characterEncoding=UTF-8</property>
    <property name="connection.username">your_mysql_username</property>
    <property name="connection.password">your_mysql_password</property>
    <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
    <property name="dbcp.poolPreparedStatements">true</property>
    <property name="dbcp.maxOpenPreparedStatements">20</property>

    <property name="hibernate.connection.charSet">UTF-8</property>
    <property name="hibernate.connection.useUnicode">true</property>
    <property name="hibernate.connection.characterEncoding">utf8</property>

  </session-factory>
</hibernate-configuration>
  • While creating webapp we can configure MySQL direct to our webapp.

enter image description here

Connection with the Docker Hub:

enter image description here

Azure web Apps runs on port 80 even if I use expose 80 as host it doesn't work.

Now it will work as if you follow the above configuration.

Upvotes: 0

Related Questions