aws-codedeploy-agent icon indicating copy to clipboard operation
aws-codedeploy-agent copied to clipboard

Add symlink copy force option at CopyCommand

Open americanomin opened this issue 6 years ago • 3 comments

Issue aws#143:

TL;DR

To fix an error that occurs when the target location is not a regular file, Add symlink copy force option to CopyCommand.

A long story why OVERWRITE option doesn't work correctly

When creating a deployment, codedeploy handles files that already exist in a deployment target location but weren't part of the previous successful deployment with fileExistsBehavior option. If the option is OVERWRITE, the deployment should replace files in the target location to the source files.

However, OVERWRITE doesn't work as expected when some conditions are met.

Suppose my source file is source and destination is target_dir/source. Since I set fileExistsBehavior as OVERWRITE, I want to have a result of target_dir/source regardless of existence of the destination file. But if target_dir/source already exists, only 1 out of 4 cases works correctly.

  • When the source file is not a symbolic link, the file is copied with FileUtils.copy.
    • (1) ⭕️target_dir/source as a regular file → result: target_dir/source, overwritten.
    • (2) ❌target_dir/source as a directory → result: target_dir/source/source.
  • When the source file is a symbolic link, the file is copied with FileUtils.symlink.
    • (3) ❌target_dir/source as a regular file → result: Errno::EEXIST error occurs, and the deployment fails.
    • (4) ❌target_dir/source as a directory → result: target_dir/source/source. That is, only case (1) is accidentally handled without a problem due to default behavior of FileUtils.copy. But since other cases are rare, it has not been a big problem.

If the target location was a directory (2, 4 Case), I didn't think it was the intended situation. So in this instance, explicitly exception was generated.

americanomin avatar Jan 11 '19 14:01 americanomin

Coverage Status

Coverage increased (+0.02%) to 92.11% when pulling 5ede9b60893f5302e8a32f80ba38688eb1c47331 on what-is-quality:fix-symlink-overwrite-option into 866632b98447312962e629c31da94e756127c620 on aws:master.

coveralls avatar Jan 11 '19 14:01 coveralls

We encountered this issue recently. I want to add that if a symlink file is deployed through any means other than the exact same CodeDeploy project/deployment group that is attempting to refresh it, the deployment will fail.

Also, if the CodeDeploy project is set to automatically rollback the deployment group to the last successful version, the rollback is able to remove one, and only one offending symlink. In our case, we had 3 symlinks that were deployed by a CodeDeploy project. After we replaced the project with one that was configured identically, it failed exactly 3 times (once for each symlink) and then succeeded on the 4th attempt.

This took a lot of time to diagnose so while it may be an edge-case, it's an expensive one.

dgoade55 avatar Mar 11 '19 17:03 dgoade55

any status update on this one? currently affected by this issue in current official version.

2023-10-31T19:34:49 INFO [codedeploy-agent(803)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.6.0-49_deb.

airtightdesign avatar Nov 01 '23 15:11 airtightdesign