0

We are using AWS code deploy with bitbucket to deploy our applications on our ec2 instances. This is a new issue that we faced for our angular project repository. This repo has node modules as we are using angular with node and hence these dependencies are needed. These dependencies are having directory names starting with special character @. We found a thread on stack which said names with special charaters might cause a failure with a similar error we encountered. The error we receive is

 “Unable to remove top level folder”

We are unable to resolve this. When we removed the node modules directory the deployment works fine. Hence we are sure that the issue has to be with the names. We cannot change or remove as these dependencies are used by angular. We believe there must be a way to tackle this and hence looking for suggetions. Appspec.yml file helps to filter out files, can that be helpful in this case?
Details of deployment:
We use the standard bitbucket code-deploy plugin to communicate with aws. The bitbucket repository branch to be deployed is set and the deployment group is selected to initiate the deployment.

enter image description here

The above image has the node modules bundled with the app in the same branch.We are using angular 7 with node hence these dependencies are needed. Now if we remove the node-modules directory, the deployment works fine. Hence we concluded that it is these special characters that are causing the failure.Here's another question which describes similar issue due to special characters.

coderunner
  • 925
  • 1
  • 18
  • 33

2 Answers2

1

Try to clean the destination directory yourself before installation using 'BeforeInstall' hook in AppSpec file as follows:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/app/myapp
hooks:
  BeforeInstall:
    - location: ./cleanup.sh

and the content of cleanup.sh is similar to this:

#!/bin/bash -xe
rm -rf /var/app/myapp/

In the above, make sure to update the destination of your application deployment.

Edit 1:

Did a simple test with Repo:

https://github.com/shariqmus/codedeploy-special-char-test

(Recursively zipped the repo and uploaded to S3 and tested from there)

... and no dramas during extraction:

[root@ip-172-31-27-170 codedeploy-agent]# tree /var/app/myapp
/var/app/myapp
├── appspec.yml
├── cleanup.sh
├── node_modules
│   └── @agm
│       └── file.txt
└── README.md
Community
  • 1
  • 1
shariqmaws
  • 8,152
  • 1
  • 16
  • 35
  • We did try this, the cleanup way, but it did not resolve the problem. – coderunner Nov 29 '19 at 04:54
  • Can you provide simple steps to reproduce, this looks like interesting scenario, will try to debug it. – shariqmaws Nov 30 '19 at 01:25
  • Updated the question, please check – coderunner Dec 02 '19 at 06:05
  • Updated my answer with Edit 1. – shariqmaws Dec 03 '19 at 12:07
  • Thanks for the update. I believe the code deploy agent and the command-line utility must be the same under the hood, so technically shouldn't fail in our case. We haven't tried it yet by compressing and deploying from s3 using command line. But would be a good test to do that. Currently we just updated our scripts and removed node modules during deployment and add them back after its done. A poor work around but had no options as such. Will try this and update you the result. – coderunner Dec 04 '19 at 05:05
1

All the time for node modules it is advised to packed them with your code rather than downloading them at deployment time.

  • They are with the code itself, the issue comes while file are copied to the instance and the naming convention is rejected by code deploy. – coderunner Nov 29 '19 at 04:53