如何在OpenShift上部署多模块Maven Spring Boot应用程序

编程入门 行业动态 更新时间:2024-10-11 05:22:42
本文介绍了如何在OpenShift上部署多模块Maven Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个要在 Openshift 上部署的多模块spring-boot项目.还安装了Jenkins.源代码托管在Github中. 每个模块都包含一场战争,以拥有微服务结构:

I have a multi-module spring-boot project that I want to deploy on Openshift, where I have installed Jenkins as well. Source code is hosted in Github. Each module consists in a war, in order to have a microservices structure:

<modules> <module>xyz-common</module> <module>xyz-data-services</module> <!--a REST service to interact with mongodb--> <module>xyz-batch-importer</module> <!--a service to import files into Mongo--> <module>xyz-frontend</module> </modules>

我发现了用于部署单个spring-boot应用程序的教程,但是我无法弄清楚它如何应用于多模块maven项目.

I found tutorial to deploy single spring-boot application, but I cannot figure out how this applies to a multi-module maven project.

推荐答案

如果要在openshift上使用多模块maven项目,则必须告诉openshift如何构建它们.您可以通过定义构建环境变量或编写可由Openshift解释的自定义构建脚本来完成此任务.

If you want to work with multi-module maven project on openshift, then you have to tell openshift how to build them. You can achieve this task by defining build environment variables or writing custom build scripts which can be interpreted by Openshift.

对于这两种方法,您都可以遵循此教程:

For both method you can follow this tutorial:

如果要使用第一种方法,则可以通过为构建配置定义"MAVEN_ARGS_APPEND"变量来告诉openshift在构建过程中使用其他maven命令.

If you want to work with first method, you can tell openshift to use additional maven commands while building process by defining "MAVEN_ARGS_APPEND" variable for build config.

因此,当构建操作从openshift开始时,它将告诉Maven使用这些附加参数来构建应用程序.

So when the build operation starts on openshift, it will tell Maven that build the application with these additional parameters.

定义以下列出的其他构建环境变量,以独立部署战争模块:

Define additional build environment variables that listed below to deploy war modules independently:

MAVEN_ARGS_APPEND:-pl模块名称--also-make

MAVEN_ARGS_APPEND: -pl modulename --also-make

ARTIFACT_DIR:模块名称/目标/

ARTIFACT_DIR: modulename/target/

MODULE_DIR:模块名

MODULE_DIR: modulename

在这里,-pl"命令提供了构建"xyz-data-services"及其所有依赖项的功能.因此,如果您的"xyz-data-services"模块依赖于"xyz-common",那么maven将构建"xyz-common",为"xyz-data-services"创建相关工件,将它们打包在一起并部署"xyz-common"数据服务"作为对客舱的战争.

In here "-pl" command provides to build "xyz-data-services" with its all dependencies. So if your "xyz-data-services" module has dependency to "xyz-common", then maven will build "xyz-common", create related artifacts for "xyz-data-services" ,package them together and deploy "xyz-data-services" as war on the pod.

以您为例,假设您要将"xyz-data-services"模块和"xyz-front-end"模块打包为war并进行部署.

In your case, suppose that you want to package "xyz-data-services" module and "xyz-front-end" module as war and deploy them.

情况1:

如果要使这些模块可自行部署,则必须创建两个将在不同Pod上运行的应用程序.

If you want to make these modules self deployable, then you have to create two applications which will run on different pods.

第一个应用程序将具有以下构建环境变量:

First application will have these build environment variables:

MAVEN_ARGS_APPEND: -pl xyz-data-services --also-make ARTIFACT_DIR: xyz-data-services/target/ MODULE_DIR: xyz-data-services

第二个人将有这些人:

MAVEN_ARGS_APPEND: -pl xyz-front-end --also-make ARTIFACT_DIR: xyz-front-end/target/ MODULE_DIR: xyz-front-end

情况2:

如果要将这些模块部署到同一吊舱中,则可以在项目中添加一个附加模块,该模块将两次大战都打包成一个耳朵,并为此耳朵定义变量.

If you want to deploy these modules into same pod, then you can add an additional module to your project which packages both wars into single ear and define the variables for this ear.

因此,让这个耳朵成为"webapp",您的父pom会看起来像这样;

So let this ear be "webapp", your parent pom will look like;

... <modules> <module>xyz-common</module> <module>xyz-data-services</module> <module>xyz-batch-importer</module> <module>xyz-frontend</module> <module>xyz-webapp</module> </modules> ...

和xyz-webapp pom看起来像;

and the xyz-webapp pom will look like;

.... <artifactId>xyz-webapp-</artifactId> <dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>xyz-common</artifactId> <version>${project.version}</version> <type>jar</type> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>xyz-data-services</artifactId> <version>${project.version}</version> <type>war</type> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>xyz-frontend</artifactId> <version>${project.version}</version> <type>war</type> </dependency> </dependencies> ....

因此您的构建环境变量将为;

So your build environment variables will be;

MAVEN_ARGS_APPEND: -pl xyz-webapp --also-make ARTIFACT_DIR: xyz-webapp/target/ MODULE_DIR: xyz-webapp

如果您只想使用单个战争和单个吊舱,那么;

If you want to work with just single war and single pod then;

情况3:

您可以将前端应用程序打包为war并声明对所有其他模块的依赖关系,而这些其他模块都打包为".jars"

You can just package front-end application as war and declare dependencies to other modules which all packaged as ".jars"

您可以继续使用哪种情况.在此重要的是,这取决于您的微服务"实现.由于未明确定义微服务"一词及其实现,并且可能会因体系结构或某些业务需求而异,因此您需要决定将前端,api,后端打包在一起或独立管理它们.

You can go on with which case do you want. It's important here that it depends on your "microservices" implementation. Because the "microservice" term and the implementation is not explicitly defined and it can vary on the architecture or some business requirements, it's your decision that packaging front-end,api,backend together or manage them independently.

更多推荐

如何在OpenShift上部署多模块Maven Spring Boot应用程序

本文发布于:2023-10-28 10:53:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   多模   如何在   OpenShift   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!