How to build and deploy Fuse 7 applications on OpenShift with Maven



In this tutorial we will learn how to create and deploy a Red Hat Fuse application as Spring Boot application on OpenShift using just the Maven command line.

Before getting started, you need to complete the following steps:

  • Install the Fuse Imagestreams and Templates on the OpenShift 4.x server. ImageStrams is an OpenShift API object that represents single virtual view of related images. (Please note that to install Fuse Imagestreams and Templates, you must have the administrator role for the OpenShift project.). You can refer to script for installing image streams and templates: https://github.com/rahmed-rh/fuse_on_OCP_7.5/blob/master/scripts/install_fis_7.5.sh
  • Make sure you have configured the Maven repository list so that you can reach Fuse archetype. (An example of settings.xml is available here)

Setting up your Fuse 7 project with Maven

Create a new Fuse-Spring Boot 2 application by running the following command, which will create a basic project from the spring-boot-camel-xml-archetype

mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \
  -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \
  -DarchetypeArtifactId=spring-boot-camel-xml-archetype \
  -DarchetypeVersion=2.2.0.fuse-740017-redhat-00003

You will be requested to complete the project GAV, therefore:

Define value for property 'groupId': : org.sample
Define value for property 'artifactId': : fuse-spring-boot
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  org.sample: : 
Confirm properties configuration:
groupId: org.sample
artifactId: fuse-spring-boot
version: 1.0-SNAPSHOT
package: org.sample
 Y: : Y

Here is what the archetype has created for you:

src
├── data
├── main
│   ├── fabric8
│   │   └── deployment.yml
│   ├── java
│   │   └── org
│   │       └── sample
│   │           ├── Application.java
│   │           └── MyTransformer.java
│   └── resources
│       ├── application.properties
│       ├── logback.xml
│       └── spring
│           └── camel-context.xml
└── test
    └── java
        └── org
            └── sample

The only change I needed to apply to the pom.xml is related to the fabric8 Maven plugin. As a matter of fact, with the version of fabric8 plugin included in the project, I'm facing the following error:

[ERROR] Failed to execute goal org.jboss.redhat-fuse:fabric8-maven-plugin:7.4.0.fuse-740036-redhat-00002:build (default) on project fuse-spring-boot: Failed to execute the build: Unable to build the image using the OpenShift build service: OpenShift Build fuse-spring-boot-s2i-1: Failed: GenericBuildFailed -> [Help 1]

Just switch the plugin, contained in the openshift profile, to the following one:

<profile>
   <id>openshift</id>
   <build>
      <plugins>
         <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>4.4.1</version>
            <executions>
               <execution>
                  <goals>
                     <goal>resource</goal>
                     <goal>build</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</profile>

Now, once that your OpenShift cluster is up and running, create a new namespace for the project:

oc new-project test

Now, from the directory of your Fuse project, use the fabric8 plugin to deploy the Fuse project:

mvn fabric8:deploy -Popenshift

In a matter of minutes your project will be available. Check the availability of its Pod:

oc get pods
NAME                             READY        STATUS   RESTARTS   AGE
fuse74-spring-boot                 1/1      Running    0          1m

If you inspect the logs of your Project, you will see that the Route has been activated, as soon as the Pod has been started:

07:29:36.603 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 320
07:29:38.603 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 222
07:29:40.603 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 267
07:29:42.604 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 531
07:29:44.604 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 557
07:29:46.605 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 821
07:29:48.604 [Camel (MyCamel) thread #1 - timer://foo] INFO  simple-route - >>> 642

Congratulations, you have just managed to run your a basic Fuse 7 Spring Boot application on the top of OpenShift with just Maven command line!

Source code available here: https://github.com/fmarchioni/masteringintegration/tree/master/fuse/fuse7-spring-boot

FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials
Cookie Policy

Cookie Policy This website uses cookies that are necessary to its functioning and required to achieve the purposes illustrated in the privacy policy. By accepting this OR scrolling this page OR continuing to browse, you agree to our privacy policy.

© 2020 Your Company. All Rights Reserved. Designed By JoomShaper

Please publish modules in offcanvas position.