[英]Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error
[英]What is the proper way to create .ebextensions for AWS Beanstalk through maven for Spring Boot app
在 GitLab CI/CD 管道期间,我们必须在 Spring Boot 应用程序的动态生成的 Elastic Beanstalk 实例中自定义hosts
文件。 为此,我们需要提供一个.ebextensions
目录,其中包含一个如下所示的配置文件:
commands:
01_add_hosts:
command: echo 123.12.12.123 myhost.com >> /etc/hosts
由于我们有一个 spring boot 应用程序,我们必须在我们的 fat jar 的根级别打包.ebextensions
。 所以,基本上我们解压缩 jar,添加 ebextensions 目录并将其压缩回来。 这样我们就成功地在我们的 Gitlab 管道中实现了 Beanstalk 定制。
然而,为了完成这个过程,我们像这样使用maven-antrun-plugin
:
<!-- 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 年的旧插件,这看起来不是实现此捆绑 jar 的正确方法。
你是如何或什么是 Spring Boot 方式来创建这个包 jar 的? 我的意思是在 Spring Boot 中在 jar 的根级别添加目录/文件? 请记住,我们在通过 AWS Beanstalk maven 插件部署的管道作业时间将其捆绑在一起。
是否要求您只将一个罐子上传到弹性豆茎? 我们这样做的方法是上传一个 zip 文件,其中包含我们的胖 jar、一个 .ebextensions 目录和一个 Procfile。 通过这种方式,ebextensions 得到应用并且 Procfile 包含启动 java 进程的命令。
例如,您可以上传包含以下内容的 hello-world.zip:
Procfile 是一个文本文件,其中包含:
网络:java -jar hello-world.jar
如果你这样做,就没有必要将你的 ebextension 文件嵌入到你的应用程序 jar 中,在我看来这会让事情变得更容易。
Build Helper Maven Plugin可用于此目的。 在项目的根目录中创建一个文件夹.ebextensions
并将插件添加到pom.xml
的<build><plugins>
部分:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-resource-ebextensions</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/.ebextensions</directory>
<targetPath>.ebextensions</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.