[英]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.yml
、 buildspec.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.