简体   繁体   English

AWS CodePipeline 成功,但未正确部署到 Elastic Beanstalk

[英]AWS CodePipeline successful, but not correctly deployed to Elastic Beanstalk

The (successful) deployment of my WAR file to Elastic Beanstalk gives me a 404 Not Found when I invoke the application URL.当我调用应用程序 URL 时,将我的 WAR 文件(成功)部署到 Elastic Beanstalk 给我一个 404 Not Found。 I can see a application.war file within /var/lib/tomcat8/webapps/ROOT/ instead of META-INF and WEB-INF, which is in there when I deploy manually.我可以在 /var/lib/tomcat8/webapps/ROOT/ 中看到 application.war 文件,而不是 META-INF 和 WEB-INF,当我手动部署时,它就在那里。

When I pull the WAR file from S3 and deploy it to Elastic Beanstalk manually it works like a charm.当我从 S3 中提取 WAR 文件并手动将其部署到 Elastic Beanstalk 时,它就像一个魅力。 Note: this is the same WAR file as generated by CodeBuild in my pipeline.注意:这与 CodeBuild 在我的管道中生成的 WAR 文件相同。 Even better, if I secure copy (scp) the file to my local computer and upload it to Elastic Beanstalk it works as well.更好的是,如果我将文件安全复制 (scp) 到我的本地计算机并将其上传到 Elastic Beanstalk,它也能正常工作。

It seems that everything works until the deployment, a working WAR file is even deployed to Elastic Beanstalk.似乎在部署之前一切正常,一个有效的 WAR 文件甚至被部署到 Elastic Beanstalk。

Going through eb-activity.log I can see it recognizes the WAR file and deploys it from a temporary directory to /var/lib/tomcat8/webapps/ROOT , but it isn't unpacked and the container/webserver isn't restarted.通过eb-activity.log我可以看到它识别出 WAR 文件并将其从临时目录部署到/var/lib/tomcat8/webapps/ROOT ,但它没有解压,容器/网络服务器也没有重新启动。

How can I correctly deploy the WAR file with CodePipeline?如何使用 CodePipeline 正确部署 WAR 文件?

It seems that almost three years later AWS Codepipeline is not yet "WAR file deployment friendly".近三年后,AWS Codepipeline 似乎还不是“WAR 文件部署友好”。 As pointed out in the comment by @Azeq the standard Elastic Beanstalk deployment procedure won't unzip the war file and nothing will be really deployed.正如@Azeq在评论中指出的那样,标准的 Elastic Beanstalk 部署过程不会解压缩 war 文件,也不会真正部署任何内容。 CodePipeline reports success because the copy of the files is made without errors but Tomcat won't unzip the war file. CodePipeline 报告成功,因为文件的副本没有错误,但 Tomcat 不会解压缩 war 文件。

The solution is to provide your artifact in exploded form (already unzipped).解决方案是以分解形式(已解压缩)提供您的工件。 To do so modify the post build phase and the artifact definiton of your CodeBuild buildspec.yml:为此,请修改构建后阶段和 CodeBuild buildspec.yml 的工件定义:

version: 0.2

phases:
    install:
        runtime-versions:
            java: openjdk8
    pre_build:
        commands:
            - echo CODEBUILD_RESOLVED_SOURCE_VERSION $CODEBUILD_RESOLVED_SOURCE_VERSION
    build:
        commands:
            - mvn compile
    post_build:
        commands:
            - mvn package
            - mkdir artifact    <-- create folder to extract war file content
            - unzip target/my.war -d artifact/    <-- unzip to that folder
artifacts:
    files:
        - artifact/**/*   <-- reference all those files as the artifact
    name: artifact
cache:
    paths:
        - '/root/.m2/**/*'

Note the mkdir and unzip commands in the post build phase, and how the files definition in the artifacts section is written.注意构建后阶段的mkdirunzip命令,以及artifacts部分中的files定义是如何编写的。 As per CodeBuild documentation , **/* means all files recursively .根据CodeBuild 文档**/*表示递归所有文件

I tried to replicate the issue which you are facing.我试图复制您面临的问题。 I think when creating the "war" file, you are putting the folder, which contains the "META-INF" and "WEB-INF" folders, as the root of the "war" output file.我认为在创建“war”文件时,您将包含“META-INF”和“WEB-INF”文件夹的文件夹作为“war”输出文件的根目录。

Instead, you should put all the files (within the folder above) in the "war" file without the root-level folder.相反,您应该将所有文件(在上面的文件夹中)放在“war”文件中,而不是根级文件夹。

I struggled with this for a while as well.我也为此挣扎了一段时间。 Finally I was able to resolve it by having the buildspec.yml extract the WEB-INF directory from the built war file in the post_build section最后,我能够通过让 buildspec.yml 从 post_build 部分中构建的 war 文件中提取 WEB-INF 目录来解决它

Since AWS places a zip wrapper around your artifact it adds another folder level around what elasticbeanstalk actually needs由于 AWS 在您的工件周围放置了一个 zip 包装器,因此它会围绕 elasticbeanstalk 实际需要的内容添加另一个文件夹级别

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11
  build:
    commands:
       - mvn compile
  post_build:
    commands:
      - mvn package
      - mkdir artifact
      - unzip target/demo-0.0.1-SNAPSHOT.war -d artifact/
      - mv artifact/WEB-INF WEB-INF
artifacts:
  files:
   - WEB-INF/**/*
  name: artifact 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS CodePipeline 在部署到 Elastic Beanstalk 后缺少目录/文件 - AWS CodePipeline missing directories/files after being deployed to Elastic Beanstalk 弹力豆茎 | CodePipeline 将无法正确部署 .war 文件 - Elastic Beanstalk | CodePipeline will not deploy .war file correctly Laravel 部署在 CodePipeline 中的 Elastic Beanstalk 应用程序给出 500 SERVER ERROR - Laravel Elastic Beanstalk app deployed in CodePipeline giving 500 SERVER ERROR AWS CodePipeline 将 Spring Boot 应用程序部署到 Elastic BeansTalk - AWS CodePipeline deploy Spring Boot application to Elastic BeansTalk AWS Elastic Beanstalk - 通过 CodePipeline 部署不工作 - 健康状况 - 严重 - AWS Elastic Beanstalk - deploy by CodePipeline not working - health status - Severe AWS CodePipeline 无法将 EFS 附加到多容器 Docker Elastic Beanstalk - AWS CodePipeline Fails attaching EFS to Multicontainer Docker Elastic Beanstalk Flask 应用程序未在 AWS elastic beanstalk 上部署 - Flask Application is not getting deployed at AWS elastic beanstalk 通过 AWS Elastic Beanstalk 成功部署 Django,但出现 500 错误 - Successful Django Deploy Through AWS Elastic Beanstalk, But Getting 500 ERROR AWS Elastic Beanstalk在部署的带有Django的EC2服务器上托管PostreSQL - AWS Elastic Beanstalk hosting PostreSQL on deployed EC2 server with Django 配置部署在 AWS Elastic Beanstalk 中的 Spring 应用程序以使用 SSL - Configure Spring application deployed in AWS Elastic Beanstalk to use SSL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM