首页 > 解决方案 > 尝试使用 codepipeline 将 spring boot + mysql 应用程序部署到 AWS 时出错

问题描述

我已经使用 AWS codepipeline 构建了一个 cicd 管道。来源来自成功的 Github。构建也成功。

我正在使用在 64 位 Amazon Linux 2 上运行的 Corretto 11 作为 Elastic Beanstalk 中的平台,因为在 64 位 Amazon Linux 上运行的 Java 8 显示它已被弃用。

在部署到 AWS Elastic Beanstalk 期间出现错误。

Action execution failed
Deployment completed, but with errors: Failed to deploy application. Unsuccessful command execution on instance id(s) 'i-03b7a9c8a86ffde8e'. Aborting the operation. [Instance: i-03b7a9c8a86ffde8e] Command failed on instance. Return code: 1 Output: Engine execution has encountered an error.. Instance deployment failed. For details, see 'eb-engine.log'.

我检查了 eb-engine.log 文件并看到以下错误消息。

...
...
2021/11/07 05:01:18.765214 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /tmp/extracted_app_source_bundle
2021/11/07 05:01:18.765227 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /tmp/extracted_app_source_bundle
2021/11/07 05:01:19.122461 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /tmp/extracted_app_source_bundle successfully
2021/11/07 05:01:19.122560 [INFO] app source bundle is zip file ...
2021/11/07 05:01:19.122566 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2021/11/07 05:01:19.122578 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2021/11/07 05:01:19.498171 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2021/11/07 05:01:19.498694 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2021/11/07 05:01:19.498712 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2021/11/07 05:01:19.498717 [INFO] Executing instruction: Java Specific Build Application
2021/11/07 05:01:19.498724 [INFO] no buildfile found, skip building java application
2021/11/07 05:01:19.498731 [INFO] old env file for build tasks does not exist
2021/11/07 05:01:19.498742 [INFO] Executing instruction: CheckProcfileForJavaApplication
2021/11/07 05:01:19.498776 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle 
 
2021/11/07 05:01:19.498786 [INFO] Executing cleanup logic
2021/11/07 05:01:19.498869 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1636261279,"severity":"ERROR"}]}]}
...
...

下面是我的 buildspec.yml 文件。

version: 0.2
 
phases:
install:
runtime-versions:
java: corretto11
commands:
- echo install
pre_build:
commands:
- echo pre_build
build:
commands:
- mvn package
- echo build
post_build:
commands:
- echo post_build
 
artifacts:
files:
- target/course_reviews_backend-0.0.1-SNAPSHOT.jar

请帮忙!!

任何帮助都会得到帮助。提前致谢。

标签: amazon-web-servicesamazon-ec2amazon-elastic-beanstalkamazon-rdsaws-codepipeline

解决方案


您应该注意此错误消息:

2021/11/07 05:01:19.498776 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle 

Procfile本质上,您必须在 spring boot 项目的根目录中添加一个名为的文件:

在此处输入图像描述

的内容Procfile应该如下:

web: java -jar target/course_reviews_backend-0.0.1-SNAPSHOT.jar

推荐阅读