如何使用 Maven 在 OpenShift 上构建和部署 Fuse 7 应用程序

x33g5p2x  于2022-09-28 转载在 Maven  
字(3.0k)|赞(0)|评价(0)|浏览(641)

在本教程中,我们将学习如何仅使用 Maven 命令行在 OpenShift 上创建和部署 Red Hat Fuse 应用程序 作为 Spring Boot 应用程序

在开始之前,您需要完成以下步骤:

  • 在 OpenShift 4.x 服务器上安装 Fuse Imagestreams 和模板。 ImageStrams 是一个 OpenShift API 对象,表示相关图像的单个虚拟视图。 (请注意,要安装 Fuse Imagestreams 和 Templates,您必须具有 OpenShift 项目的管理员角色。)。安装图片流和模板可以参考脚本:https://github.com/rahmed-rh/fuse_on_OCP_7.5/blob/master/scripts/install_fis_7.5.sh
  • 确保您已配置 Maven 存储库 列表,以便您可以访问 Fuse 原型。 (settings.xml 的示例可用 here

使用 Maven 设置 Fuse 7 项目

通过运行以下命令创建一个新的 Fuse-Spring Boot 2 应用程序,这将从 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

您将被要求完成项目 GAV,因此:

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

以下是原型为您创建的内容:

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

我需要应用于 pom.xml 的唯一更改与 fabric8 Maven 插件有关。事实上,使用项目中包含的 fabric8 插件版本,我面临以下错误:

[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]

只需将 openshift 配置文件中包含的插件切换为以下插件:

<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>

现在,一旦您的 OpenShift 集群启动并运行,为项目创建一个新的命名空间:

oc new-project test

现在,从您的 Fuse 项目目录中,使用 fabric8 插件部署 Fuse 项目:

mvn fabric8:deploy -Popenshift

几分钟后,您的项目将可用。检查其 Pod 的可用性:

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

如果您检查项目的日志,您将看到 Route 已被激活,只要 Pod 已启动:

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

恭喜,您刚刚成功地在 OpenShift 上使用 Maven 命令行运行了一个基本的 Fuse 7 Spring Boot 应用程序!

此处提供源代码:https://github.com/fmarchioni/masteringintegration/tree/master/fuse/fuse7-spring-boot

相关文章

微信公众号

最新文章

更多