gpt4 book ai didi

amazon-web-services - AWS CodePipeline 将 Spring Boot 应用程序部署到 Elastic BeansTalk

转载 作者:行者123 更新时间:2023-12-05 01:13:09 25 4
gpt4 key购买 nike

我用 3 个步骤为 SpringBoot Java 应用程序构建了一个简单的 CodePipeline:

  • 来源:从 GitHub 获取源代码
  • 构建:jar 文件
  • 部署:到 AWS Elastic Beanstalk 实例

1 和 2 步骤成功通过,而 Deploy 步骤失败。我在 Elastic Beanstalk 日志中看到的唯一错误:

01_configure_application.sh] : Activity execution failed, because: Executing: /usr/bin/unzip -o -d /var/app/staging /opt/elasticbeanstalk/deploy/appsource/source_bundle
FileMagic v0.7.1: compiled magic version [5.21] does not match with shared library magic version [5.37]
Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle
inflating: /var/app/staging/microservices/my-service/target/my-service.jar
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile.
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile. (ElasticBeanstalk::ExternalInvocationError)
caused by: Executing: /usr/bin/unzip -o -d /var/app/staging /opt/elasticbeanstalk/deploy/appsource/source_bundle
FileMagic v0.7.1: compiled magic version [5.21] does not match with shared library magic version [5.37]
Archive: /opt/elasticbeanstalk/deploy/appsource/source_bundle
inflating: /var/app/staging/microservices/my-service/target/my-service.jar
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile.
Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile. (Executor::NonZeroExitStatus)

我的构建规范:

build:
commands:
- mvn -P ci --settings settings.xml install -DskipTests
artifacts:
files:
- microservices/my-service/target/my-service.jar

如果我使用 AWS Web Interface 将这个 jar 直接部署到 AWS Elastic Beanstalk,它会完美运行。

请帮帮我。我已准备好按需共享任何其他配置。

最佳答案

虽然 Denys 的回答是正确的,但我认为它不能清楚地解释问题。

artifacts 下输出时,工件必须是顶级或最多一个深度目录指示。

例如,使用 gradle 的 spring 项目的默认值是输出到 <project root>/build/libs/<artifact name>.jar执行 bootJar 后任务

直觉上你会这样定义:

version: 0.2

phases:
install:
runtime-versions:
java: corretto8
build:
commands:
# bootJar task outputs to build/libs/<name>.jar
- ./gradlew bootJar
artifacts:
files:
- build/libs/<name>.jar

此构建将成功并将压缩的工件上传到 S3。解压后你会得到:

build/libs/<name>.jar .您可以通过从 s3 下载工件并自己解压缩来确认这一点(就像弹性 beanstalk 在 vm 中所做的那样)。

所以当弹性 beanstalk 尝试部署它时它会失败,因为它会寻找顶级 <name>.jar最多 somedir/<name>.jar你会得到那个相当神秘的错误信息

Unable to launch application as the source bundle does not contain either a file named application.jar or a Procfile.

它很神秘,因为它暗示工件必须被命名为 application.jar或者必须添加 Procfile。这些都不是真的

所以解决方案围绕着使该 jar 文件成为顶级文件。你可以:

将构建工具中的输出工件定义为将其置于顶层(不理想)

将第二个命令添加到 build将该 jar 文件移到顶层的阶段,例如:

version: 0.2

phases:
install:
runtime-versions:
java: corretto8
build:
commands:
# bootJar task outputs to build/libs/<name>.jar
- ./gradlew bootJar
# move the jar (by wildcard, agnostic to its name) to top level app.jar
- mv build/libs/*.jar app.jar
artifacts:
files:
# publish the now top level app.jar as the artifact
- app.jar

最合适的解决方案是使用 post_build专为清理/重组步骤而设计的指令,如下所示:

version: 0.2

phases:
install:
runtime-versions:
java: corretto8
build:
commands:
# bootJar task outputs to build/libs/<name>.jar
- ./gradlew bootJar
post_build:
commands:
# move the jar (by wildcard, agnostic to its name) to top level app.jar
- mv build/libs/*.jar app.jar
artifacts:
files:
# publish the now top level app.jar as the artifact
- app.jar

解压后你会得到app.jar顶级弹力 bean 茎开心!请注意 app.jarbuild/libs是任意的,设置它们对您和您的项目有意义。重要的是artifacts.files是一个顶级的 jar 文件。 Elastic Beanstalk 会处理剩下的事情

如果您是 CP 新手或有一个简单的项目,则无需使用 config.yml 进行覆盖。或添加 Procfile正如其他类似问题中所建议的那样。

希望这对其他人有帮助。

关于amazon-web-services - AWS CodePipeline 将 Spring Boot 应用程序部署到 Elastic BeansTalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60840569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com