Search code examples
amazon-web-servicescontinuous-integrationcontinuous-deploymentaws-code-deploy

AWS CodeDeploy: In Appspec.yml Move Files That Are More Than 1 Folder Deep


In my appspec.yml file I need to deploy files that are more than one level deep. The following example will only get files in the views folder but within views folder there are other folders/files I need.

version: 0.0
os: linux
files:
  - source: /views
    destination: /var/www/views

Again this gives me all the files in /views but I need the folders within the /views folder.

I've tried adding another entry after views for the folders but that doesn't work. It'll give the error "No such file or directory".


Solution

  • The work around: zip application folder into source build then unzip when deploying.

    buildspec.yml

    version: 0.2
    phases:
      post_build:
        commands:
          - echo Entered the post_build phase...
          - zip -r site.zip ./*
          - echo Build completed on `date`
    artifacts:
      files:
        - appspec.yml
        - site.zip
        - DeployScripts/*
    

    appspec.yml

    version: 0.0
    os: linux
    files:
      - source: site.zip
        destination: /var/www/ecommercepricing
    hooks:
      AfterInstall:
        - location: DeployScripts/UnzipSite.sh
          timeout: 400
    

    DeployScripts/UnzipSite.sh

    #!/bin/bash
    
    echo Starting unzip
    apt-get install -y unzip
    unzip -o /var/www/ecommercepricing/site -d /var/www/ecommercepricing
    echo Finishing unzip