kavin
kavin

Reputation: 107

AWS CodeDeploy with git

I am using AWS codedeploy for application deployment along with git. I have created a appspec.yml. In files section i need to copy a file from different folder (eg :/home/ec2-user/sample.war) to destination.


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?

Upvotes: 1

Views: 889

Answers (2)

captainblack
captainblack

Reputation: 4425

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

What you would want is to do is edit the after_install.sh file in the AfterInstall hook, like so:

after_install.sh

#!/bin/sh
sudo cp /path/to/file /your/app/folder/

Upvotes: 0

Bangxi Yu
Bangxi Yu

Reputation: 191

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

Upvotes: 0

Related Questions