Fed*_*zza 0 java amazon-web-services maven spring-boot gitlab-ci
hosts在 GitLab CI/CD 管道期间,我们必须在 Spring Boot 应用程序的动态生成的 Elastic Beanstalk 实例中自定义文件。为此,我们需要提供一个.ebextensions包含如下配置文件的目录:
commands:
01_add_hosts:
command: echo 123.12.12.123 myhost.com >> /etc/hosts
Run Code Online (Sandbox Code Playgroud)
由于我们有一个spring boot应用程序,我们必须.ebextensions在我们的fat jar的根级别进行打包。所以,基本上我们解压缩 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>
Run Code Online (Sandbox Code Playgroud)
问题是这maven-antrun-plugin是 2014 年的旧插件,这看起来不是实现此捆绑 jar 的正确方法。
你是如何或什么是 Spring Boot 方式来创建这个包 jar 的?我的意思是在 Spring Boot 中在 jar 的根级别添加目录/文件?请记住,我们在通过 AWS Beanstalk maven 插件部署的管道作业时间将其捆绑在一起。
Build Helper Maven 插件可用于此目的。在项目的根目录中创建一个文件夹.ebextensions并将插件添加到以下<build><plugins>部分pom.xml:
<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>
Run Code Online (Sandbox Code Playgroud)
小智 5
是否要求您只将一个罐子上传到弹性豆茎?我们这样做的方法是上传一个 zip 文件,其中包含我们的胖 jar、一个 .ebextensions 目录和一个 Procfile。通过这种方式,ebextensions 得到应用并且 Procfile 包含启动 java 进程的命令。
例如,您可以上传包含以下内容的 hello-world.zip:
Procfile 是一个文本文件,其中包含:
网络:java -jar hello-world.jar
如果你这样做,就没有必要将你的 ebextension 文件嵌入到你的应用程序 jar 中,在我看来这会让事情变得更容易。
| 归档时间: |
|
| 查看次数: |
1169 次 |
| 最近记录: |