我使用AWS codedeploy和git进行应用程序部署。我已经创建了一个appspec.yml。在文件部分,我需要从不同的文件夹(例如:/home/ec2 user/sample.war)复制一个文件到目的地。
version: 0.0
os: linux
files:
- source: /home/ec2-user/deploy/sample.war
destination: /usr/share/tomcat6/webapps/
source property in file section only looks for files inside the codedeploy agent directory (eg : /opt/codedeploy-agent/deployment-root/1d4de60d-99c1-4e40-bd14-335b6f8b5633/d-sfjksdjfkl/home/ec-user/sample.war). As per AWS documentation it is correct.Is any other option available to copy the file from different location of ec2 instance? or any variable available to locate the aws codedeploy agent folder at runtime?
I think you can use hook script to do this. It seems the file is not included in the bundle, you can have a simple script to do the cp for you. I think the best you can run the script during "BeforeInstall" event to copy the script over.
You can check hereto check out how to set up hook in appsec file.
Bangxi
You can totally customize what CodeDeploy does before, after and during an app install. You simply have to state the file you want to copy in the hooks section, like so:
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/dbex.ml
hooks:
BeforeInstall:
- location: scripts/install_dependencies.sh
timeout: 300
runas: root
AfterInstall:
- location: scripts/after_install.sh
timeout: 300
runas: root
ApplicationStart:
- location: scripts/start_server.sh
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server.sh
timeout: 300
runas: root
您想要做的是在AfterInstall挂钩中编辑after_install.sh文件,如下所示:
after_install.sh
#!/bin/sh
sudo cp /path/to/file /your/app/folder/