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