简体   繁体   English

如何在 buildspec.yml 文件工件中添加 .platform

[英]How to add .platform in buildspec.yml file artifacts

How I can include the .platform directory in the artifacts of the buildspec.yml file?如何在buildspec.yml文件的工件中包含.platform目录?

Background: I want to change the nginx setting client_max_body_size on Elastic Beanstalk.背景:我想更改 Elastic Beanstalk 上的 nginx 设置client_max_body_size I am using CodePipeline to deploy my war file on Elastic Beanstalk.我正在使用 CodePipeline 在 Elastic Beanstalk 上部署我的战争文件。

Below is my repo directory structure:下面是我的回购目录结构:

├── .checkstyle
├── .gitignore
├── .platform
│   ├── hooks
│   │   └── postdeploy
│   │       └── 01_nginx.sh
│   └── nginx
│       └── conf.d
│           └── proxy.conf
├── README.md
├── appspec.yml
├── buildspec.yml
├── mvnw
├── mvnw.cmd
├── nginx.sh
├── pom.xml
└── src
    ├── .platform
    │   └── nginx
    │       └── conf.d
    │           ├── hooks
    │           │   └── postdeploy
    │           │       └── 01_nginx.sh
    │           └── proxy.conf
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── k12
    │   │           └── caap
    │   │               └── service
    │   │                   └── ServiceNAME

Edit: The buildspec.yml is not including the '.platform' directory in the artifact.zip file.编辑: buildspec.yml不包括artifact.zip文件中的“.platform”目录。 The proxy.conf file is not getting added on the server. proxy.conf文件未添加到服务器上。

buildspec.yml: buildspec.yml:

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11

  pre_build:
    commands:
      - pip3 install awscli --upgrade --user

  build:
    commands:
      - mvn clean compile package
      
artifacts:
  files:
    - target/*.war
    - '.platform'        
  discard-paths: yes

Below are the logs from EC2 /var/log/eb-engine.log以下是来自 EC2 /var/log/eb-engine.log 的日志

[INFO] Executing instruction: RunAppDeployPostDeployHooks                      
[INFO] Executing platform hooks in .platform/hooks/postdeploy/                 
[INFO] The dir .platform/hooks/postdeploy/ does not exist                      
[INFO] Finished running scripts in /var/app/current/.platform/hooks/postdeploy 

Content of 01_nginx.sh script 01_nginx.sh 脚本的内容

echo "client_max_body_size 20M;" > /etc/nginx/conf.d/proxy.conf
systemctl restart nginx.service

There are three misconfigurations and two tips to improve:存在三个错误配置和两个改进技巧:

  • In your buildspec.yml , you have set discard-paths: yes for the artifact.在您的buildspec.yml中,您已为工件设置了discard-paths: yes This means that all files will be put directly in the artifact, subdirectories will be lost.这意味着所有文件都将直接放在工件中,子目录将丢失。 Therefore, your nginx configuration proxy.conf will not be in .platform/nginx/conf.d/proxy.conf but ./proxy.conf .因此,你的 nginx 配置proxy.conf不会在.platform/nginx/conf.d/proxy.conf而是./proxy.conf This is the reason why the beanstalk deployment cannot find it.这就是 beanstalk 部署找不到它的原因。

    Just remove the option discard-paths: yes and copy your war files to the root directory (and change the artifact file path accordingly).只需删除选项discard-paths: yes并将您的战争文件复制到根目录(并相应地更改工件文件路径)。 This way, your war files will be at the same place as before.这样,您的战争文件将与以前一样位于同一位置。

  • You have given the artifact file path '.platform' (with quotation marks).您已经给出了工件文件路径'.platform' (带引号)。 According to the documentation of the buildspec , it needs to be .platform/**/* (without quotation marks).根据buildspec 的文档,它需要是.platform/**/* (不带引号)。

  • The same way, you will have to add the files appspec.yml , buildspec.yml and whatever CodeDeploy or the Beanstalk needs to the artifact file paths.同样,您必须将文件appspec.ymlbuildspec.yml以及 CodeDeploy 或 Beanstalk 需要的任何内容添加到工件文件路径中。

  • I'm unsure why you have another src/.platform directory.我不确定你为什么有另一个src/.platform目录。 Just keep in mind that it's structure is wrong since it has the hooks directory under .platform/nginx/conf.d instead of .platform .请记住,它的结构是错误的,因为它在.platform/nginx/conf.d而不是.platform下有hooks目录。 Under this path, it will also not be found by the beanstalk.在这个路径下,也不会被豆茎发现。

  • You have put the script 01_nginx.sh only in the directory hooks , which is for deployment hooks.您已将脚本01_nginx.sh仅放在目录hooks中,该目录用于部署挂钩。 You probably also want to put it in confighooks , see the documentation on beanstalk hooks .您可能还想将它放在confighooks中,请参阅有关 beanstalk hooks 的文档 Currently, the script will not run if the beanstalk needs to deploy again due to configuration changes only during code deployments.目前,如果beantalk仅在代码部署期间由于配置更改而需要再次部署,脚本将不会运行。

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

相关问题 如何在此 buildspec.yml 文件中使用 env 变量? - How can I use env variables in this buildspec.yml file? 如何将环境变量添加到CodeBuild buildspec.yml? - How Do You Add Environment Variables to CodeBuild buildspec.yml? Spring 引导项目的 buildspec.yml 文件 - buildspec.yml file for Spring Boot project AWS CodePipeline BuildAction 未检测到 buildspec.yml 辅助工件 - AWS CodePipeline BuildAction not detecting buildspec.yml secondary artifacts 如何使用 AWS CodePipeline 为 Laravel 应用程序正确创建 buildspec.yml 文件 - How do I properly create buildspec.yml file for Laravel Application using AWS CodePipeline 如何在buildspec.yml中正确定义阶段和命令? - How to correctly define stages & commands in buildspec.yml? 如何将环境变量传递给 AWS 代码构建的 buildspec.yml - How to pass environment variable to the buildspec.yml for AWS codebuild AWS CodeBuild:如何强制 buildspec.yml 在出错时退出 - AWS CodeBuild: How to force buildspec.yml quit on error 我们如何在buildspec.yml中获取最新的Packer版本? - How do we fetch latest packer release in buildspec.yml? 如何有条件地从 buildspec.yml 中删除报告部分 - How to remove the reports section conditionally from buildspec.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM