[英]How to add .platform in buildspec.yml file artifacts
如何在buildspec.yml
文件的工件中包含.platform
目錄?
背景:我想更改 Elastic Beanstalk 上的 nginx 設置client_max_body_size
。 我正在使用 CodePipeline 在 Elastic Beanstalk 上部署我的戰爭文件。
下面是我的回購目錄結構:
├── .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
編輯: buildspec.yml
不包括artifact.zip
文件中的“.platform”目錄。 proxy.conf
文件未添加到服務器上。
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
以下是來自 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
01_nginx.sh 腳本的內容
echo "client_max_body_size 20M;" > /etc/nginx/conf.d/proxy.conf
systemctl restart nginx.service
存在三個錯誤配置和兩個改進技巧:
在您的buildspec.yml
中,您已為工件設置了discard-paths: yes
。 這意味着所有文件都將直接放在工件中,子目錄將丟失。 因此,你的 nginx 配置proxy.conf
不會在.platform/nginx/conf.d/proxy.conf
而是./proxy.conf
。 這就是 beanstalk 部署找不到它的原因。
只需刪除選項discard-paths: yes
並將您的戰爭文件復制到根目錄(並相應地更改工件文件路徑)。 這樣,您的戰爭文件將與以前一樣位於同一位置。
您已經給出了工件文件路徑'.platform'
(帶引號)。 根據buildspec 的文檔,它需要是.platform/**/*
(不帶引號)。
同樣,您必須將文件appspec.yml
、 buildspec.yml
以及 CodeDeploy 或 Beanstalk 需要的任何內容添加到工件文件路徑中。
我不確定你為什么有另一個src/.platform
目錄。 請記住,它的結構是錯誤的,因為它在.platform/nginx/conf.d
而不是.platform
下有hooks
目錄。 在這個路徑下,也不會被豆莖發現。
您已將腳本01_nginx.sh
僅放在目錄hooks
中,該目錄用於部署掛鈎。 您可能還想將它放在confighooks
中,請參閱有關 beanstalk hooks 的文檔。 目前,如果beantalk僅在代碼部署期間由於配置更改而需要再次部署,腳本將不會運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.