通过Maven for Spring Boot应用程序为AWS Beanstalk创建.ebextensions的正确方法是什么 [英] What is the proper way to create .ebextensions for AWS Beanstalk through maven for Spring Boot app

查看:330
本文介绍了通过Maven for Spring Boot应用程序为AWS Beanstalk创建.ebextensions的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须在GitLab CI/CD管道中在Spring Boot应用程序的动态生成的Elastic Beanstalk实例中自定义 hosts 文件.为此,我们需要提供一个 .ebextensions 目录,并带有一个如下所示的配置文件:

We have to customize hosts file in our dynamically generated Elastic Beanstalk instance of our Spring Boot application during our GitLab CI/CD pipeline. To do this, we need to provide a .ebextensions directory with a config file that looks like this:

commands:
  01_add_hosts:
    command: echo 123.12.12.123 myhost.com >> /etc/hosts

因为我们有一个Spring Boot应用程序,所以我们必须在胖子的根目录下打包 .ebextensions .因此,基本上,我们将jar解压缩,添加ebextensions目录,然后将其压缩回去.这样,我们就可以在Gitlab管道中成功实现Beanstalk定制.

Since we have a spring boot application, we have to package .ebextensions at the root level of our fat jar. So, basically we unzip the jar, add the ebextensions directory and zip it back. This way we successfully achieve the Beanstalk customization in our Gitlab pipelines.

但是,要进行此过程,我们使用 maven-antrun-plugin 这样:

However, to make this process we use maven-antrun-plugin like this:

<!-- Bundle .ebextensions inside jar -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>prepare</id>
            <phase>package</phase>
            <configuration>
                <tasks>
                    <unzip src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.directory}/${project.build.finalName}" />
                    <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
                        <fileset dir="./" includes=".ebextensions/**"/>
                    </copy>
                    <zip compress="false" destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.build.finalName}"/>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

问题是 maven-antrun-plugin 是2014年的旧插件,这似乎不是实现此捆绑罐的正确方法.

The problem is that maven-antrun-plugin is and old plugin from 2014 and this looks like not the proper way to achieve this bundle jar.

您是如何或通过什么方式来创建此捆绑罐的弹簧启动方式?我的意思是在春季启动时在jar的根目录级别添加目录/文件?请记住,我们在通过AWS Beanstalk maven插件部署的管道作业时间将其捆绑在一起.

Do you how or what it is the spring boot way to create this bundle jar? I mean add directories/files at the root level of the jar in spring boot? Bear in mind that we bundle this at our pipeline job time that deploys through AWS Beanstalk maven plugin.

推荐答案

是否只需要将一个jar上载到弹性beantalk?我们的方法是上传一个zip文件,其中包含我们的胖子jar,.ebextensions目录和Procfile.这样就可以应用ebextensions,并且Procfile包含启动Java进程的命令.

Is it required that you upload only a jar to elastic beanstalk? The way we do it is that we upload a zipfile, containing our fat jar, a .ebextensions directory and a Procfile. This way the ebextensions get applied and the Procfile contains the command to start the java process.

例如,您可以上传包含以下内容的hello-world.zip

So for example you could upload hello-world.zip containing:

  • .ebextensions:
    • hosts.config

    Procfile是一个包含以下内容的文本文件:

    With Procfile being a text file containing:

    网络:java -jar hello-world.jar

    web: java -jar hello-world.jar

    如果您这样做,则无需在应用程序jar中嵌入ebextension文件,这使事情变得非常简单.

    If you do it like this, there's no need to embed your ebextension files in your application jar, which makes things a whole lot easier in my opinion.

    Procfile文档

    这篇关于通过Maven for Spring Boot应用程序为AWS Beanstalk创建.ebextensions的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆