“Fast-Deploy”. HowTo deploy Cuba-platform over Openshift Paas with postgres db.

Deploy Cuba-platform app on Openshift with Tomcat 8 server running jdk8 and set connection with Postgres 9.2 db.
Install and setup.
1. Create diy and postgres cartridges

From host host :
rhc app create diy cuba
rhc cartridge add postgresql-9.2 –a cuba
2. Install Apache Tomcat 8

Openshift not let deploy one step Tomcat8, so it will operate manually.
SSH your server (I use Putty from Windows).
Donwload Tomcat8 :

cd $OPENSHIFT_DATA_DIR
mkdir tomcat8
wget http://mirror.sdunix.com/apache/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz
tar –xvzf apache-tomcat-8.0.33.tar.gz tomcat8

3. Cuba-platform app server files required.

Main files:
In {cuba-app}/build/tomcat/webapps app and app-core.
In {cuba-app}/build/tomcat/lib jdbc postgres driver.
In {cuba-app}/build/tomcat/shared/lib all cuba-platform libraries.
We have several choices to put them in our $OPENSHIFT_DATA_DIR:
• Clone your {cuba-app}/build/tomcat from a git reository
• Ftps: upload {cuba-app} source code, and use buildTomcat and deploy tasks, you will require gradle2.6
• Ftps: upload directly {cuba-app}/build/tomcat

Move main files to the appropiate directories.
Shared libs can live in the tomcat/ lib folder, if you want have shared libs in a sepparate folder, you must denote it in tomcat/conf/catalina.propeties (line common.loader).
4. Set addressing.

cd $OPENSHIFT_DATA_DIR/tomcat8
• conf/server.xml: replace server ip and host dns (you can remove this line).
Ports configuration its ok, Openshift just let use ports over 18000 except for 8080 port.
(Openshift forward directly 8080 to 80 port)

<?xml version='1.0' encoding='utf-8'?>
<Server address="<<Put your server IP>>" port="18005"  shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector address="<<Put your server IP>>" port="8080"  protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="18443" />
    <Connector address="<<Put your server IP>>" port="18009"  protocol="AJP/1.3" redirectPort="18443" />
    <Engine name="Catalina" defaultHost="<<Put your server IP>>">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="<<Put here your DNS>>"  appBase="webapps"
            unpackWARs="false" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

• webapps/app-core/META-INF/context.xml :

<Context>
    <!-- Database connection -->
    <Resource driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
              name="jdbc/CubaDS"
              password="<<Postgres password>>"
              type="javax.sql.DataSource"
              url="jdbc:postgresql://<<YOUR SERVER IP>/<YOUR POSTGRES DATABASE NAME>"
              username="<<Postgres username>>"/>
    <Manager pathname=""/>
</Context>

5. Set start and stop action hook.

In the folder created on step 1 remove all dirs less .openshift.
Overwrite {host}/cuba/.openshift/action_hooks/start with

#!/bin/bash
set -x
cd $OPENSHIFT_DATA_DIR
	cd apache8 /bin
	./startup.sh

And {host}/cuba/.openshift/action_hooks/stop with

#!/bin/bash
set -x
cd $OPENSHIFT_DATA_DIR

	cd apache8 /bin
	./shutdown.sh

Then:

git add .
git commit –m “change action_hooks”
git push

Now go your http://openshift-url/app, you will have a Cuba-platform running on your Openshift diy gear.
If you want put the app on the Root directory check this link[url=] https://doc.cuba-platform.com/manual-6.0/tomcat_in_prod.html[/url]

I write this guide cause I had many troubles to deploy cuba copying directly all tomcat server files to my server.
Hope help you.

Hi Ismael,

Thank you for sharing your experience and detailed guide, I’m sure it will be helpful for the community!

Regards,
Aleksey