aws / aws-codedeploy-agent

Host Agent for AWS CodeDeploy
https://aws.amazon.com/codedeploy
Apache License 2.0
329 stars 187 forks source link

Setting :max-revisions to 0 prevents new deployments #57

Closed dskrvk closed 5 years ago

dskrvk commented 8 years ago

Please refer to this post for the issue description: https://forums.aws.amazon.com/thread.jspa?messageID=711273

Based on my reading of the code, this is what happens:

  1. During a deployment, command_executor#execute_command is called with command = DownloadBundle.
  2. It creates a new deployment directory: https://github.com/aws/aws-codedeploy-agent/blob/master/lib/instance_agent/plugins/codedeploy/command_executor.rb#L59
  3. It invokes method download_bundle which performs a cleanup: https://github.com/aws/aws-codedeploy-agent/blob/master/lib/instance_agent/plugins/codedeploy/command_executor.rb#L71.
  4. With :max-revisions = 0, cleanup_old_archives removes all the deployment directories except for the last successful one, including the newly-created one.
  5. This causes the new file creation to fail in download_from_s3: https://github.com/aws/aws-codedeploy-agent/blob/master/lib/instance_agent/plugins/codedeploy/command_executor.rb#L207.

You either need to keep track of and exclude the newly-created directory from the cleanup, or perform the cleanup before creating new directories.

After I set :max-revisions to 2, the deployments were able to proceed.

dskrvk commented 8 years ago

An excerpt from the log with debug level enabled (for some reason every line in my log is doubled, but I removed the duplicates here):

2016-03-28 22:52:48 DEBUG [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Successfully parsed the deployment spec 2016-03-28 22:52:48 DEBUG [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Creating deployment root directory /opt/codedeploy-agent/deployment-root/e445d2a1-8733-4850-aab0-1ac6d1f587c7/d-ZN9F64XVE 2016-03-28 22:52:48 DEBUG [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Executing DownloadBundle command for execution CodeDeploy/us-east-1/Prod/arn:aws:sds:us-east-1:663148821630:deployment/d-ZN9F64XVE 2016-03-28 22:52:48 DEBUG [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Downloading artifact bundle from bucket 'codepipeline-us-east-1-423929197064' and key '[redacted]/AAdCJYb.zip', version '', etag '7cb7551a4003c7b9234c386e79ab0848' 2016-03-28 22:52:48 DEBUG [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" ... 2016-03-28 22:52:48 ERROR [codedeploy-agent(22961)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: Errno::ENOENT - No such file or directory - /opt/codedeploy-agent/deployment-root/e445d2a1-8733-4850-aab0-1ac6d1f587c7/d-ZN9F64XVE/bundle.tar - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:208:in initialize' /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:208:inopen' /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:208:in `download_from_s3'

gaohan137 commented 8 years ago

You are correct. We have created task to fix this issue and roll out updated version soon. Thanks for letting us know!

gaohan137 commented 8 years ago

This fix is written up and will be released in next release of host agent.

mxro commented 7 years ago

So, has this been released yet?

Btw, if changing this value to 1 or 0 will superfluous copies be automatically deleted?

vvavepacket commented 7 years ago

was this released?

Constantin07 commented 6 years ago

any updates ?

annamataws commented 6 years ago

Hi,

We are currently working on the fix. The deployments will fail because the agent will not start with the max_revisions set to 0. Right now only integers 1 or greater work.

Thank you

annamataws commented 6 years ago

@mxro Superfluous copies will not be automatically deleted immediately. They will be deleted at the beginning of the next deployment.

annamataws commented 5 years ago

Hi,

Through many talks with managers, we have concluded we do not plan on supporting setting max_revision to 0 because of rollbacks and other functionality that relies on this. There are ways to work around this if you'd like. you can turn on the setting to ignore ApplicationStop failures and use a script to remove all old deployments.

Thank you