How I can include the .platform
directory in the artifacts of the buildspec.yml
file?
Background: I want to change the nginx setting client_max_body_size
on Elastic Beanstalk. I am using CodePipeline to deploy my war file on 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. The proxy.conf
file is not getting added on the server.
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
[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
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. 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
. This is the reason why the beanstalk deployment cannot find it.
Just remove the option discard-paths: yes
and copy your war files to the root directory (and change the artifact file path accordingly). This way, your war files will be at the same place as before.
You have given the artifact file path '.platform'
(with quotation marks). According to the documentation of the buildspec, it needs to be .platform/**/*
(without quotation marks).
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.
I'm unsure why you have another src/.platform
directory. Just keep in mind that it's structure is wrong since it has the hooks
directory under .platform/nginx/conf.d
instead of .platform
. 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. You probably also want to put it in confighooks
, see the documentation on beanstalk hooks. Currently, the script will not run if the beanstalk needs to deploy again due to configuration changes only during code deployments.