Dec 8, 2019 10:28:42 PM Thomas Dumont avatar

Deploy on Openshift

openshift

Use openshift to host lutece apps: https://www.openshift.com/ create an account on the website, then use the rhc command line tool https://developers.openshift.com/en/managing-client-tools.html

  • Create a tomcat7 app:
    $ rhc create-app demo jbossews-2.0
  • Add mysql
    $ rhc cartridge-add -a demo mysql-5.5

Either set an environnement variable with rhc for this app

$ rhc env-set -a demo -e MAVEN_ARGS="clean lutece:site-assembly -Popenshift"
Or alternatively, you should also be able to add the following executable file to the repo so that it works with every open shift app

$ ls -l .openshift/action_hooks/pre_build
-rwxrwxr-x 1 jon jon 47 juil. 21 19:39 .openshift/action_hooks/pre_build

$ cat .openshift/action_hooks/pre_build 
export MAVEN_ARGS="clean lutece:site-assembly -Popenshift"

  • edit default server.xml to unpackWars:
    diff --git a/.openshift/config/server.xml b/.openshift/config/server.xml
    index 70f0514..727be57 100644
    --- a/.openshift/config/server.xml
    +++ b/.openshift/config/server.xml
    @@ -124,7 +124,7 @@
           </Realm>
    
           <Host name="localhost"  appBase="webapps"
    -            unpackWARs="false" autoDeploy="true">
    +            unpackWARs="true" autoDeploy="true">
    
             <!-- SingleSignOn valve, share authentication between web applications
                  Documentation at: /docs/config/valve.html -->
  • use the openshift default tomcat connection pool:
    diff --git a/webapp/WEB-INF/conf/db.properties b/webapp/WEB-INF/conf/db.properties
    new file mode 100644
    index 0000000..b3d7a07
    --- /dev/null
    +++ b/webapp/WEB-INF/conf/db.properties
    @@ -0,0 +1,2 @@
    +portal.poolservice=fr.paris.lutece.util.pool.service.TomcatConnectionService
    +portal.ds=jdbc/MySQLDS
  • Generate the war in the correct folder with the correct name:
    diff --git a/pom.xml b/pom.xml
    index bd894b7..6efadfe 100644
    --- a/pom.xml
    +++ b/pom.xml
    @@ -48,6 +48,23 @@
                     </plugins>
                 </build>
             </profile>
    +        <profile>
    +            <id>openshift</id>
    +            <build>
    +                <plugins>
    +                    <plugin>
    +                        <groupId>fr.paris.lutece.tools</groupId>
    +                        <artifactId>lutece-maven-plugin</artifactId>
    +                        <version>4.0.1</version>
    +                        <extensions>true</extensions>
    +                        <configuration>
    +                           <finalName>ROOT</finalName>
    +                           <outputDirectory>webapps</outputDirectory>
    +                        </configuration>
    +                    </plugin>
    +                </plugins>
    +            </build>
    +        </profile>
         </profiles>
         <repositories>
             <repository>
  • upload an initial database dump:
    $ rhc scp demo upload sitedemo.sql app-root/data
    To get the initial database dump, you can for example launch the site on the local machine (mvn lutece:site-assembly, configure the database, run ant in the target/WEB-INF/sql folder), and run mysqldump.
  • ssh and load the dump
    $ rhc ssh demo
    $ mysql demo < app-root/data/sitedemo.sql
  • git commit and push everything (if there is a timeout during the build on openshift, add a newline to a file and push again)