Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symlink copy force option at CopyCommand #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

americanomin
Copy link

@americanomin americanomin commented Jan 11, 2019

Issue #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.

@coveralls
Copy link

coveralls commented Jan 11, 2019

Coverage Status

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

@americanomin americanomin changed the title when deploying with fileExistsBehavior as "OVERWRITE" AND target location is not regular file ( symlink or directory ), Fix errors that occur. Add symlink copy force option at CopyCommand Jan 12, 2019
@americanomin americanomin force-pushed the fix-symlink-overwrite-option branch from 0f5cb2a to 5ede9b6 Compare January 12, 2019 11:22
@dgoade55
Copy link

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.

@airtightdesign
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants